From 17a29d688d4a0f42d99173b6a3d59ae54e41e937 Mon Sep 17 00:00:00 2001 From: Lee SeungHeon <51286325+dev-Crayon@users.noreply.github.com> Date: Wed, 6 Mar 2024 08:49:46 +0900 Subject: [PATCH] =?UTF-8?q?[Fix]:=20=EC=9C=A0=EC=A0=80=20=ED=83=88?= =?UTF-8?q?=ED=87=B4=EC=8B=9C=20=EA=B4=80=EB=A0=A8=20=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=ED=84=B0=20=EC=82=AD=EC=A0=9C=20(#109)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 유저 삭제 로직 코드 추가 각 Repository에 delete 로직 추가 Related to: #108 --- .../auth/application/AuthService.java | 27 +++++++++++++++++-- .../infrastructure/FriendRepository.java | 4 +++ .../pill/infrastructure/PillRepository.java | 3 +++ .../LikeScheduleRepository.java | 4 +++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/sobok/SobokSobok/auth/application/AuthService.java b/src/main/java/io/sobok/SobokSobok/auth/application/AuthService.java index 1118d22..86b7ba8 100644 --- a/src/main/java/io/sobok/SobokSobok/auth/application/AuthService.java +++ b/src/main/java/io/sobok/SobokSobok/auth/application/AuthService.java @@ -6,8 +6,17 @@ import io.sobok.SobokSobok.auth.ui.dto.JwtTokenResponse; import io.sobok.SobokSobok.exception.ErrorCode; import io.sobok.SobokSobok.exception.model.NotFoundException; +import io.sobok.SobokSobok.friend.infrastructure.FriendQueryRepository; +import io.sobok.SobokSobok.friend.infrastructure.FriendRepository; +import io.sobok.SobokSobok.pill.domain.Pill; +import io.sobok.SobokSobok.pill.infrastructure.PillQueryRepository; +import io.sobok.SobokSobok.pill.infrastructure.PillRepository; +import io.sobok.SobokSobok.pill.infrastructure.PillScheduleQueryRepository; +import io.sobok.SobokSobok.pill.infrastructure.PillScheduleRepository; import io.sobok.SobokSobok.security.jwt.Jwt; import io.sobok.SobokSobok.security.jwt.JwtProvider; +import io.sobok.SobokSobok.sticker.infrastructure.LikeScheduleQueryRepository; +import io.sobok.SobokSobok.sticker.infrastructure.LikeScheduleRepository; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ValueOperations; @@ -15,11 +24,17 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Service @RequiredArgsConstructor public class AuthService { private final UserRepository userRepository; + private final FriendRepository friendRepository; + private final PillRepository pillRepository; + private final PillScheduleRepository pillScheduleRepository; + private final LikeScheduleRepository likeScheduleRepository; private final RedisTemplate redisTemplate; private final JwtProvider jwtProvider; @@ -62,8 +77,7 @@ public JwtTokenResponse refresh(String token) { @Transactional public void leave(Long userId, String leaveReason) { - User user = userRepository.findById(userId) - .orElseThrow(() -> new NotFoundException(ErrorCode.UNREGISTERED_USER)); + User user = UserServiceUtil.findUserById(userRepository, userId); ValueOperations valueOperations = redisTemplate.opsForValue(); if (valueOperations.get(user.getSocialInfo().getSocialId()) == null) { @@ -72,5 +86,14 @@ public void leave(Long userId, String leaveReason) { redisTemplate.delete(user.getSocialInfo().getSocialId()); user.deleteUser(leaveReason); + + List pills = pillRepository.findAllByUserId(userId); + for (Pill pill : pills) { + pillScheduleRepository.deleteAllByPillId(pill.getId()); + } + + pillRepository.deleteAllByUserId(userId); + friendRepository.deleteAllBySenderIdOrReceiverId(userId, userId); + likeScheduleRepository.deleteAllBySenderId(userId); } } diff --git a/src/main/java/io/sobok/SobokSobok/friend/infrastructure/FriendRepository.java b/src/main/java/io/sobok/SobokSobok/friend/infrastructure/FriendRepository.java index 899558b..5d84d59 100644 --- a/src/main/java/io/sobok/SobokSobok/friend/infrastructure/FriendRepository.java +++ b/src/main/java/io/sobok/SobokSobok/friend/infrastructure/FriendRepository.java @@ -6,7 +6,11 @@ public interface FriendRepository extends JpaRepository { + // READ List findAllBySenderId(Long senderId); Integer countBySenderId(Long senderId); + + // DELETE + void deleteAllBySenderIdOrReceiverId(Long senderId, Long receiverId); } diff --git a/src/main/java/io/sobok/SobokSobok/pill/infrastructure/PillRepository.java b/src/main/java/io/sobok/SobokSobok/pill/infrastructure/PillRepository.java index 24f96dc..dd2b4ca 100644 --- a/src/main/java/io/sobok/SobokSobok/pill/infrastructure/PillRepository.java +++ b/src/main/java/io/sobok/SobokSobok/pill/infrastructure/PillRepository.java @@ -9,4 +9,7 @@ public interface PillRepository extends JpaRepository { // READ List findAllByUserId(Long userId); + + // DELETE + void deleteAllByUserId(Long userId); } diff --git a/src/main/java/io/sobok/SobokSobok/sticker/infrastructure/LikeScheduleRepository.java b/src/main/java/io/sobok/SobokSobok/sticker/infrastructure/LikeScheduleRepository.java index d5cc238..c5a7b48 100644 --- a/src/main/java/io/sobok/SobokSobok/sticker/infrastructure/LikeScheduleRepository.java +++ b/src/main/java/io/sobok/SobokSobok/sticker/infrastructure/LikeScheduleRepository.java @@ -5,5 +5,9 @@ public interface LikeScheduleRepository extends JpaRepository { + // READ Boolean existsBySenderIdAndScheduleId(Long senderId, Long scheduleId); + + // DELETE + void deleteAllBySenderId(Long userId); }