Skip to content

Commit c6ac1c1

Browse files
committed
refact: dto의 untilDate 타입 미변경 수정 + 조회,수정,삭제에도 정적 팩토리 기법 적용
1 parent bbee5a0 commit c6ac1c1

File tree

4 files changed

+148
-129
lines changed

4 files changed

+148
-129
lines changed

src/main/java/com/back/domain/study/plan/dto/StudyPlanRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import lombok.NoArgsConstructor;
1010
import lombok.Setter;
1111

12+
import java.time.LocalDate;
1213
import java.time.LocalDateTime;
1314
import java.time.temporal.ChronoUnit;
1415
import java.util.ArrayList;
@@ -56,6 +57,6 @@ public static class RepeatRuleRequest {
5657
private List<DayOfWeek> byDay = new ArrayList<>();
5758

5859
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
59-
private String untilDate; // "2025-12-31" 형태
60+
private LocalDate untilDate; // "2025-12-31" 형태
6061
}
6162
}

src/main/java/com/back/domain/study/plan/entity/RepeatRuleEmbeddable.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,15 @@ public class RepeatRuleEmbeddable {
2424
private Integer repeatInterval;
2525
private List<DayOfWeek> byDay = new ArrayList<>();
2626
private LocalDate untilDate; // LocalDateTime → LocalDate 변경
27+
28+
// 정적 팩토리 메서드
29+
public static RepeatRuleEmbeddable create(Frequency frequency, Integer repeatInterval,
30+
List<DayOfWeek> byDay, LocalDate untilDate) {
31+
RepeatRuleEmbeddable embeddable = new RepeatRuleEmbeddable();
32+
embeddable.frequency = frequency;
33+
embeddable.repeatInterval = repeatInterval;
34+
embeddable.byDay = byDay != null ? byDay : new ArrayList<>();
35+
embeddable.untilDate = untilDate;
36+
return embeddable;
37+
}
2738
}

src/main/java/com/back/domain/study/plan/entity/StudyPlanException.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,56 @@ public enum ExceptionType {
6666
@AttributeOverride(name = "untilDate", column = @Column(name = "modified_until_date"))
6767
})
6868
private RepeatRuleEmbeddable modifiedRepeatRule;
69+
70+
// 정적 팩토리 메서드 - 수정 예외
71+
public static StudyPlanException createModified(StudyPlan studyPlan, LocalDate exceptionDate,
72+
ApplyScope applyScope, String modifiedSubject,
73+
LocalDateTime modifiedStartDate, LocalDateTime modifiedEndDate,
74+
Color modifiedColor, RepeatRuleEmbeddable modifiedRepeatRule) {
75+
StudyPlanException exception = new StudyPlanException();
76+
exception.studyPlan = studyPlan;
77+
exception.exceptionDate = exceptionDate;
78+
exception.exceptionType = ExceptionType.MODIFIED;
79+
exception.applyScope = applyScope;
80+
exception.modifiedSubject = modifiedSubject;
81+
exception.modifiedStartDate = modifiedStartDate;
82+
exception.modifiedEndDate = modifiedEndDate;
83+
exception.modifiedColor = modifiedColor;
84+
exception.modifiedRepeatRule = modifiedRepeatRule;
85+
return exception;
86+
}
87+
88+
// 정적 팩토리 메서드 - 삭제 예외
89+
public static StudyPlanException createDeleted(StudyPlan studyPlan, LocalDate exceptionDate,
90+
ApplyScope applyScope) {
91+
StudyPlanException exception = new StudyPlanException();
92+
exception.studyPlan = studyPlan;
93+
exception.exceptionDate = exceptionDate;
94+
exception.exceptionType = ExceptionType.DELETED;
95+
exception.applyScope = applyScope;
96+
return exception;
97+
}
98+
99+
// 수정 내용 업데이트
100+
public void updateModifiedContent(String subject, LocalDateTime startDate,
101+
LocalDateTime endDate, Color color,
102+
RepeatRuleEmbeddable repeatRule, ApplyScope applyScope) {
103+
if (subject != null) this.modifiedSubject = subject;
104+
if (startDate != null) this.modifiedStartDate = startDate;
105+
if (endDate != null) this.modifiedEndDate = endDate;
106+
if (color != null) this.modifiedColor = color;
107+
if (repeatRule != null) this.modifiedRepeatRule = repeatRule;
108+
if (applyScope != null) this.applyScope = applyScope;
109+
}
110+
111+
// 삭제 타입으로 변경
112+
public void changeToDeleted(ApplyScope applyScope) {
113+
this.exceptionType = ExceptionType.DELETED;
114+
this.applyScope = applyScope;
115+
this.modifiedSubject = null;
116+
this.modifiedStartDate = null;
117+
this.modifiedEndDate = null;
118+
this.modifiedColor = null;
119+
this.modifiedRepeatRule = null;
120+
}
69121
}

0 commit comments

Comments
 (0)