Skip to content

Commit

Permalink
배포 1.1.8
Browse files Browse the repository at this point in the history
Merge pull request #123 from team-crews/hotfix/close-recruitments
  • Loading branch information
jongmee authored Nov 15, 2024
2 parents 9b5b3cd + 7bfc6e8 commit a6c05a5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,4 +44,6 @@ public interface RecruitmentRepository extends JpaRepository<Recruitment, Long>
where r.title = :title
""")
Optional<Recruitment> findWithSectionsByTitle(@Param("title") String title);

List<Recruitment> findByDeadlineLessThanEqualAndProgressNot(LocalDateTime deadline, RecruitmentProgress progress);
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@ public void updateDeadline(Long publisherId, DeadlineUpdateRequest request) {
@Scheduled(cron = "${schedules.cron.closing-recruitment}")
public void closeRecruitments() {
LocalDateTime now = LocalDateTime.now(clock);
List<Recruitment> recruitments = recruitmentRepository.findAll();
List<Recruitment> recruitmentsToBeClosed = recruitments.stream()
.filter(recruitment -> recruitment.hasOnOrAfterDeadline(now))
.toList();
List<Recruitment> recruitmentsToBeClosed = recruitmentRepository.findByDeadlineLessThanEqualAndProgressNot(now,
RecruitmentProgress.ANNOUNCED);
recruitmentsToBeClosed.forEach(Recruitment::close);

String closedRecruitmentIds = recruitmentsToBeClosed.stream()
.map(Recruitment::getId)
.map(String::valueOf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Recruitment> recruitments = recruitmentRepository.findByDeadlineLessThanEqualAndProgressNot(
LocalDateTime.of(2030, 10, 5, 18, 0), RecruitmentProgress.ANNOUNCED);

// then
assertThat(recruitments).hasSize(1);
}
}

0 comments on commit a6c05a5

Please sign in to comment.