Skip to content

Commit

Permalink
Fix: logic in user-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
bin-pro committed Jul 21, 2024
1 parent 7c2d464 commit 0b4210a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -51,4 +52,8 @@ public interface FilterRepository extends JpaRepository<Filter, Long>{

@Query("SELECT f FROM Filter f WHERE f.user = :user")
List<Filter> findByUser(User user);

@Modifying
@Query("DELETE FROM Filter f WHERE f.user = :user")
void deleteByUser(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ public interface FilterTagRepository extends JpaRepository<FilterTag, Long> {
@Query("DELETE FROM FilterTag ft WHERE ft.filter = :filter")
void deleteByFilter(Filter filter);

@Modifying
@Query("DELETE FROM FilterTag ft WHERE ft.filter.user = :user")
void deleteByUserOfFilter(User user);

@Modifying
@Query("DELETE FROM FilterTag ft WHERE ft.temporaryFilter.user = :user")
void deleteByUserOfTemporaryFilter(User user);
void deleteByUser(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.blackshoe.esthete.entity.User;
import com.blackshoe.esthete.entity.UserTag;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

Expand All @@ -17,4 +18,8 @@ public interface UserTagRepository extends JpaRepository<UserTag, Long> {

@Query("SELECT ut FROM UserTag ut JOIN FETCH ut.tag WHERE ut.user = :user")
List<UserTag> findByUserWithTags(@Param("user") User user);

@Modifying
@Query("DELETE FROM UserTag ut WHERE ut.user = :user")
void deleteByUser(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import com.blackshoe.esthete.dto.KafkaConsumerDto;
import com.blackshoe.esthete.entity.User;
import com.blackshoe.esthete.exception.KafkaErrorResult;
import com.blackshoe.esthete.repository.FilterRepository;
import com.blackshoe.esthete.repository.FilterTagRepository;
import com.blackshoe.esthete.repository.TemporaryFilterRepository;
import com.blackshoe.esthete.repository.UserRepository;
import com.blackshoe.esthete.repository.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -30,7 +27,7 @@ public class KafkaUserInfoConsumer{
private final FilterRepository filterRepository;
private final FilterTagRepository filterTagRepository;
private final TemporaryFilterRepository temporaryFilterRepository;

private final UserTagRepository userTagRepository;
@KafkaListener(topics = "user-create")
@Transactional
public void createUser(String payload, Acknowledgment acknowledgment) {
Expand Down Expand Up @@ -126,15 +123,10 @@ public void deleteUser(String payload, Acknowledgment acknowledgment) {
UUID userId = UUID.fromString(userDeleteDto.getUserId());
final User user = userRepository.findByUserId(userId).orElseThrow(() -> new KafkaException(KafkaErrorResult.USER_NOT_FOUND));

filterTagRepository.deleteByUserOfTemporaryFilter(user);
filterTagRepository.deleteByUser(user);
temporaryFilterRepository.deleteByUser(user);

filterTagRepository.deleteByUserOfFilter(user);

List<Filter> filters = user.getFilters();
for (Filter filter : filters) {
filter.freeFilter();
}
filterRepository.deleteByUser(user);
userTagRepository.deleteByUser(user);

userRepository.delete(user);

Expand Down

0 comments on commit 0b4210a

Please sign in to comment.