Skip to content

Commit

Permalink
refactor: Period를 외부에서 생성된 상태로 받도록 수정 (#793)
Browse files Browse the repository at this point in the history
* refactor: RequiredArgs 생성자로 변경

* refactor: 생성된 Period를 인자로 받도록 수정

* refactor: START_TO_END_PERIOD 상수를 사용하도록 변경

* refactor: STUDY_ONGOING_PERIOD 적용

* feat: 2차 모집기간 상수 추가

* style: spotless 적용
  • Loading branch information
uwoobeat authored Oct 12, 2024
1 parent f12092a commit 382ac9a
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public void createRecruitmentRound(RecruitmentRoundCreateRequest request) {
recruitmentRoundsInThisSemester);

RecruitmentRound recruitmentRound = RecruitmentRound.create(
request.name(), request.startDate(), request.endDate(), recruitment, request.roundType());
request.name(),
Period.createPeriod(request.startDate(), request.endDate()),
recruitment,
request.roundType());
recruitmentRoundRepository.save(recruitmentRound);

log.info("[AdminRecruitmentService] 모집회차 생성: recruitmentRoundId={}", recruitmentRound.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ private RecruitmentRound(
this.roundType = roundType;
}

public static RecruitmentRound create(
String name, LocalDateTime startDate, LocalDateTime endDate, Recruitment recruitment, RoundType roundType) {
Period period = Period.createPeriod(startDate, endDate);
public static RecruitmentRound create(String name, Period period, Recruitment recruitment, RoundType roundType) {
return RecruitmentRound.builder()
.name(name)
.period(period)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.gdschongik.gdsc.domain.recruitment.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@AllArgsConstructor
@RequiredArgsConstructor
public enum RoundType {
FIRST("1차"),
SECOND("2차");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class 준회원으로_일괄_강등시 {
@Test
void 해당_학기에_이미_시작된_모집기간이_있다면_실패한다() {
// given
Recruitment recruitment = Recruitment.createRecruitment(
ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, Period.createPeriod(START_DATE, END_DATE));
Recruitment recruitment =
Recruitment.createRecruitment(ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, START_TO_END_PERIOD);
LocalDateTime now = LocalDateTime.now();
RecruitmentRound recruitmentRound = RecruitmentRound.create(
RECRUITMENT_ROUND_NAME,
LocalDateTime.now().minusDays(1),
LocalDateTime.now().plusDays(1),
Period.createPeriod(now.minusDays(1), now.plusDays(1)),
recruitment,
ROUND_TYPE);
List<RecruitmentRound> recruitmentRounds = List.of(recruitmentRound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class 멤버십_가입신청시 {
FEE_NAME,
Period.createPeriod(SEMESTER_START_DATE, SEMESTER_END_DATE));
RecruitmentRound recruitmentRound =
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_DATE, END_DATE, recruitment, ROUND_TYPE);
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_TO_END_PERIOD, recruitment, ROUND_TYPE);

// when
Membership membership = Membership.createMembership(member, recruitmentRound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ private RecruitmentRound createRecruitmentRound(
LocalDateTime endDate) {
Recruitment recruitment = Recruitment.createRecruitment(
academicYear, semesterType, fee, FEE_NAME, Period.createPeriod(SEMESTER_START_DATE, SEMESTER_END_DATE));
return RecruitmentRound.create(RECRUITMENT_ROUND_NAME, startDate, endDate, recruitment, ROUND_TYPE);
return RecruitmentRound.create(
RECRUITMENT_ROUND_NAME, Period.createPeriod(startDate, endDate), recruitment, ROUND_TYPE);
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ class 모집회차_수정시 {
recruitmentRepository.save(recruitment);

RecruitmentRound recruitmentRound = RecruitmentRound.create(
RECRUITMENT_ROUND_NAME, now.plusDays(1), now.plusDays(2), recruitment, ROUND_TYPE);
RECRUITMENT_ROUND_NAME,
Period.createPeriod(now.plusDays(1), now.plusDays(2)),
recruitment,
ROUND_TYPE);
recruitmentRoundRepository.save(recruitmentRound);

RecruitmentRoundUpdateRequest request = new RecruitmentRoundUpdateRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class 모집회차_생성시 {
@Test
void 모집_시작일과_종료일이_학기_시작일로부터_2_이내에_있지_않다면_실패한다() {
// given
Recruitment recruitment = Recruitment.createRecruitment(
ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, Period.createPeriod(START_DATE, END_DATE));
Recruitment recruitment =
Recruitment.createRecruitment(ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, START_TO_END_PERIOD);

// when & then
assertThatThrownBy(() -> recruitmentRoundValidator.validateRecruitmentRoundCreate(
Expand All @@ -71,11 +71,11 @@ class 모집회차_생성시 {
@Test
void 학년도_학기_차수가_모두_중복되면_실패한다() {
// given
Recruitment recruitment = Recruitment.createRecruitment(
ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, Period.createPeriod(START_DATE, END_DATE));
Recruitment recruitment =
Recruitment.createRecruitment(ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, START_TO_END_PERIOD);

RecruitmentRound recruitmentRound =
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_DATE, END_DATE, recruitment, ROUND_TYPE);
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_TO_END_PERIOD, recruitment, ROUND_TYPE);

// when & then
assertThatThrownBy(() -> recruitmentRoundValidator.validateRecruitmentRoundCreate(
Expand All @@ -91,8 +91,8 @@ class 모집회차_생성시 {
@Test
void RoundType_1가_없을때_2차를_생성하려_하면_실패한다() {
// given
Recruitment recruitment = Recruitment.createRecruitment(
ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, Period.createPeriod(START_DATE, END_DATE));
Recruitment recruitment =
Recruitment.createRecruitment(ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, START_TO_END_PERIOD);

// when & then
assertThatThrownBy(() -> recruitmentRoundValidator.validateRecruitmentRoundCreate(
Expand All @@ -104,11 +104,11 @@ class 모집회차_생성시 {
@Test
void 기간이_중복되는_모집회차가_있다면_실패한다() {
// given
Recruitment recruitment = Recruitment.createRecruitment(
ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, Period.createPeriod(START_DATE, END_DATE));
Recruitment recruitment =
Recruitment.createRecruitment(ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, START_TO_END_PERIOD);

RecruitmentRound recruitmentRound =
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_DATE, END_DATE, recruitment, ROUND_TYPE);
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_TO_END_PERIOD, recruitment, ROUND_TYPE);

// when & then
assertThatThrownBy(() -> recruitmentRoundValidator.validateRecruitmentRoundCreate(
Expand All @@ -124,15 +124,15 @@ class 모집회차_수정시 {
@Test
void 기간이_중복되는_모집회차가_있다면_실패한다() {
// given
Recruitment recruitment = Recruitment.createRecruitment(
ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, Period.createPeriod(START_DATE, END_DATE));
Recruitment recruitment =
Recruitment.createRecruitment(ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, START_TO_END_PERIOD);

RecruitmentRound firstRound =
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_DATE, END_DATE, recruitment, ROUND_TYPE);
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_TO_END_PERIOD, recruitment, ROUND_TYPE);
ReflectionTestUtils.setField(firstRound, "id", 1L);

RecruitmentRound secondRound = RecruitmentRound.create(
RECRUITMENT_ROUND_NAME, ROUND_TWO_START_DATE, ROUND_TWO_END_DATE, recruitment, RoundType.SECOND);
RECRUITMENT_ROUND_NAME, ROUND_TWO_START_TO_END_PERIOD, recruitment, RoundType.SECOND);
ReflectionTestUtils.setField(secondRound, "id", 2L);

// when & then
Expand All @@ -145,15 +145,15 @@ class 모집회차_수정시 {
@Test
void 차수가_중복되는_모집회차가_있다면_실패한다() {
// given
Recruitment recruitment = Recruitment.createRecruitment(
ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, Period.createPeriod(START_DATE, END_DATE));
Recruitment recruitment =
Recruitment.createRecruitment(ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, START_TO_END_PERIOD);

RecruitmentRound firstRound =
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_DATE, END_DATE, recruitment, ROUND_TYPE);
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_TO_END_PERIOD, recruitment, ROUND_TYPE);
ReflectionTestUtils.setField(firstRound, "id", 1L);

RecruitmentRound secondRound = RecruitmentRound.create(
RECRUITMENT_ROUND_NAME, ROUND_TWO_START_DATE, ROUND_TWO_END_DATE, recruitment, RoundType.SECOND);
RECRUITMENT_ROUND_NAME, ROUND_TWO_START_TO_END_PERIOD, recruitment, RoundType.SECOND);
ReflectionTestUtils.setField(secondRound, "id", 2L);

// when & then
Expand All @@ -166,11 +166,11 @@ class 모집회차_수정시 {
@Test
void 모집_시작일과_종료일이_학기_시작일로부터_2_이내에_있지_않다면_실패한다() {
// given
Recruitment recruitment = Recruitment.createRecruitment(
ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, Period.createPeriod(START_DATE, END_DATE));
Recruitment recruitment =
Recruitment.createRecruitment(ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, START_TO_END_PERIOD);

RecruitmentRound firstRound =
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_DATE, END_DATE, recruitment, ROUND_TYPE);
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_TO_END_PERIOD, recruitment, ROUND_TYPE);
ReflectionTestUtils.setField(firstRound, "id", 1L);

// when & then
Expand All @@ -183,11 +183,11 @@ class 모집회차_수정시 {
@Test
void RoundType_1차를_2차로_수정하려_하면_실패한다() {
// given
Recruitment recruitment = Recruitment.createRecruitment(
ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, Period.createPeriod(START_DATE, END_DATE));
Recruitment recruitment =
Recruitment.createRecruitment(ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, START_TO_END_PERIOD);

RecruitmentRound firstRound =
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_DATE, END_DATE, recruitment, ROUND_TYPE);
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_TO_END_PERIOD, recruitment, ROUND_TYPE);
ReflectionTestUtils.setField(firstRound, "id", 1L);

// when & then
Expand All @@ -200,11 +200,11 @@ class 모집회차_수정시 {
@Test
void 모집_시작일이_지났다면_수정_실패한다() {
// given
Recruitment recruitment = Recruitment.createRecruitment(
ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, Period.createPeriod(START_DATE, END_DATE));
Recruitment recruitment =
Recruitment.createRecruitment(ACADEMIC_YEAR, SEMESTER_TYPE, FEE, FEE_NAME, START_TO_END_PERIOD);

RecruitmentRound recruitmentRound =
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_DATE, END_DATE, recruitment, ROUND_TYPE);
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_TO_END_PERIOD, recruitment, ROUND_TYPE);
long recruitmentRoundId = 1L;
ReflectionTestUtils.setField(recruitmentRound, "id", recruitmentRoundId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ private AssignmentHistory createAssignmentHistory() {
}

private Study createStudyWithMentor(Long mentorId) {
Period period = Period.createPeriod(STUDY_START_DATETIME, STUDY_END_DATETIME);
Period applicationPeriod =
Period.createPeriod(STUDY_START_DATETIME.minusDays(7), STUDY_START_DATETIME.minusDays(1));
return fixtureHelper.createStudyWithMentor(mentorId, period, applicationPeriod);
return fixtureHelper.createStudyWithMentor(mentorId, STUDY_ONGOING_PERIOD, applicationPeriod);
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ private Member createMember(Long id) {
}

private Study createStudyWithMentor(Long mentorId) {
Period period = Period.createPeriod(STUDY_START_DATETIME, STUDY_END_DATETIME);
Period applicationPeriod =
Period.createPeriod(STUDY_START_DATETIME.minusDays(7), STUDY_START_DATETIME.minusDays(1));
return fixtureHelper.createStudyWithMentor(mentorId, period, applicationPeriod);
return fixtureHelper.createStudyWithMentor(mentorId, STUDY_ONGOING_PERIOD, applicationPeriod);
}

private StudyDetail createStudyDetailWithAssignment(Study study) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ private Member createMember(Long id) {
}

private Study createStudyWithMentor(Long mentorId) {
Period period = Period.createPeriod(STUDY_START_DATETIME, STUDY_END_DATETIME);
Period applicationPeriod =
Period.createPeriod(STUDY_START_DATETIME.minusDays(7), STUDY_START_DATETIME.minusDays(1));
return fixtureHelper.createStudyWithMentor(mentorId, period, applicationPeriod);
return fixtureHelper.createStudyWithMentor(mentorId, STUDY_ONGOING_PERIOD, applicationPeriod);
}

private StudyDetail createStudyDetailWithAssignment(Study study) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class 스터디_개설시 {
void 게스트인_회원을_멘토로_지정하면_실패한다() {
// given
Member guestMember = Member.createGuestMember(OAUTH_ID);
Period period = Period.createPeriod(START_DATE, END_DATE);
Period applicationPeriod = Period.createPeriod(START_DATE.minusDays(10), START_DATE.minusDays(5));

// when & then
Expand All @@ -46,7 +45,7 @@ class 스터디_개설시 {
SEMESTER_TYPE,
STUDY_TITLE,
guestMember,
period,
START_TO_END_PERIOD,
applicationPeriod,
TOTAL_WEEK,
ONLINE_STUDY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gdschongik.gdsc.domain.common.vo.Money;
import com.gdschongik.gdsc.domain.recruitment.domain.RoundType;
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period;
import java.math.BigDecimal;
import java.time.LocalDateTime;

Expand All @@ -12,6 +13,7 @@ public class RecruitmentConstant {
public static final LocalDateTime BETWEEN_START_AND_END_DATE = LocalDateTime.of(2024, 3, 3, 0, 0);
public static final LocalDateTime WRONG_END_DATE = LocalDateTime.of(2024, 3, 2, 0, 0);
public static final LocalDateTime END_DATE = LocalDateTime.of(2024, 3, 5, 0, 0);
public static final Period START_TO_END_PERIOD = Period.createPeriod(START_DATE, END_DATE);

public static final Money FEE = Money.from(20000L);
public static final BigDecimal FEE_AMOUNT = BigDecimal.valueOf(20000);
Expand All @@ -22,6 +24,8 @@ public class RecruitmentConstant {
public static final String ROUND_TWO_RECRUITMENT_NAME = "2024학년도 1학기 2차 모집";
public static final LocalDateTime ROUND_TWO_START_DATE = LocalDateTime.of(2024, 3, 8, 0, 0);
public static final LocalDateTime ROUND_TWO_END_DATE = LocalDateTime.of(2024, 3, 10, 0, 0);
public static final Period ROUND_TWO_START_TO_END_PERIOD =
Period.createPeriod(ROUND_TWO_START_DATE, ROUND_TWO_END_DATE);

private RecruitmentConstant() {}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gdschongik.gdsc.global.common.constant;

import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period;
import com.gdschongik.gdsc.domain.study.domain.StudyType;
import java.time.DayOfWeek;
import java.time.LocalDateTime;
Expand All @@ -26,6 +27,7 @@ private StudyConstant() {}
// Study (2024-09-01 ~ 2024-10-27)
public static final LocalDateTime STUDY_START_DATETIME = LocalDateTime.of(2024, 9, 1, 0, 0);
public static final LocalDateTime STUDY_END_DATETIME = STUDY_START_DATETIME.plusWeeks(8);
public static final Period STUDY_ONGOING_PERIOD = Period.createPeriod(STUDY_START_DATETIME, STUDY_END_DATETIME);
public static final String STUDY_NOTION_LINK = "notionLink";
public static final String STUDY_INTRODUCTION = "introduction";

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public RecruitmentRound createRecruitmentRound(
Recruitment recruitment = Recruitment.createRecruitment(
academicYear, semesterType, fee, FEE_NAME, Period.createPeriod(SEMESTER_START_DATE, SEMESTER_END_DATE));

return RecruitmentRound.create(RECRUITMENT_ROUND_NAME, startDate, endDate, recruitment, RoundType.FIRST);
return RecruitmentRound.create(
RECRUITMENT_ROUND_NAME, Period.createPeriod(startDate, endDate), recruitment, RoundType.FIRST);
}

public Membership createMembership(Member member, RecruitmentRound recruitmentRound) {
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/com/gdschongik/gdsc/helper/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected RecruitmentRound createRecruitmentRound() {
Recruitment recruitment = createRecruitment(ACADEMIC_YEAR, SEMESTER_TYPE, FEE);

RecruitmentRound recruitmentRound =
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_DATE, END_DATE, recruitment, ROUND_TYPE);
RecruitmentRound.create(RECRUITMENT_ROUND_NAME, START_TO_END_PERIOD, recruitment, ROUND_TYPE);

return recruitmentRoundRepository.save(recruitmentRound);
}
Expand All @@ -205,7 +205,8 @@ protected RecruitmentRound createRecruitmentRound(
Money fee) {
Recruitment recruitment = createRecruitment(academicYear, semesterType, fee);

RecruitmentRound recruitmentRound = RecruitmentRound.create(name, startDate, endDate, recruitment, roundType);
RecruitmentRound recruitmentRound =
RecruitmentRound.create(name, Period.createPeriod(startDate, endDate), recruitment, roundType);
return recruitmentRoundRepository.save(recruitmentRound);
}

Expand Down

0 comments on commit 382ac9a

Please sign in to comment.