From 72a2e1de1e2794e04071b9134f3569a5abdc4519 Mon Sep 17 00:00:00 2001 From: khs960616 <55014803+khs960616@users.noreply.github.com> Date: Thu, 26 Oct 2023 00:28:33 +0900 Subject: [PATCH] =?UTF-8?q?hotfix:=20=ED=9A=8C=EC=9B=90=ED=83=88=ED=87=B4?= =?UTF-8?q?=20=EB=A6=AC=ED=81=AC=EB=A3=A8=ED=8A=B8=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=ED=95=AB=ED=94=BD=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 삭제된 리크루트가 조회되지 않도록 엔티티 클래스의 where clause 추가 * chore: 미사용 import 제거 * fix: 매칭 완료된 리크루트 존재시, current number 일괄 변경 추가 --- .../recruit/controller/RecruitController.java | 1 - .../ssafsound/domain/recruit/domain/Recruit.java | 2 ++ .../recruit/dto/RecruitOffsetPagingRequestDto.java | 5 ++++- .../domain/recruit/event/RecruitEventListener.java | 3 +++ .../repository/RecruitLimitationRepository.java | 13 +++++++++++++ .../domain/RecruitApplication.java | 2 ++ .../repository/RecruitApplicationRepository.java | 7 ++++++- 7 files changed, 30 insertions(+), 3 deletions(-) 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/dto/RecruitOffsetPagingRequestDto.java b/src/main/java/com/ssafy/ssafsound/domain/recruit/dto/RecruitOffsetPagingRequestDto.java index 6df777459..6483a468b 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/recruit/dto/RecruitOffsetPagingRequestDto.java +++ b/src/main/java/com/ssafy/ssafsound/domain/recruit/dto/RecruitOffsetPagingRequestDto.java @@ -1,10 +1,13 @@ package com.ssafy.ssafsound.domain.recruit.dto; import lombok.Getter; +import lombok.Setter; + import net.minidev.json.annotate.JsonIgnore; import org.springframework.data.domain.PageRequest; @Getter +@Setter public class RecruitOffsetPagingRequestDto { protected Integer page; @@ -12,7 +15,7 @@ public class RecruitOffsetPagingRequestDto { @JsonIgnore public PageRequest getPageRequest() { - int page = (this.page != null && this.page >= 0) ? this.page-1 : 0; + int page = (this.page != null && this.page > 0) ? this.page-1 : 0; int size = this.size == null ? 10 : this.size; return PageRequest.of(page, size); } 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..17a41b338 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 diff --git a/src/main/java/com/ssafy/ssafsound/domain/recruitapplication/repository/RecruitApplicationRepository.java b/src/main/java/com/ssafy/ssafsound/domain/recruitapplication/repository/RecruitApplicationRepository.java index 4514f6e7c..c108449ed 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/recruitapplication/repository/RecruitApplicationRepository.java +++ b/src/main/java/com/ssafy/ssafsound/domain/recruitapplication/repository/RecruitApplicationRepository.java @@ -50,6 +50,11 @@ public interface RecruitApplicationRepository extends JpaRepository