Skip to content

Commit 80f8dcb

Browse files
committed
refect: 수정,삭제 scope 통합
1 parent dafe408 commit 80f8dcb

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

src/main/java/com/back/domain/study/plan/controller/StudyPlanController.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.back.domain.study.plan.dto.StudyPlanRequest;
55
import com.back.domain.study.plan.dto.StudyPlanListResponse;
66
import com.back.domain.study.plan.dto.StudyPlanResponse;
7-
import com.back.domain.study.plan.entity.StudyPlanException;
7+
import com.back.domain.study.plan.entity.ApplyScope;
88
import com.back.domain.study.plan.service.StudyPlanService;
99
import com.back.global.common.dto.RsData;
1010
import com.back.global.security.CustomUserDetails;
@@ -74,7 +74,7 @@ public ResponseEntity<RsData<StudyPlanResponse>> updateStudyPlan(
7474
// @AuthenticationPrincipal CustomUserDetails user,
7575
@PathVariable Long planId,
7676
@RequestBody StudyPlanRequest request,
77-
@RequestParam(required = false, defaultValue = "THIS_ONLY") StudyPlanException.ApplyScope applyScope) {
77+
@RequestParam(required = false, defaultValue = "THIS_ONLY") ApplyScope applyScope) {
7878
// Long userId = user.getId();
7979
Long userId = 1L; // 임시
8080

@@ -85,18 +85,19 @@ public ResponseEntity<RsData<StudyPlanResponse>> updateStudyPlan(
8585

8686

8787
// ==================== 삭제 ===================
88+
// 플랜 아이디는 원본의 아이디를 받음
89+
// 가상인지 원본인지는 서비스에서 원본과 날짜를 대조해 판단
90+
// 삭제 적용 범위를 쿼리 파라미터로 받음 (THIS_ONLY, FROM_THIS_DATE)
8891
@DeleteMapping("/{planId}")
8992
public ResponseEntity<RsData<Void>> deleteStudyPlan(
9093
// @AuthenticationPrincipal CustomUserDetails user,
9194
@PathVariable Long planId,
9295
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate selectedDate,
93-
@RequestBody(required = false) StudyPlanDeleteRequest request) {
96+
@RequestParam(required = false) ApplyScope applyScope) {
9497
Long userId = 1L; // 임시
9598

96-
studyPlanService.deleteStudyPlan(userId, planId, selectedDate, request);
99+
studyPlanService.deleteStudyPlan(userId, planId, selectedDate, applyScope);
97100
return ResponseEntity.ok(RsData.success("학습 계획이 성공적으로 삭제되었습니다."));
98101
}
99102

100-
101-
102103
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.back.domain.study.plan.entity;
2+
3+
public enum ApplyScope {
4+
THIS_ONLY, // 이 날짜만
5+
FROM_THIS_DATE // 이 날짜부터 이후 모든 날짜
6+
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ public enum ExceptionType {
5757
MODIFIED // 해당 날짜 수정
5858
}
5959

60-
public enum ApplyScope {
61-
THIS_ONLY, // 이 날짜만
62-
FROM_THIS_DATE // 이 날짜부터 이후 모든 날짜
63-
}
64-
6560
@Embedded
6661
@AttributeOverrides({
6762
@AttributeOverride(name = "frequency", column = @Column(name = "modified_frequency")),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.back.domain.study.plan.repository;
22

3+
import com.back.domain.study.plan.entity.ApplyScope;
34
import com.back.domain.study.plan.entity.StudyPlanException;
45
import org.springframework.data.jpa.repository.JpaRepository;
56
import org.springframework.data.jpa.repository.Query;
@@ -20,7 +21,7 @@ public interface StudyPlanExceptionRepository extends JpaRepository<StudyPlanExc
2021
"ORDER BY spe.exceptionDate DESC")
2122
List<StudyPlanException> findByStudyPlanIdAndApplyScopeAndExceptionDateBefore(
2223
@Param("planId") Long planId,
23-
@Param("applyScope") StudyPlanException.ApplyScope applyScope,
24+
@Param("applyScope") ApplyScope applyScope,
2425
@Param("targetDate") LocalDateTime targetDate);
2526
// 특정 계획의 특정 기간 동안(start~end)의 예외를 조회
2627
@Query("SELECT spe FROM StudyPlanException spe WHERE spe.studyPlan.id = :planId " +

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import com.back.domain.study.plan.dto.StudyPlanDeleteRequest;
44
import com.back.domain.study.plan.dto.StudyPlanRequest;
55
import com.back.domain.study.plan.dto.StudyPlanResponse;
6-
import com.back.domain.study.plan.entity.RepeatRule;
7-
import com.back.domain.study.plan.entity.RepeatRuleEmbeddable;
8-
import com.back.domain.study.plan.entity.StudyPlan;
9-
import com.back.domain.study.plan.entity.StudyPlanException;
6+
import com.back.domain.study.plan.entity.*;
107
import com.back.domain.study.plan.repository.StudyPlanExceptionRepository;
118
import com.back.domain.study.plan.repository.StudyPlanRepository;
129
import com.back.global.exception.CustomException;
@@ -211,7 +208,7 @@ private StudyPlanException getEffectiveException(Long planId, LocalDate targetDa
211208
List<StudyPlanException> scopeExceptions = studyPlanExceptionRepository
212209
.findByStudyPlanIdAndApplyScopeAndExceptionDateBefore(
213210
planId,
214-
StudyPlanException.ApplyScope.FROM_THIS_DATE,
211+
ApplyScope.FROM_THIS_DATE,
215212
targetDate.atStartOfDay()
216213
);
217214

@@ -280,7 +277,7 @@ private enum UpdateType {
280277
REPEAT_INSTANCE_UPDATE // 기존 예외 수정
281278
}
282279
@Transactional
283-
public StudyPlanResponse updateStudyPlan(Long userId, Long planId, StudyPlanRequest request, StudyPlanException.ApplyScope applyScope) {
280+
public StudyPlanResponse updateStudyPlan(Long userId, Long planId, StudyPlanRequest request, ApplyScope applyScope) {
284281
StudyPlan originalPlan = studyPlanRepository.findById(planId)
285282
.orElseThrow(() -> new CustomException(ErrorCode.PLAN_NOT_FOUND));
286283

@@ -348,7 +345,7 @@ private StudyPlanResponse updateOriginalPlan(StudyPlan originalPlan, StudyPlanRe
348345
}
349346

350347
// 새로운 예외 추가
351-
private StudyPlanResponse createRepeatException(StudyPlan originalPlan, StudyPlanRequest request, StudyPlanException.ApplyScope applyScope) {
348+
private StudyPlanResponse createRepeatException(StudyPlan originalPlan, StudyPlanRequest request, ApplyScope applyScope) {
352349
LocalDate exceptionDate = request.getStartDate().toLocalDate();
353350

354351
// 해당 날짜에 실제로 반복 계획이 있는지 확인
@@ -393,7 +390,7 @@ private StudyPlanResponse createRepeatException(StudyPlan originalPlan, StudyPla
393390
}
394391

395392
// 기존 예외 수정
396-
private StudyPlanResponse updateExistingException(StudyPlan originalPlan, StudyPlanRequest request, StudyPlanException.ApplyScope applyScope) {
393+
private StudyPlanResponse updateExistingException(StudyPlan originalPlan, StudyPlanRequest request, ApplyScope applyScope) {
397394
LocalDate exceptionDate = request.getStartDate().toLocalDate();
398395

399396
StudyPlanException existingException = studyPlanExceptionRepository
@@ -451,24 +448,24 @@ private void updateRepeatRule(RepeatRule repeatRule, StudyPlanRequest.RepeatRule
451448

452449
// ==================== 삭제 ===================
453450
@Transactional
454-
public void deleteStudyPlan(Long userId, Long planId, LocalDate selectedDate, StudyPlanDeleteRequest request) {
451+
public void deleteStudyPlan(Long userId, Long planId, LocalDate selectedDate, ApplyScope applyScope) {
455452
StudyPlan studyPlan = studyPlanRepository.findById(planId)
456453
.orElseThrow(() -> new CustomException(ErrorCode.PLAN_NOT_FOUND));
457454

458455
validateUserAccess(studyPlan, userId);
459456

460-
// 단발성 계획 삭제 (request가 null이거나 deleteScope가 없는 경우)
461-
if (studyPlan.getRepeatRule() == null || request == null || request.getDeleteScope() == null) {
457+
// 단발성 계획 삭제 (반복 룰이 null이거나 applyScope가 null인 경우)
458+
if (studyPlan.getRepeatRule() == null || applyScope == null ) {
462459
studyPlanRepository.delete(studyPlan);
463460
return;
464461
}
465462

466-
// 반복성 계획 삭제 - deleteScope에 따른 처리
467-
deleteRepeatPlan(studyPlan, selectedDate, request.getDeleteScope());
463+
// 반복성 계획 삭제 - applyScope에 따른 처리
464+
deleteRepeatPlan(studyPlan, selectedDate, applyScope);
468465
}
469466

470-
private void deleteRepeatPlan(StudyPlan studyPlan, LocalDate selectedDate, StudyPlanDeleteRequest.DeleteScope deleteScope) {
471-
switch (deleteScope) {
467+
private void deleteRepeatPlan(StudyPlan studyPlan, LocalDate selectedDate, ApplyScope applyScope) {
468+
switch (applyScope) {
472469
case FROM_THIS_DATE:
473470
// 원본 날짜부터 삭제하는 경우 = 전체 계획 삭제
474471
if (selectedDate.equals(studyPlan.getStartDate().toLocalDate())) {
@@ -488,7 +485,7 @@ private void deleteRepeatPlan(StudyPlan studyPlan, LocalDate selectedDate, Study
488485
exception.setStudyPlan(studyPlan);
489486
exception.setExceptionDate(selectedDate);
490487
exception.setExceptionType(StudyPlanException.ExceptionType.DELETED);
491-
exception.setApplyScope(StudyPlanException.ApplyScope.THIS_ONLY);
488+
exception.setApplyScope(ApplyScope.THIS_ONLY);
492489
studyPlanExceptionRepository.save(exception);
493490
break;
494491
}

0 commit comments

Comments
 (0)