1515import bitnagil .bitnagil_backend .global .exception .CustomException ;
1616import bitnagil .bitnagil_backend .routine .domain .Routine ;
1717import bitnagil .bitnagil_backend .routine .domain .SubRoutine ;
18- import bitnagil .bitnagil_backend .routine .domain .enums .RoutineType ;
1918import bitnagil .bitnagil_backend .routine .repository .RoutineRepository ;
2019import bitnagil .bitnagil_backend .routine .repository .SubRoutineRepository ;
20+ import bitnagil .bitnagil_backend .routine .request .DeleteRoutineByDayRequest ;
2121import bitnagil .bitnagil_backend .routine .request .RoutineCompletionInfo ;
2222import bitnagil .bitnagil_backend .user .domain .User ;
2323import lombok .RequiredArgsConstructor ;
@@ -38,16 +38,16 @@ public class RoutineValidator {
3838 public void validateRoutineOwnership (User user , RoutineCompletionInfo info ) {
3939 switch (info .getRoutineType ()) {
4040 case ROUTINE :
41- validateRoutine (user , info );
41+ validateRoutine (user , info . getRoutineId (), info . getHistorySeq () );
4242 break ;
4343 case SUB_ROUTINE :
44- validateSubRoutine (user , info );
44+ validateSubRoutine (user , info . getRoutineId (), info . getHistorySeq () );
4545 break ;
4646 case CHANGED_ROUTINE :
47- validateChangedRoutine (user , info );
47+ validateChangedRoutine (user , info . getRoutineId (), info . getHistorySeq () );
4848 break ;
4949 case CHANGED_SUB_ROUTINE :
50- validateChangedSubRoutine (user , info );
50+ validateChangedSubRoutine (user , info . getRoutineId (), info . getHistorySeq () );
5151 break ;
5252 }
5353 }
@@ -67,19 +67,21 @@ public Routine validateRoutineOwnership(UUID routineId, User user, LocalDateTime
6767 return routine ;
6868 }
6969
70- private void validateRoutine (User user , RoutineCompletionInfo info ) {
70+ public Routine validateRoutine (User user , UUID routineId , Long historySeq ) {
7171 Routine routine = routineRepository
72- .findByRoutinePk (new HistoryPk (info . getRoutineId (), info . getHistorySeq () ))
72+ .findByRoutinePk (new HistoryPk (routineId , historySeq ))
7373 .orElseThrow (() -> new CustomException (ErrorCode .NOT_FOUND_ROUTINE ));
7474
7575 if (!user .getUserPk ().getId ().equals (routine .getUserId ())) {
7676 throw new CustomException (ErrorCode .ROUTINE_USER_NOT_MATCHED );
7777 }
78+
79+ return routine ;
7880 }
7981
80- private void validateSubRoutine (User user , RoutineCompletionInfo info ) {
82+ private void validateSubRoutine (User user , UUID routineId , Long historySeq ) {
8183 SubRoutine subRoutine = subRoutineRepository
82- .findBySubRoutinePk (new HistoryPk (info . getRoutineId (), info . getHistorySeq () ))
84+ .findBySubRoutinePk (new HistoryPk (routineId , historySeq ))
8385 .orElseThrow (() -> new CustomException (ErrorCode .NOT_FOUND_SUB_ROUTINE ));
8486
8587 // 추후 성능 이슈가 발생할 수 있는 부분
@@ -90,19 +92,21 @@ private void validateSubRoutine(User user, RoutineCompletionInfo info) {
9092 }
9193 }
9294
93- private void validateChangedRoutine (User user , RoutineCompletionInfo info ) {
95+ public ChangedRoutine validateChangedRoutine (User user , UUID routineId , Long historySeq ) {
9496 ChangedRoutine changedRoutine = changedRoutineRepository
95- .findByChangedRoutinePk (new HistoryPk (info . getRoutineId (), info . getHistorySeq () ))
97+ .findByChangedRoutinePk (new HistoryPk (routineId , historySeq ))
9698 .orElseThrow (() -> new CustomException (ErrorCode .NOT_FOUND_CHANGED_ROUTINE ));
9799
98100 if (!user .getUserPk ().getId ().equals (changedRoutine .getUserId ())) {
99101 throw new CustomException (ErrorCode .CHANGED_ROUTINE_USER_NOT_MATCHED );
100102 }
103+
104+ return changedRoutine ;
101105 }
102106
103- private void validateChangedSubRoutine (User user , RoutineCompletionInfo info ) {
107+ private void validateChangedSubRoutine (User user , UUID routineId , Long historySeq ) {
104108 ChangedSubRoutine changedSubRoutine = changedSubRoutineRepository
105- .findByChangedSubRoutinePk (new HistoryPk (info . getRoutineId (), info . getHistorySeq () ))
109+ .findByChangedSubRoutinePk (new HistoryPk (routineId , historySeq ))
106110 .orElseThrow (() -> new CustomException (ErrorCode .NOT_FOUND_CHANGED_SUB_ROUTINE ));
107111
108112 List <ChangedRoutine > changedRoutines = changedRoutineRepository .findByChangedRoutinePk_Id (
0 commit comments