Skip to content

Commit

Permalink
Merge pull request #110 from TeamSobokSobok/develop
Browse files Browse the repository at this point in the history
[Fix]: 유저 탈퇴시 관련 데이터 삭제 (#109)
  • Loading branch information
dev-Crayon authored Mar 5, 2024
2 parents b3b73e0 + 17a29d6 commit 90372d7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,35 @@
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;
import org.springframework.security.core.Authentication;
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<String, String> redisTemplate;
private final JwtProvider jwtProvider;
Expand Down Expand Up @@ -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<String, String> valueOperations = redisTemplate.opsForValue();
if (valueOperations.get(user.getSocialInfo().getSocialId()) == null) {
Expand All @@ -72,5 +86,14 @@ public void leave(Long userId, String leaveReason) {

redisTemplate.delete(user.getSocialInfo().getSocialId());
user.deleteUser(leaveReason);

List<Pill> pills = pillRepository.findAllByUserId(userId);
for (Pill pill : pills) {
pillScheduleRepository.deleteAllByPillId(pill.getId());
}

pillRepository.deleteAllByUserId(userId);
friendRepository.deleteAllBySenderIdOrReceiverId(userId, userId);
likeScheduleRepository.deleteAllBySenderId(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

public interface FriendRepository extends JpaRepository<Friend, Long> {

// READ
List<Friend> findAllBySenderId(Long senderId);

Integer countBySenderId(Long senderId);

// DELETE
void deleteAllBySenderIdOrReceiverId(Long senderId, Long receiverId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ public interface PillRepository extends JpaRepository<Pill, Long> {

// READ
List<Pill> findAllByUserId(Long userId);

// DELETE
void deleteAllByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@

public interface LikeScheduleRepository extends JpaRepository<LikeSchedule, Long> {

// READ
Boolean existsBySenderIdAndScheduleId(Long senderId, Long scheduleId);

// DELETE
void deleteAllBySenderId(Long userId);
}

0 comments on commit 90372d7

Please sign in to comment.