Skip to content

Commit

Permalink
[refactor] 유저 탈퇴시 pokeHistory 삭제 Event 추가 (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
kseysh committed Oct 31, 2024
1 parent 6108774 commit 100e51e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package org.sopt.app.application.poke;

import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.val;
import java.util.*;
import lombok.*;
import org.sopt.app.application.poke.PokeInfo.PokeHistoryInfo;
import org.sopt.app.application.user.UserWithdrawEvent;
import org.sopt.app.common.exception.BadRequestException;
import org.sopt.app.common.response.ErrorCode;
import org.sopt.app.domain.entity.poke.PokeHistory;
import org.sopt.app.interfaces.postgres.PokeHistoryRepository;
import org.springframework.context.event.EventListener;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -80,4 +78,10 @@ public List<PokeHistoryInfo> getAllPokeHistoryByUsers(Long userId, Long friendUs
val pokeHistories = pokeHistoryRepository.findAllPokeHistoryByUsers(userId, friendUserId);
return pokeHistories.stream().map(PokeHistoryInfo::from).toList();
}

@EventListener(UserWithdrawEvent.class)
public void handleUserWithdrawEvent(final UserWithdrawEvent event) {
pokeHistoryRepository.deleteAllByPokerIdInQuery(event.getUserId());
pokeHistoryRepository.deleteAllByPokedIdInQuery(event.getUserId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public interface PokeHistoryRepository extends JpaRepository<PokeHistory, Long>

Page<PokeHistory> findAllByIdIsInOrderByCreatedAtDesc(List<Long> historyIds, Pageable pageable);

@Query("DELETE From PokeHistory ph WHERE ph.pokedId = :userId")
void deleteAllByPokedIdInQuery(@Param("userId") Long userId);

@Query("DELETE From PokeHistory ph WHERE ph.pokerId = :userId")
void deleteAllByPokerIdInQuery(@Param("userId") Long userId);

@Query("SELECT ph FROM PokeHistory ph WHERE ((ph.pokerId = :userId AND ph.pokedId = :friendId) OR (ph.pokerId = :friendId AND ph.pokedId = :userId)) AND ph.isReply = false ORDER BY ph.createdAt DESC ")
List<PokeHistory> findAllWithFriendOrderByCreatedAtDescIsReplyFalse(@Param("userId") Long userId,
@Param("friendId") Long friendId);
Expand Down

0 comments on commit 100e51e

Please sign in to comment.