Skip to content

Commit fd7faed

Browse files
authored
Merge branch 'dev' into Refactor/228
2 parents 5d0e3bc + 48a1138 commit fd7faed

File tree

8 files changed

+228
-194
lines changed

8 files changed

+228
-194
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/dto/StudyPlanResponse.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import java.time.LocalDate;
1414
import java.time.LocalDateTime;
1515
import java.util.ArrayList;
16-
import java.util.Arrays;
1716
import java.util.List;
18-
import java.util.stream.Collectors;
1917

2018
@Getter
2119
@Setter

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,29 @@ public class RepeatRule extends BaseEntity {
3232
private List<DayOfWeek> byDay = new ArrayList<>();
3333

3434
private LocalDate untilDate;
35+
36+
// 정적 팩토리 메서드
37+
public static RepeatRule create(Frequency frequency, int repeatInterval,
38+
List<DayOfWeek> byDay, LocalDate untilDate) {
39+
RepeatRule rule = new RepeatRule();
40+
rule.frequency = frequency;
41+
rule.repeatInterval = repeatInterval;
42+
rule.byDay = byDay != null ? byDay : new ArrayList<>();
43+
rule.untilDate = untilDate;
44+
return rule;
45+
}
46+
47+
// 수정 메서드
48+
public void update(Frequency frequency, Integer repeatInterval,
49+
List<DayOfWeek> byDay, LocalDate untilDate) {
50+
if (frequency != null) this.frequency = frequency;
51+
if (repeatInterval != null) this.repeatInterval = repeatInterval;
52+
if (byDay != null) this.byDay = byDay;
53+
if (untilDate != null) this.untilDate = untilDate;
54+
}
55+
56+
// 계획 연결 메서드
57+
public void setStudyPlan(StudyPlan studyPlan) {
58+
this.studyPlan = studyPlan;
59+
}
3560
}

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/StudyPlan.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,31 @@ public class StudyPlan extends BaseEntity {
4444
//반복 주기 설정 시 예외 리스트
4545
@OneToMany(mappedBy = "studyPlan", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
4646
private List<StudyPlanException> exceptions = new ArrayList<>();
47+
48+
// 정적 팩토리 메서드
49+
public static StudyPlan create(User user, String subject, LocalDateTime startDate,
50+
LocalDateTime endDate, Color color) {
51+
StudyPlan plan = new StudyPlan();
52+
plan.user = user;
53+
plan.subject = subject;
54+
plan.startDate = startDate;
55+
plan.endDate = endDate;
56+
plan.color = color;
57+
return plan;
58+
}
59+
60+
// 수정 메서드
61+
public void update(String subject, LocalDateTime startDate, LocalDateTime endDate, Color color) {
62+
if (subject != null) this.subject = subject;
63+
if (startDate != null) this.startDate = startDate;
64+
if (endDate != null) this.endDate = endDate;
65+
if (color != null) this.color = color;
66+
}
67+
// 반복 규칙 설정 메서드
68+
public void setRepeatRule(RepeatRule repeatRule) {
69+
this.repeatRule = repeatRule;
70+
if (repeatRule != null) {
71+
repeatRule.setStudyPlan(this);
72+
}
73+
}
4774
}

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
}

src/main/java/com/back/domain/study/plan/repository/StudyPlanExceptionRepository.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
import com.back.domain.study.plan.entity.ApplyScope;
44
import com.back.domain.study.plan.entity.StudyPlanException;
55
import org.springframework.data.jpa.repository.JpaRepository;
6-
import org.springframework.data.jpa.repository.Modifying;
76
import org.springframework.data.jpa.repository.Query;
87
import org.springframework.data.repository.query.Param;
98
import org.springframework.stereotype.Repository;
109

1110
import java.time.LocalDate;
12-
import java.time.LocalDateTime;
1311
import java.util.List;
1412
import java.util.Optional;
1513

@@ -21,21 +19,13 @@ List<StudyPlanException> findByStudyPlanIdAndApplyScopeAndExceptionDateLessThanE
2119
ApplyScope applyScope,
2220
LocalDate exceptionDate
2321
);
24-
// 특정 계획의 특정 기간 동안(start~end)의 예외를 조회
25-
@Query("SELECT spe FROM StudyPlanException spe WHERE spe.studyPlan.id = :planId " +
26-
"AND spe.exceptionDate BETWEEN :startDate AND :endDate " +
27-
"ORDER BY spe.exceptionDate")
28-
List<StudyPlanException> findByStudyPlanIdAndExceptionDateBetween(@Param("planId") Long planId,
29-
@Param("startDate") LocalDateTime startDate,
30-
@Param("endDate") LocalDateTime endDate);
22+
3123
// 특정 계획의 특정 날짜 예외 조회
3224
@Query("SELECT spe FROM StudyPlanException spe WHERE spe.studyPlan.id = :planId " +
3325
"AND DATE(spe.exceptionDate) = DATE(:targetDate)")
3426
Optional<StudyPlanException> findByPlanIdAndDate(@Param("planId") Long planId,
3527
@Param("targetDate") LocalDate targetDate);
3628

3729
// 특정 계획의 특정 날짜 이후 예외 모두 삭제
38-
@Modifying
39-
@Query("DELETE FROM StudyPlanException spe WHERE spe.studyPlan.id = :planId AND spe.exceptionDate > :date")
40-
void deleteByStudyPlanIdAndExceptionDateAfter(@Param("planId") Long planId, @Param("date") LocalDate date);
30+
void deleteByStudyPlanIdAndExceptionDateGreaterThanEqual(Long studyPlanId, LocalDate date);
4131
}

0 commit comments

Comments
 (0)