Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/main/java/stackpot/stackpot/pot/repository/PotRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import stackpot.stackpot.pot.entity.Pot;
import stackpot.stackpot.user.entity.enums.Role;

Expand Down Expand Up @@ -56,9 +57,9 @@ public interface PotRepository extends JpaRepository<Pot, Long> {
@Modifying
@Query("DELETE FROM Pot f WHERE f.user.id = :userId")
void deleteByUserId(@Param("userId") Long userId);
@Modifying
@Query("DELETE FROM Pot p WHERE p.user.id = :userId AND p.potId IN :potIds AND p.potStatus = 'RECRUITING'")
void deleteByUserIdAndPotIds(@Param("userId") Long userId, @Param("potIds") List<Long> potIds);
// @Modifying
// @Query("DELETE FROM Pot p WHERE p.user.id = :userId AND p.potId IN :potIds AND p.potStatus = 'RECRUITING'")
// void deleteByUserIdAndPotIds(@Param("userId") Long userId, @Param("potIds") List<Long> potIds);
boolean existsByUserId(Long userId);

// 지원자 수 기준으로 모든 Pot 정렬
Expand All @@ -85,4 +86,13 @@ List<Long> findIdsByUserIdAndStatus(@Param("userId") Long userId,
@Query("select p.potId from Pot p where p.user.id = :userId and p.potStatus not in :statuses")
List<Long> findIdsByUserIdAndStatusNotIn(@Param("userId") Long userId,
@Param("statuses") List<String> statuses);

@Modifying @Transactional
@Query("""
delete from Pot p
where p.user.id = :userId
and p.potId in :potIds
and p.potStatus = 'RECRUITING'
""")
void deleteByUserIdAndPotIds(@Param("userId") Long userId, @Param("potIds") List<Long> potIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,12 @@ default Map<Long, Integer> countSavesByPotIds(List<Long> potIds) {
void deleteAllByUserAndPots(@Param("user") User user, @Param("pots") List<Pot> pots);

List<PotSave> findByUser(User user);

@Modifying
@Transactional
void deleteByUser(User user);

@Modifying @Transactional
@Query("delete from PotSave ps where ps.pot.potId in :potIds")
int deleteByPotIds(@Param("potIds") List<Long> potIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import stackpot.stackpot.user.repository.TempUserRepository;

import java.time.LocalDateTime;
Expand All @@ -15,7 +16,8 @@ public class TempUserCleanupScheduler {

private final TempUserRepository tempUserRepository;

@Scheduled(cron = "0 0 * * * *") // 매 정시
@Scheduled(cron = "0 0 * * * *")
@Transactional// 매 정시
public void deleteOldTempUsers() {
LocalDateTime oneHourAgo = LocalDateTime.now().minusHours(1);
int deletedCount = tempUserRepository.deleteByCreatedAtBefore(oneHourAgo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,9 @@ public void handleCreatorPotDeletion(User user) {
// PotApplication 삭제
potApplicationRepository.deleteByPotIds(recruitingPotIds);
potRepository.deleteByUserIdAndPotIds(userId, recruitingPotIds);
potSaveRepository.deleteByPotIds(recruitingPotIds);

potRepository.deleteByUserIdAndPotIds(userId, recruitingPotIds);
}


Expand Down Expand Up @@ -470,7 +473,7 @@ public void deletePotAndRelatedData(Pot pot) {
potApplicationRepository.deleteByPotId(pot.getPotId());

potRecruitmentDetailsRepository.deleteByPot_PotId(pot.getPotId());

potSaveRepository.deleteByPotIds(List.of(pot.getPotId()));
// Pot 삭제
potRepository.delete(pot);

Expand Down