From 90fc9d89b84cf14d323881727666586812442c09 Mon Sep 17 00:00:00 2001 From: jongmee Date: Fri, 15 Nov 2024 22:25:23 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=EC=9D=B4=EB=AF=B8=20=EB=B0=9C?= =?UTF-8?q?=ED=91=9C=EB=90=9C=20=EB=AA=A8=EC=A7=91=20=EA=B3=B5=EA=B3=A0?= =?UTF-8?q?=EB=A5=BC=20=EB=AA=A8=EC=A7=91=20=EA=B3=B5=EA=B3=A0=20=EB=A7=88?= =?UTF-8?q?=EA=B0=90=EC=97=90=EC=84=9C=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/crews/recruitment/service/RecruitmentService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/server/crews/recruitment/service/RecruitmentService.java b/src/main/java/com/server/crews/recruitment/service/RecruitmentService.java index f01df84..1aeb9ff 100644 --- a/src/main/java/com/server/crews/recruitment/service/RecruitmentService.java +++ b/src/main/java/com/server/crews/recruitment/service/RecruitmentService.java @@ -147,10 +147,13 @@ public void updateDeadline(Long publisherId, DeadlineUpdateRequest request) { public void closeRecruitments() { LocalDateTime now = LocalDateTime.now(clock); List recruitments = recruitmentRepository.findAll(); + List recruitmentsToBeClosed = recruitments.stream() .filter(recruitment -> recruitment.hasOnOrAfterDeadline(now)) + .filter(recruitment -> !recruitment.isAnnounced()) .toList(); recruitmentsToBeClosed.forEach(Recruitment::close); + String closedRecruitmentIds = recruitmentsToBeClosed.stream() .map(Recruitment::getId) .map(String::valueOf) From 7bfc6e8c6a192d7ef88413470dc33a57fcef72b5 Mon Sep 17 00:00:00 2001 From: jongmee Date: Sat, 16 Nov 2024 01:49:34 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20=EB=A7=88=EA=B0=90=ED=95=A0=20?= =?UTF-8?q?=EB=AA=A8=EC=A7=91=20=EA=B3=B5=EA=B3=A0=20=ED=95=84=ED=84=B0?= =?UTF-8?q?=EB=A7=81=EC=9D=84=20=EC=BF=BC=EB=A6=AC=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../crews/recruitment/domain/Recruitment.java | 3 ++- .../repository/RecruitmentRepository.java | 5 +++++ .../service/RecruitmentService.java | 8 ++------ .../repository/RecruitmentRepositoryTest.java | 18 +++++++++++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/server/crews/recruitment/domain/Recruitment.java b/src/main/java/com/server/crews/recruitment/domain/Recruitment.java index 7fe1307..8e0a075 100644 --- a/src/main/java/com/server/crews/recruitment/domain/Recruitment.java +++ b/src/main/java/com/server/crews/recruitment/domain/Recruitment.java @@ -37,7 +37,8 @@ indexes = { @Index(columnList = "publisher_id", name = "idx_publisher_id"), @Index(columnList = "code", name = "idx_code"), - @Index(columnList = "title", name = "idx_title") + @Index(columnList = "title", name = "idx_title"), + @Index(columnList = "deadline, progress", name = "idx_deadline_progress") } ) @EntityListeners(AuditingEntityListener.class) diff --git a/src/main/java/com/server/crews/recruitment/repository/RecruitmentRepository.java b/src/main/java/com/server/crews/recruitment/repository/RecruitmentRepository.java index 9c6435e..2acba6e 100644 --- a/src/main/java/com/server/crews/recruitment/repository/RecruitmentRepository.java +++ b/src/main/java/com/server/crews/recruitment/repository/RecruitmentRepository.java @@ -1,6 +1,9 @@ package com.server.crews.recruitment.repository; import com.server.crews.recruitment.domain.Recruitment; +import com.server.crews.recruitment.domain.RecruitmentProgress; +import java.time.LocalDateTime; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -41,4 +44,6 @@ public interface RecruitmentRepository extends JpaRepository where r.title = :title """) Optional findWithSectionsByTitle(@Param("title") String title); + + List findByDeadlineLessThanEqualAndProgressNot(LocalDateTime deadline, RecruitmentProgress progress); } diff --git a/src/main/java/com/server/crews/recruitment/service/RecruitmentService.java b/src/main/java/com/server/crews/recruitment/service/RecruitmentService.java index 1aeb9ff..297f83e 100644 --- a/src/main/java/com/server/crews/recruitment/service/RecruitmentService.java +++ b/src/main/java/com/server/crews/recruitment/service/RecruitmentService.java @@ -146,12 +146,8 @@ public void updateDeadline(Long publisherId, DeadlineUpdateRequest request) { @Scheduled(cron = "${schedules.cron.closing-recruitment}") public void closeRecruitments() { LocalDateTime now = LocalDateTime.now(clock); - List recruitments = recruitmentRepository.findAll(); - - List recruitmentsToBeClosed = recruitments.stream() - .filter(recruitment -> recruitment.hasOnOrAfterDeadline(now)) - .filter(recruitment -> !recruitment.isAnnounced()) - .toList(); + List recruitmentsToBeClosed = recruitmentRepository.findByDeadlineLessThanEqualAndProgressNot(now, + RecruitmentProgress.ANNOUNCED); recruitmentsToBeClosed.forEach(Recruitment::close); String closedRecruitmentIds = recruitmentsToBeClosed.stream() diff --git a/src/test/java/com/server/crews/recruitment/repository/RecruitmentRepositoryTest.java b/src/test/java/com/server/crews/recruitment/repository/RecruitmentRepositoryTest.java index 860b22f..aa4f6cb 100644 --- a/src/test/java/com/server/crews/recruitment/repository/RecruitmentRepositoryTest.java +++ b/src/test/java/com/server/crews/recruitment/repository/RecruitmentRepositoryTest.java @@ -11,8 +11,9 @@ import com.server.crews.auth.domain.Administrator; import com.server.crews.environ.repository.RepositoryTest; import com.server.crews.recruitment.domain.Recruitment; -import com.server.crews.recruitment.repository.RecruitmentRepository; +import com.server.crews.recruitment.domain.RecruitmentProgress; import jakarta.validation.ConstraintViolationException; +import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -51,4 +52,19 @@ void saveWithValidation() { assertThatThrownBy(() -> recruitmentRepository.save(recruitment)) .isInstanceOf(ConstraintViolationException.class); } + + @Test + @DisplayName("기준보다 이전 마감일과 모집 단계로 모집 공고 목록을 조회한다.") + void findByDeadlineLessThanEqualAndProgressNot() { + // given + Administrator publisher = createDefaultAdmin(); + createDefaultRecruitment(publisher); + + // when + List recruitments = recruitmentRepository.findByDeadlineLessThanEqualAndProgressNot( + LocalDateTime.of(2030, 10, 5, 18, 0), RecruitmentProgress.ANNOUNCED); + + // then + assertThat(recruitments).hasSize(1); + } }