@@ -567,30 +567,39 @@ private void deleteRepeatPlan(StudyPlan studyPlan, LocalDate selectedDate, Apply
567567 if (existingException .isPresent ()) {
568568 StudyPlanException exception = existingException .get ();
569569
570- // FROM_THIS_DATE 범위의 수정을 THIS_ONLY 삭제하는 경우
571- if (exception .getApplyScope () == ApplyScope .FROM_THIS_DATE ) {
572- // 다음 날짜부터 수정 내용을 유지하기 위해 새 예외 생성
570+ // FROM_THIS_DATE 범위의 MODIFIED를 THIS_ONLY 삭제하는 경우
571+ if (exception .getApplyScope () == ApplyScope .FROM_THIS_DATE
572+ && exception .getExceptionType () == StudyPlanException .ExceptionType .MODIFIED ) {
573+
573574 LocalDate nextDate = selectedDate .plusDays (1 );
574- StudyPlanException continuedException = new StudyPlanException ();
575- continuedException .setStudyPlan (studyPlan );
576- continuedException .setExceptionDate (nextDate );
577- continuedException .setExceptionType (StudyPlanException .ExceptionType .MODIFIED );
578- continuedException .setApplyScope (ApplyScope .FROM_THIS_DATE );
579-
580- // 기존 수정 내용 복사
581- continuedException .setModifiedSubject (exception .getModifiedSubject ());
582- if (exception .getModifiedStartDate () != null ) {
583- continuedException .setModifiedStartDate (
584- exception .getModifiedStartDate ().plusDays (1 ));
585- }
586- if (exception .getModifiedEndDate () != null ) {
587- continuedException .setModifiedEndDate (
588- exception .getModifiedEndDate ().plusDays (1 ));
589- }
590- continuedException .setModifiedColor (exception .getModifiedColor ());
591- continuedException .setModifiedRepeatRule (exception .getModifiedRepeatRule ());
592575
593- studyPlanExceptionRepository .save (continuedException );
576+ // 다음 날에 이미 예외가 있는지 확인
577+ Optional <StudyPlanException > nextDayException = studyPlanExceptionRepository
578+ .findByPlanIdAndDate (studyPlan .getId (), nextDate );
579+
580+ // 예외가 없을 때만 새로 생성
581+ if (!nextDayException .isPresent ()) {
582+ StudyPlanException continuedException = new StudyPlanException ();
583+ continuedException .setStudyPlan (studyPlan );
584+ continuedException .setExceptionDate (nextDate );
585+ continuedException .setExceptionType (StudyPlanException .ExceptionType .MODIFIED );
586+ continuedException .setApplyScope (ApplyScope .FROM_THIS_DATE );
587+
588+ // 기존 수정 내용 복사
589+ continuedException .setModifiedSubject (exception .getModifiedSubject ());
590+ if (exception .getModifiedStartDate () != null ) {
591+ continuedException .setModifiedStartDate (
592+ exception .getModifiedStartDate ().plusDays (1 ));
593+ }
594+ if (exception .getModifiedEndDate () != null ) {
595+ continuedException .setModifiedEndDate (
596+ exception .getModifiedEndDate ().plusDays (1 ));
597+ }
598+ continuedException .setModifiedColor (exception .getModifiedColor ());
599+ continuedException .setModifiedRepeatRule (exception .getModifiedRepeatRule ());
600+
601+ studyPlanExceptionRepository .save (continuedException );
602+ }
594603 }
595604
596605 // 현재 날짜는 삭제로 변경
0 commit comments