Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -9,6 +9,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
Expand Down Expand Up @@ -56,6 +57,6 @@ public static class RepeatRuleRequest {
private List<DayOfWeek> byDay = new ArrayList<>();

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private String untilDate; // "2025-12-31" 형태
private LocalDate untilDate; // "2025-12-31" 형태
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@Setter
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/back/domain/study/plan/entity/RepeatRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,29 @@ public class RepeatRule extends BaseEntity {
private List<DayOfWeek> byDay = new ArrayList<>();

private LocalDate untilDate;

// 정적 팩토리 메서드
public static RepeatRule create(Frequency frequency, int repeatInterval,
List<DayOfWeek> byDay, LocalDate untilDate) {
RepeatRule rule = new RepeatRule();
rule.frequency = frequency;
rule.repeatInterval = repeatInterval;
rule.byDay = byDay != null ? byDay : new ArrayList<>();
rule.untilDate = untilDate;
return rule;
}

// 수정 메서드
public void update(Frequency frequency, Integer repeatInterval,
List<DayOfWeek> byDay, LocalDate untilDate) {
if (frequency != null) this.frequency = frequency;
if (repeatInterval != null) this.repeatInterval = repeatInterval;
if (byDay != null) this.byDay = byDay;
if (untilDate != null) this.untilDate = untilDate;
}

// 계획 연결 메서드
public void setStudyPlan(StudyPlan studyPlan) {
this.studyPlan = studyPlan;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,15 @@ public class RepeatRuleEmbeddable {
private Integer repeatInterval;
private List<DayOfWeek> byDay = new ArrayList<>();
private LocalDate untilDate; // LocalDateTime → LocalDate 변경

// 정적 팩토리 메서드
public static RepeatRuleEmbeddable create(Frequency frequency, Integer repeatInterval,
List<DayOfWeek> byDay, LocalDate untilDate) {
RepeatRuleEmbeddable embeddable = new RepeatRuleEmbeddable();
embeddable.frequency = frequency;
embeddable.repeatInterval = repeatInterval;
embeddable.byDay = byDay != null ? byDay : new ArrayList<>();
embeddable.untilDate = untilDate;
return embeddable;
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/back/domain/study/plan/entity/StudyPlan.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,31 @@ public class StudyPlan extends BaseEntity {
//반복 주기 설정 시 예외 리스트
@OneToMany(mappedBy = "studyPlan", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<StudyPlanException> exceptions = new ArrayList<>();

// 정적 팩토리 메서드
public static StudyPlan create(User user, String subject, LocalDateTime startDate,
LocalDateTime endDate, Color color) {
StudyPlan plan = new StudyPlan();
plan.user = user;
plan.subject = subject;
plan.startDate = startDate;
plan.endDate = endDate;
plan.color = color;
return plan;
}

// 수정 메서드
public void update(String subject, LocalDateTime startDate, LocalDateTime endDate, Color color) {
if (subject != null) this.subject = subject;
if (startDate != null) this.startDate = startDate;
if (endDate != null) this.endDate = endDate;
if (color != null) this.color = color;
}
// 반복 규칙 설정 메서드
public void setRepeatRule(RepeatRule repeatRule) {
this.repeatRule = repeatRule;
if (repeatRule != null) {
repeatRule.setStudyPlan(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,56 @@ public enum ExceptionType {
@AttributeOverride(name = "untilDate", column = @Column(name = "modified_until_date"))
})
private RepeatRuleEmbeddable modifiedRepeatRule;

// 정적 팩토리 메서드 - 수정 예외
public static StudyPlanException createModified(StudyPlan studyPlan, LocalDate exceptionDate,
ApplyScope applyScope, String modifiedSubject,
LocalDateTime modifiedStartDate, LocalDateTime modifiedEndDate,
Color modifiedColor, RepeatRuleEmbeddable modifiedRepeatRule) {
StudyPlanException exception = new StudyPlanException();
exception.studyPlan = studyPlan;
exception.exceptionDate = exceptionDate;
exception.exceptionType = ExceptionType.MODIFIED;
exception.applyScope = applyScope;
exception.modifiedSubject = modifiedSubject;
exception.modifiedStartDate = modifiedStartDate;
exception.modifiedEndDate = modifiedEndDate;
exception.modifiedColor = modifiedColor;
exception.modifiedRepeatRule = modifiedRepeatRule;
return exception;
}

// 정적 팩토리 메서드 - 삭제 예외
public static StudyPlanException createDeleted(StudyPlan studyPlan, LocalDate exceptionDate,
ApplyScope applyScope) {
StudyPlanException exception = new StudyPlanException();
exception.studyPlan = studyPlan;
exception.exceptionDate = exceptionDate;
exception.exceptionType = ExceptionType.DELETED;
exception.applyScope = applyScope;
return exception;
}

// 수정 내용 업데이트
public void updateModifiedContent(String subject, LocalDateTime startDate,
LocalDateTime endDate, Color color,
RepeatRuleEmbeddable repeatRule, ApplyScope applyScope) {
if (subject != null) this.modifiedSubject = subject;
if (startDate != null) this.modifiedStartDate = startDate;
if (endDate != null) this.modifiedEndDate = endDate;
if (color != null) this.modifiedColor = color;
if (repeatRule != null) this.modifiedRepeatRule = repeatRule;
if (applyScope != null) this.applyScope = applyScope;
}

// 삭제 타입으로 변경
public void changeToDeleted(ApplyScope applyScope) {
this.exceptionType = ExceptionType.DELETED;
this.applyScope = applyScope;
this.modifiedSubject = null;
this.modifiedStartDate = null;
this.modifiedEndDate = null;
this.modifiedColor = null;
this.modifiedRepeatRule = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import com.back.domain.study.plan.entity.ApplyScope;
import com.back.domain.study.plan.entity.StudyPlanException;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

Expand All @@ -21,21 +19,13 @@ List<StudyPlanException> findByStudyPlanIdAndApplyScopeAndExceptionDateLessThanE
ApplyScope applyScope,
LocalDate exceptionDate
);
// 특정 계획의 특정 기간 동안(start~end)의 예외를 조회
@Query("SELECT spe FROM StudyPlanException spe WHERE spe.studyPlan.id = :planId " +
"AND spe.exceptionDate BETWEEN :startDate AND :endDate " +
"ORDER BY spe.exceptionDate")
List<StudyPlanException> findByStudyPlanIdAndExceptionDateBetween(@Param("planId") Long planId,
@Param("startDate") LocalDateTime startDate,
@Param("endDate") LocalDateTime endDate);

// 특정 계획의 특정 날짜 예외 조회
@Query("SELECT spe FROM StudyPlanException spe WHERE spe.studyPlan.id = :planId " +
"AND DATE(spe.exceptionDate) = DATE(:targetDate)")
Optional<StudyPlanException> findByPlanIdAndDate(@Param("planId") Long planId,
@Param("targetDate") LocalDate targetDate);

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