Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Period를 외부에서 생성된 상태로 받도록 수정 #793

Merged
merged 6 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,18 @@ 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);
Comment on lines +148 to +149
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

일관된 변경 승인 및 불일치 사항 재확인 필요

151-152행과 155행의 변경사항은 이전 세그먼트들과 일관되게 START_TO_END_PERIOD를 사용하고 있어 적절합니다.

하지만 159-162행은 이전 세그먼트에서 지적한 것과 동일한 문제가 있습니다:

  1. Period.createPeriod 사용이 파일의 다른 부분과 일치하지 않습니다.
  2. 종료 날짜 매개변수에 ROUND_TWO_START_DATE를 사용하고 있어 오타일 가능성이 있습니다.

이 부분을 검토하고 필요한 경우 수정해 주시기 바랍니다.

Also applies to: 155-155, 159-162


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 +169,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 +186,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 +203,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,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 @@ -194,7 +194,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);
Comment on lines +197 to +198
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Period 객체를 메서드 파라미터로 받도록 개선이 필요합니다.

현재 구현은 Period 객체를 사용하도록 개선되었지만, PR의 목표를 완전히 달성하지 못했습니다. 다음과 같은 개선을 제안합니다:

  1. startDateendDate 대신 Period 객체를 직접 메서드 파라미터로 받도록 변경하세요.
  2. 메서드 내에서 Period.createPeriod()를 호출하는 대신, 외부에서 생성된 Period를 사용하세요.

다음과 같이 메서드 시그니처를 변경하고 구현을 수정하는 것을 고려해보세요:

 protected RecruitmentRound createRecruitmentRound(
         String name,
-        LocalDateTime startDate,
-        LocalDateTime endDate,
+        Period period,
         Integer academicYear,
         SemesterType semesterType,
         RoundType roundType,
         Money fee) {
     Recruitment recruitment = createRecruitment(academicYear, semesterType, fee);
     RecruitmentRound recruitmentRound =
-            RecruitmentRound.create(name, Period.createPeriod(startDate, endDate), recruitment, roundType);
+            RecruitmentRound.create(name, period, recruitment, roundType);
     return recruitmentRoundRepository.save(recruitmentRound);
 }

이렇게 변경하면 PR의 목표인 "Period를 외부에서 생성된 상태로 받도록 수정"을 완전히 달성할 수 있습니다.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
RecruitmentRound recruitmentRound =
RecruitmentRound.create(name, Period.createPeriod(startDate, endDate), recruitment, roundType);
RecruitmentRound recruitmentRound =
RecruitmentRound.create(name, period, recruitment, roundType);

return recruitmentRoundRepository.save(recruitmentRound);
}

Expand Down
Loading