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: VO의 정적 팩토리 메서드 네이밍 변경 #804

Merged
merged 20 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
95d3db5
refactor: Period 정적 팩토리 이름 변경
uwoobeat Oct 12, 2024
af5a394
refactor: Period VO를 common 패키지로 이동
uwoobeat Oct 12, 2024
87d7b46
feat: Period를 상속 불가능하게 변경
uwoobeat Oct 12, 2024
e77e907
refactor: EqualsAndHashCode 사용하도록 변경
uwoobeat Oct 12, 2024
eeb8aa0
refactor: 상수 위치 변경
uwoobeat Oct 12, 2024
e1bc9a9
docs: 주석 추가
uwoobeat Oct 12, 2024
7744b00
refactor: Assignment VO 정적 팩토리 이름 변경
uwoobeat Oct 12, 2024
0a6c811
refactor: MoneyInfo VO 정적 팩토리 이름 변경
uwoobeat Oct 12, 2024
de2ad71
docs: 투두 주석 추가
uwoobeat Oct 12, 2024
7e562bf
refactor: 준회원 승급조건 VO 정적 팩토리 이름 변경
uwoobeat Oct 12, 2024
beb4fa7
refactor: 정회원 승급조건 VO 정적 팩토리 이름 변경
uwoobeat Oct 12, 2024
785e51b
refactor: 커리큘럼 VO 정적 팩토리 이름 변경
uwoobeat Oct 12, 2024
a47453c
refactor: 정적 팩토리 이름 unsatisfied로 변경
uwoobeat Oct 15, 2024
71b8636
refactor: MoneyInfo 정적 팩토리 이름 변경
uwoobeat Oct 15, 2024
086d284
refactor: Attendance 정적 팩토리 이름 변경
uwoobeat Oct 15, 2024
3f0edc1
refactor: Assignment 정적 팩토리 이름 변경
uwoobeat Oct 15, 2024
eee5c51
refactor: 스터디상세 정적 팩토리 이름 변경
uwoobeat Oct 15, 2024
1f23e78
refactor: 엔티티 정적 팩토리 이름 변경
uwoobeat Oct 15, 2024
941b25b
docs: 주석 및 로그 표현 수정
uwoobeat Oct 15, 2024
fc2f783
refactor: 커리큘럼 VO 정적 팩토리 이름 변경
uwoobeat Oct 15, 2024
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 @@ -17,6 +17,8 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public final class Money {

public static final Money ZERO = Money.from(BigDecimal.ZERO);

private BigDecimal amount;

@Override
Expand All @@ -34,8 +36,6 @@ private Money(BigDecimal amount) {
this.amount = amount;
}

public static final Money ZERO = Money.from(BigDecimal.ZERO);

public static Money from(BigDecimal amount) {
validateAmountNotNull(amount);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.gdschongik.gdsc.domain.recruitment.domain.vo;
package com.gdschongik.gdsc.domain.common.vo;

import static com.gdschongik.gdsc.global.exception.ErrorCode.*;

import com.gdschongik.gdsc.global.exception.CustomException;
import jakarta.persistence.Embeddable;
import java.time.LocalDateTime;
import java.util.Objects;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Embeddable
@EqualsAndHashCode
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Period {
public final class Period {

private LocalDateTime startDate;

private LocalDateTime endDate;
Expand All @@ -25,7 +27,7 @@ private Period(final LocalDateTime startDate, final LocalDateTime endDate) {
this.endDate = endDate;
}

public static Period createPeriod(LocalDateTime startDate, LocalDateTime endDate) {
public static Period of(LocalDateTime startDate, LocalDateTime endDate) {
validatePeriod(startDate, endDate);
return Period.builder().startDate(startDate).endDate(endDate).build();
}
Expand All @@ -37,6 +39,7 @@ private static void validatePeriod(LocalDateTime startDate, LocalDateTime endDat
}

public boolean isOpen() {
// TODO: now를 내부에서 선언하지 않고 파라미터로 받아서 테스트 가능하도록 변경
LocalDateTime now = LocalDateTime.now();
return (now.isAfter(startDate) || now.isEqual(startDate)) && (now.isBefore(endDate) || now.isEqual(startDate));
}
Expand All @@ -46,17 +49,4 @@ public void validatePeriodOverlap(LocalDateTime startDate, LocalDateTime endDate
throw new CustomException(PERIOD_OVERLAP);
}
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Period that = (Period) o;
return startDate == that.startDate && endDate == that.endDate;
}

@Override
public int hashCode() {
return Objects.hash(startDate, endDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class CouponService {

@Transactional
public void createCoupon(CouponCreateRequest request) {
Coupon coupon = Coupon.createCoupon(request.name(), Money.from(request.discountAmount()));
Coupon coupon = Coupon.create(request.name(), Money.from(request.discountAmount()));
couponRepository.save(coupon);
log.info("[CouponService] 쿠폰 생성: name={}, discountAmount={}", request.name(), request.discountAmount());
}
Expand All @@ -59,7 +59,7 @@ public void createIssuedCoupon(CouponIssueRequest request) {
List<Member> members = memberRepository.findAllById(request.memberIds());

List<IssuedCoupon> issuedCoupons = members.stream()
.map(member -> IssuedCoupon.issue(coupon, member))
.map(member -> IssuedCoupon.create(coupon, member))
.toList();

issuedCouponRepository.saveAll(issuedCoupons);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private Coupon(String name, Money discountAmount) {
this.discountAmount = discountAmount;
}

public static Coupon createCoupon(String name, Money discountAmount) {
public static Coupon create(String name, Money discountAmount) {
validateDiscountAmountPositive(discountAmount);
return Coupon.builder().name(name).discountAmount(discountAmount).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private IssuedCoupon(Coupon coupon, Member member, Boolean hasRevoked) {
this.hasRevoked = hasRevoked;
}

public static IssuedCoupon issue(Coupon coupon, Member member) {
public static IssuedCoupon create(Coupon coupon, Member member) {
return IssuedCoupon.builder()
.coupon(coupon)
.member(member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
User author = event.getAuthor();
TextChannel channel = event.getChannel().asTextChannel();
Message message = event.getMessage();
String content = message.getContentRaw(); // get only textual content of message
String content = message.getContentRaw();

log.info("Message of {} in {}: {}", author.getName(), channel.getName(), message.getContentDisplay());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void createTestMember(String githubHandle) {
throw new CustomException(INTERNAL_SERVER_ERROR);
}

Member guestMember = Member.createGuestMember(githubOauthId);
Member guestMember = Member.createGuest(githubOauthId);
memberRepository.save(guestMember);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private AssociateRequirement(
this.infoStatus = infoStatus;
}

public static AssociateRequirement createRequirement() {
public static AssociateRequirement unsatisfied() {
return AssociateRequirement.builder()
.univStatus(UNSATISFIED)
.discordStatus(UNSATISFIED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ private Member(
this.associateRequirement = associateRequirement;
}

public static Member createGuestMember(String oauthId) {
AssociateRequirement associateRequirement = AssociateRequirement.createRequirement();
public static Member createGuest(String oauthId) {
AssociateRequirement associateRequirement = AssociateRequirement.unsatisfied();
return Member.builder()
.oauthId(oauthId)
.role(GUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void submitMembership(Long recruitmentRoundId) {

membershipValidator.validateMembershipSubmit(currentMember, recruitmentRound, isMembershipDuplicate);

Membership membership = Membership.createMembership(currentMember, recruitmentRound);
Membership membership = Membership.create(currentMember, recruitmentRound);
membershipRepository.save(membership);

log.info("[MembershipService] 멤버십 가입 신청 접수: membershipId = {}", membership.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ private Membership(Member member, RecruitmentRound recruitmentRound, RegularRequ
this.regularRequirement = regularRequirement;
}

public static Membership createMembership(Member member, RecruitmentRound recruitmentRound) {
public static Membership create(Member member, RecruitmentRound recruitmentRound) {
return Membership.builder()
.member(member)
.recruitmentRound(recruitmentRound)
.regularRequirement(RegularRequirement.createUnsatisfiedRequirement())
.regularRequirement(RegularRequirement.unsatisfied())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private RegularRequirement(RequirementStatus paymentStatus) {
this.paymentStatus = paymentStatus;
}

public static RegularRequirement createUnsatisfiedRequirement() {
public static RegularRequirement unsatisfied() {
return RegularRequirement.builder()
.paymentStatus(RequirementStatus.UNSATISFIED)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import static com.gdschongik.gdsc.global.exception.ErrorCode.*;

import com.gdschongik.gdsc.domain.common.vo.Money;
import com.gdschongik.gdsc.domain.common.vo.Period;
import com.gdschongik.gdsc.domain.recruitment.dao.RecruitmentRepository;
import com.gdschongik.gdsc.domain.recruitment.dao.RecruitmentRoundRepository;
import com.gdschongik.gdsc.domain.recruitment.domain.Recruitment;
import com.gdschongik.gdsc.domain.recruitment.domain.RecruitmentRound;
import com.gdschongik.gdsc.domain.recruitment.domain.RecruitmentRoundValidator;
import com.gdschongik.gdsc.domain.recruitment.domain.RecruitmentValidator;
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period;
import com.gdschongik.gdsc.domain.recruitment.dto.request.RecruitmentCreateRequest;
import com.gdschongik.gdsc.domain.recruitment.dto.request.RecruitmentRoundCreateRequest;
import com.gdschongik.gdsc.domain.recruitment.dto.request.RecruitmentRoundUpdateRequest;
Expand Down Expand Up @@ -40,12 +40,12 @@ public void createRecruitment(RecruitmentCreateRequest request) {

recruitmentValidator.validateRecruitmentCreate(isRecruitmentOverlap);

Recruitment recruitment = Recruitment.createRecruitment(
Recruitment recruitment = Recruitment.create(
request.academicYear(),
request.semesterType(),
Money.from(request.fee()),
request.feeName(),
Period.createPeriod(request.semesterStartDate(), request.semesterEndDate()));
Period.of(request.semesterStartDate(), request.semesterEndDate()));
recruitmentRepository.save(recruitment);

log.info("[AdminRecruitmentService] 리쿠르팅 생성: recruitmentId={}", recruitment.getId());
Expand Down Expand Up @@ -81,10 +81,7 @@ public void createRecruitmentRound(RecruitmentRoundCreateRequest request) {
recruitmentRoundsInThisSemester);

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

log.info("[AdminRecruitmentService] 모집회차 생성: recruitmentRoundId={}", recruitmentRound.getId());
Expand All @@ -106,7 +103,7 @@ public void updateRecruitmentRound(Long recruitmentRoundId, RecruitmentRoundUpda
request.startDate(), request.endDate(), request.roundType(), recruitmentRound, recruitmentRounds);

recruitmentRound.updateRecruitmentRound(
request.name(), Period.createPeriod(request.startDate(), request.endDate()), request.roundType());
request.name(), Period.of(request.startDate(), request.endDate()), request.roundType());

log.info("[AdminRecruitmentService] 모집회차 수정: recruitmentRoundId={}", recruitmentRoundId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.gdschongik.gdsc.domain.common.model.BaseSemesterEntity;
import com.gdschongik.gdsc.domain.common.model.SemesterType;
import com.gdschongik.gdsc.domain.common.vo.Money;
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period;
import com.gdschongik.gdsc.domain.common.vo.Period;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
Expand Down Expand Up @@ -37,7 +37,7 @@ private Recruitment(
this.semesterPeriod = semesterPeriod;
}

public static Recruitment createRecruitment(
public static Recruitment create(
Integer academicYear, SemesterType semesterType, Money fee, String feeName, Period semesterPeriod) {
return Recruitment.builder()
.academicYear(academicYear)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import com.gdschongik.gdsc.domain.common.model.BaseSemesterEntity;
import com.gdschongik.gdsc.domain.common.model.SemesterType;
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period;
import com.gdschongik.gdsc.domain.common.vo.Period;
import com.gdschongik.gdsc.global.exception.CustomException;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.gdschongik.gdsc.domain.recruitment.dto;

import com.gdschongik.gdsc.domain.common.vo.Period;
import com.gdschongik.gdsc.domain.recruitment.domain.RecruitmentRound;
import com.gdschongik.gdsc.domain.recruitment.domain.RoundType;
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period;
import java.math.BigDecimal;

public record RecruitmentRoundFullDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ public void createStudyAnnouncement(Long studyId, StudyAnnouncementCreateUpdateR

studyValidator.validateStudyMentor(currentMember, study);

StudyAnnouncement studyAnnouncement =
StudyAnnouncement.createStudyAnnouncement(study, request.title(), request.link());
StudyAnnouncement studyAnnouncement = StudyAnnouncement.create(study, request.title(), request.link());
studyAnnouncementRepository.save(studyAnnouncement);

log.info("[MentorStudyService] 스터디 공지 생성: studyAnnouncementId={}", studyAnnouncement.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void attend(Long studyDetailId, StudyAttendCreateRequest request) {
attendanceValidator.validateAttendance(
studyDetail, request.attendanceNumber(), LocalDate.now(), isAlreadyAttended, isAppliedToStudy);

Attendance attendance = Attendance.create(currentMember, studyDetail);
Attendance attendance = Attendance.of(currentMember, studyDetail);
attendanceRepository.save(attendance);

log.info("[StudyService] 스터디 출석: attendanceId={}, memberId={}", attendance.getId(), currentMember.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private Attendance(Member student, StudyDetail studyDetail) {
this.studyDetail = studyDetail;
}

public static Attendance create(Member student, StudyDetail studyDetail) {
public static Attendance of(Member student, StudyDetail studyDetail) {
return Attendance.builder().student(student).studyDetail(studyDetail).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import com.gdschongik.gdsc.domain.common.model.BaseSemesterEntity;
import com.gdschongik.gdsc.domain.common.model.SemesterType;
import com.gdschongik.gdsc.domain.common.vo.Period;
import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period;
import com.gdschongik.gdsc.global.exception.CustomException;
import jakarta.persistence.AttributeOverride;
import jakarta.persistence.Column;
Expand Down Expand Up @@ -102,7 +102,7 @@ private Study(
this.endTime = endTime;
}

public static Study createStudy(
public static Study create(
Integer academicYear,
SemesterType semesterType,
String title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public StudyAnnouncement(Study study, String title, String link) {
this.link = link;
}

public static StudyAnnouncement createStudyAnnouncement(Study study, String title, String link) {
public static StudyAnnouncement create(Study study, String title, String link) {
return StudyAnnouncement.builder().study(study).title(title).link(link).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static com.gdschongik.gdsc.global.exception.ErrorCode.*;

import com.gdschongik.gdsc.domain.common.model.BaseEntity;
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period;
import com.gdschongik.gdsc.domain.common.vo.Period;
import com.gdschongik.gdsc.domain.study.domain.vo.Assignment;
import com.gdschongik.gdsc.domain.study.domain.vo.Curriculum;
import com.gdschongik.gdsc.global.exception.CustomException;
Expand Down Expand Up @@ -71,28 +71,28 @@ private StudyDetail(
this.assignment = assignment;
}

public static StudyDetail createStudyDetail(Study study, Long week, String attendanceNumber, Period period) {
public static StudyDetail create(Study study, Long week, String attendanceNumber, Period period) {
return StudyDetail.builder()
.study(study)
.week(week)
.period(period)
.attendanceNumber(attendanceNumber)
.period(period)
.curriculum(Curriculum.createEmptyCurriculum())
.assignment(Assignment.createEmptyAssignment())
.curriculum(Curriculum.empty())
.assignment(Assignment.empty())
.build();
}

public void cancelAssignment() {
assignment = Assignment.cancelAssignment();
assignment = Assignment.canceled();
}

public void publishAssignment(String title, LocalDateTime deadLine, String descriptionNotionLink) {
assignment = Assignment.generateAssignment(title, deadLine, descriptionNotionLink);
assignment = Assignment.of(title, deadLine, descriptionNotionLink);
}

public void updateAssignment(String title, LocalDateTime deadLine, String descriptionNotionLink) {
assignment = Assignment.generateAssignment(title, deadLine, descriptionNotionLink);
assignment = Assignment.of(title, deadLine, descriptionNotionLink);
}

// 데이터 전달 로직
Expand Down Expand Up @@ -135,7 +135,7 @@ public boolean isAttendanceDayNotPassed(LocalDate now) {

public void updateCurriculum(
LocalTime startAt, String title, String description, Difficulty difficulty, StudyStatus status) {
curriculum = Curriculum.generateCurriculum(startAt, title, description, difficulty, status);
curriculum = Curriculum.of(startAt, title, description, difficulty, status);
}

public void validateAssignmentSubmittable(LocalDateTime now) {
Expand Down
Loading