Skip to content

Commit 183ccb8

Browse files
committed
refact: plan - 사용되지 않는 import 및 매서드 정리
1 parent c6ac1c1 commit 183ccb8

File tree

3 files changed

+14
-50
lines changed

3 files changed

+14
-50
lines changed

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/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
}

src/main/java/com/back/domain/study/plan/service/StudyPlanService.java

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
import java.time.LocalDate;
1818
import java.time.LocalDateTime;
19-
import java.time.LocalTime;
20-
import java.time.format.DateTimeFormatter;
2119
import java.time.temporal.ChronoUnit;
2220
import java.util.ArrayList;
2321
import 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

Comments
 (0)