diff --git a/src/main/java/com/ssafy/ssafsound/domain/recruit/controller/RecruitController.java b/src/main/java/com/ssafy/ssafsound/domain/recruit/controller/RecruitController.java index b41b3a680..b0ebef9b2 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/recruit/controller/RecruitController.java +++ b/src/main/java/com/ssafy/ssafsound/domain/recruit/controller/RecruitController.java @@ -8,7 +8,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; -import org.springframework.data.web.PageableDefault; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; diff --git a/src/main/java/com/ssafy/ssafsound/domain/recruit/domain/Recruit.java b/src/main/java/com/ssafy/ssafsound/domain/recruit/domain/Recruit.java index 678bae988..b1692d9f1 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/recruit/domain/Recruit.java +++ b/src/main/java/com/ssafy/ssafsound/domain/recruit/domain/Recruit.java @@ -12,6 +12,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.Where; import javax.persistence.*; import java.time.LocalDateTime; @@ -24,6 +25,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@Where(clause = "deleted_recruit = false") public class Recruit extends BaseTimeEntity { @Id diff --git a/src/main/java/com/ssafy/ssafsound/domain/recruit/event/RecruitEventListener.java b/src/main/java/com/ssafy/ssafsound/domain/recruit/event/RecruitEventListener.java index 4698da9a3..a4c476fce 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/recruit/event/RecruitEventListener.java +++ b/src/main/java/com/ssafy/ssafsound/domain/recruit/event/RecruitEventListener.java @@ -1,6 +1,7 @@ package com.ssafy.ssafsound.domain.recruit.event; import com.ssafy.ssafsound.domain.event.MemberLeavedEvent; +import com.ssafy.ssafsound.domain.recruit.repository.RecruitLimitationRepository; import com.ssafy.ssafsound.domain.recruit.repository.RecruitRepository; import com.ssafy.ssafsound.domain.recruitapplication.repository.RecruitApplicationRepository; import lombok.RequiredArgsConstructor; @@ -15,6 +16,7 @@ public class RecruitEventListener { private final RecruitRepository recruitRepository; + private final RecruitLimitationRepository recruitLimitationRepository private final RecruitApplicationRepository recruitApplicationrepository; @TransactionalEventListener(phase = TransactionPhase.BEFORE_COMMIT) @@ -22,6 +24,7 @@ public void transactionalEventListenerAfterCommit(MemberLeavedEvent memberLeaved Long memberId = memberLeavedEvent.getMemberId(); log.info("{} 회원 탈퇴로 인한 등록 리크루트글 일괄 삭제 및 리크루트 신청 일괄 취소", memberLeavedEvent.getMemberId()); recruitRepository.deleteAllByMemberId(memberId); + recruitLimitationRepository.decreaseCurrentNumberByMemberId(memberId); recruitApplicationrepository.cancelAllByMemberId(memberId); } } diff --git a/src/main/java/com/ssafy/ssafsound/domain/recruit/repository/RecruitLimitationRepository.java b/src/main/java/com/ssafy/ssafsound/domain/recruit/repository/RecruitLimitationRepository.java index 85ee964d6..8b6a5351c 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/recruit/repository/RecruitLimitationRepository.java +++ b/src/main/java/com/ssafy/ssafsound/domain/recruit/repository/RecruitLimitationRepository.java @@ -3,6 +3,8 @@ import com.ssafy.ssafsound.domain.recruit.domain.Recruit; import com.ssafy.ssafsound.domain.recruit.domain.RecruitLimitation; 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 java.util.List; @@ -11,4 +13,15 @@ public interface RecruitLimitationRepository extends JpaRepository findByRecruitId(Long recruitId); void deleteAllByRecruit(@Param("recruit") Recruit recruit); + + @Modifying + @Query(value = "update recruit_limitation rl " + + "set rl.currentNumber = rl.currentNumber-1 " + + "where (rl.recruit, rl.type) in " + + "(" + + " select ra.recruit, ra.type from recruit_application ra " + + " where ra.matchStatus = com.ssafy.ssafsound.domain.recruitapplication.domain.MatchStatus.DONE and ra.member.id = :memberId" + + ")" + ) + void decreaseCurrentNumberByMemberId(Long memberId); } diff --git a/src/main/java/com/ssafy/ssafsound/domain/recruitapplication/domain/RecruitApplication.java b/src/main/java/com/ssafy/ssafsound/domain/recruitapplication/domain/RecruitApplication.java index 8e66f0d2a..aca1c9499 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/recruitapplication/domain/RecruitApplication.java +++ b/src/main/java/com/ssafy/ssafsound/domain/recruitapplication/domain/RecruitApplication.java @@ -9,6 +9,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.Where; import javax.persistence.*; @@ -17,6 +18,7 @@ @Builder @NoArgsConstructor @AllArgsConstructor +@Where(clause = "match_status != 'CANCEL'") public class RecruitApplication extends BaseTimeEntity { @Id