1616
1717import java .time .LocalDate ;
1818import java .time .LocalDateTime ;
19- import java .time .LocalTime ;
20- import java .time .format .DateTimeFormatter ;
2119import java .time .temporal .ChronoUnit ;
2220import java .util .ArrayList ;
2321import java .util .Comparator ;
@@ -439,15 +437,14 @@ private StudyPlanResponse updateExistingException(StudyPlan originalPlan, StudyP
439437
440438 // 원본의 반복 룰 수정 (엔티티)
441439 private void updateRepeatRule (RepeatRule repeatRule , StudyPlanRequest .RepeatRuleRequest request , StudyPlan studyPlan ) {
442- // byDay, untilDate 처리
440+ // byDay 처리
443441 List <DayOfWeek > byDay = getByDayForWeekly (request , studyPlan .getStartDate ());
444- LocalDate untilDate = request .getUntilDate ();
445442
446443 repeatRule .update (
447444 request .getFrequency (),
448445 request .getIntervalValue (),
449446 byDay ,
450- untilDate
447+ request . getUntilDate ()
451448 );
452449 }
453450
@@ -497,30 +494,20 @@ private void deleteRepeatPlan(StudyPlan studyPlan, LocalDate selectedDate, Apply
497494 if (selectedDate .equals (studyPlan .getStartDate ().toLocalDate ())) {
498495 studyPlanRepository .delete (studyPlan ); // CASCADE로 RepeatRule, Exception 모두 삭제
499496 } else {
500- // 기존 예외 확인
501- Optional <StudyPlanException > existingException = studyPlanExceptionRepository
502- .findByPlanIdAndDate (studyPlan .getId (), selectedDate );
503-
504- if (existingException .isPresent ()) {
505- // 기존 예외가 있다면 삭제 타입으로 변경
506- existingException .get ().changeToDeleted (ApplyScope .FROM_THIS_DATE );
507- studyPlanExceptionRepository .save (existingException .get ());
508- } else {
509- // 예외가 없다면 새로 생성
510- StudyPlanException exception = StudyPlanException .createDeleted (
511- studyPlan , selectedDate , ApplyScope .FROM_THIS_DATE
512- );
513- studyPlanExceptionRepository .save (exception );
514- }
515-
516- // untilDate 수정
497+ /* 선택한 날짜가 원본 날짜 이후인 경우
498+ * untilDate 조정만으로도 조회가 안되게 설정이 가능하기 때문에
499+ * 예외를 안 만들고 untilDate 수정으로 처리
500+ */
517501 RepeatRule repeatRule = studyPlan .getRepeatRule ();
518502 LocalDate newUntilDate = selectedDate .minusDays (1 );
519503 repeatRule .update (null , null , null , newUntilDate );
520504 studyPlanRepository .save (studyPlan );
521505
522- studyPlanExceptionRepository .deleteByStudyPlanIdAndExceptionDateAfter (
523- studyPlan .getId (), selectedDate );
506+ // 선택한 날짜 포함 이후의 예외들은 모두 삭제
507+ studyPlanExceptionRepository .deleteByStudyPlanIdAndExceptionDateGreaterThanEqual (
508+ studyPlan .getId (),
509+ selectedDate
510+ );
524511 }
525512 break ;
526513
@@ -651,7 +638,7 @@ private void validateRepeatRuleDate(StudyPlan studyPlan, LocalDate untilDate) {
651638 throw new CustomException (ErrorCode .REPEAT_INVALID_UNTIL_DATE );
652639 }
653640 }
654- // WEEKLY인 경우 빈 byDay 처리 메서드 (RepeatRule용 )
641+ // WEEKLY인 경우 빈 byDay 처리 메서드 (RepeatRule, RepeatRuleEmbeddable 둘 다 사용 가능 )
655642 private List <DayOfWeek > getByDayForWeekly (StudyPlanRequest .RepeatRuleRequest request , LocalDateTime startDate ) {
656643 if (request .getFrequency () == Frequency .WEEKLY ) {
657644 if (request .getByDay () == null || request .getByDay ().isEmpty ()) {
@@ -662,17 +649,6 @@ private List<DayOfWeek> getByDayForWeekly(StudyPlanRequest.RepeatRuleRequest req
662649 }
663650 return new ArrayList <>();
664651 }
665- // WEEKLY인 경우 빈 byDay 처리 메서드 (RepeatRuleEmbeddable용 - 오버로딩)
666- private void getByDayInWeekly (StudyPlanRequest .RepeatRuleRequest request , LocalDateTime startDate , RepeatRuleEmbeddable embeddable ) {
667- if (request .getFrequency () == Frequency .WEEKLY ) {
668- if (request .getByDay () == null || request .getByDay ().isEmpty ()) {
669- DayOfWeek startDay = DayOfWeek .valueOf (startDate .getDayOfWeek ().name ().substring (0 , 3 ));
670- embeddable .setByDay (List .of (startDay ));
671- } else {
672- embeddable .setByDay (request .getByDay ());
673- }
674- }
675- }
676652
677653 // THIS_ONLY로 FROM_THIS_DATE 예외를 삭제할 때 다음 빈 날짜 찾기 (재귀탐색)
678654 private LocalDate findNextAvailableDateForException (StudyPlan studyPlan , LocalDate startDate ) {
0 commit comments