Skip to content

Commit

Permalink
[MERGE] Merge pull request #225 from Team-WSS/feat/#224
Browse files Browse the repository at this point in the history
[FIX] 카카오 회원 탈퇴에 따른 리소스 수정 및 삭제 로직 추가
  • Loading branch information
Kim-TaeUk authored Nov 13, 2024
2 parents 1a5bd3e + fc30a7f commit c27f81a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/websoso/WSSServer/domain/User.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.websoso.WSSServer.domain;

import static jakarta.persistence.CascadeType.ALL;
import static org.websoso.WSSServer.domain.common.Gender.M;
import static org.websoso.WSSServer.domain.common.Role.USER;

Expand All @@ -10,9 +11,12 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import java.time.Year;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -74,6 +78,12 @@ public class User {
@ColumnDefault("'USER'")
private Role role;

@OneToMany(mappedBy = "user", cascade = ALL, orphanRemoval = true)
private List<GenrePreference> genrePreferences = new ArrayList<>();

@OneToMany(mappedBy = "user", cascade = ALL, orphanRemoval = true)
private List<UserNovel> userNovels = new ArrayList<>();

public void updateProfileStatus(Boolean profileStatus) {
this.isProfilePublic = profileStatus;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.websoso.WSSServer.dto.auth.AuthResponse;
import org.websoso.WSSServer.exception.exception.CustomKakaoException;
import org.websoso.WSSServer.oauth2.dto.KakaoUserInfo;
import org.websoso.WSSServer.repository.CommentRepository;
import org.websoso.WSSServer.repository.FeedRepository;
import org.websoso.WSSServer.repository.RefreshTokenRepository;
import org.websoso.WSSServer.repository.UserRepository;

Expand All @@ -28,6 +30,8 @@
public class KakaoService {

private final UserRepository userRepository;
private final FeedRepository feedRepository;
private final CommentRepository commentRepository;
private final RefreshTokenRepository refreshTokenRepository;
private final JwtProvider jwtProvider;

Expand Down Expand Up @@ -108,6 +112,8 @@ public void unlinkFromKakao(User user, String refreshToken) {
String socialId = user.getSocialId();
String kakaoUserInfoId = socialId.replaceFirst("kakao_", "");

feedRepository.updateUserToUnknown(user.getUserId());
commentRepository.updateUserToUnknown(user.getUserId());
userRepository.delete(user);

MultiValueMap<String, String> withdrawInfoBodies = new LinkedMultiValueMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package org.websoso.WSSServer.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.websoso.WSSServer.domain.Comment;

@Repository
public interface CommentRepository extends JpaRepository<Comment, Long> {

@Transactional
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("UPDATE Comment c SET c.userId = -1 WHERE c.userId = :userId")
void updateUserToUnknown(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.websoso.WSSServer.domain.Feed;

@Repository
Expand All @@ -31,4 +33,9 @@ public interface FeedRepository extends JpaRepository<Feed, Long>, FeedCustomRep
+ "OR f.user.userId NOT IN (SELECT b.blockedId FROM Block b WHERE b.blockingId = :userId)) "
+ "ORDER BY f.feedId DESC")
Slice<Feed> findFeedsByNovelId(Long novelId, Long lastFeedId, Long userId, PageRequest pageRequest);

@Transactional
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("UPDATE Feed f SET f.user.userId = -1 WHERE f.user.userId = :userId")
void updateUserToUnknown(Long userId);
}

0 comments on commit c27f81a

Please sign in to comment.