@@ -165,11 +165,6 @@ public RoutineResponse.ApplyRoutineInfoDTO getRoutineApplyInfo(Long userId, Long
165165 Routine routine = routineRepository .findById (routineId )
166166 .orElseThrow (() -> new ErrorHandler (ErrorStatus .ROUTINE_NOT_FOUND ));
167167
168- // 본인 루틴은 미리보기 제한 (단, userId=1은 예외 허용)
169- // if (!userId.equals(1L) && routine.getUser().getId().equals(userId)) {
170- // throw new ErrorHandler(ErrorStatus.ROUTINE_PREVIEW_NOT_ALLOWED);
171- // }
172-
173168 // 3. 해당 루틴의 예산 생성 월 기준으로 내 예산 조회
174169 Budget myBudget = budgetRepository .findByUserAndCreatedMonth (user , routine .getBudget ().getCreatedMonth ())
175170 .orElseThrow (() -> new ErrorHandler (ErrorStatus .BUDGET_NOT_FOUND ));
@@ -202,7 +197,7 @@ public RoutineResponse.ApplyRoutineInfoDTO getRoutineApplyInfo(Long userId, Long
202197 })
203198 .collect (Collectors .toList ());
204199
205- // 7. 루틴 기반 ROUTINE_CATEGORY 구성 (CUSTOM과 이름이 겹치는 항목 포함 )
200+ // 7. 루틴 기반 ROUTINE_CATEGORY 구성 (CUSTOM과 이름이 겹치면 무조건 ROUTINE_CATEGORY )
206201 Set <String > routineCategoryNames = new HashSet <>();
207202 List <RoutineResponse .ApplyCategoryBudgetDTO > routineCategoryBudgets = routineAmounts .stream ()
208203 .filter (ra -> !defaultNames .contains (ra .getCategoryName ()))
@@ -219,7 +214,7 @@ public RoutineResponse.ApplyRoutineInfoDTO getRoutineApplyInfo(Long userId, Long
219214 .filter (mc -> {
220215 String name = mc .getConsumptionCategory ().getBudgetCategoryName ();
221216 return mc .getConsumptionCategory ().getBudgetCategoryType () == CategoryType .CUSTOM &&
222- !routineCategoryNames .contains (name );
217+ !routineCategoryNames .contains (name ); // ✅ 겹치면 ROUTINE_CATEGORY 우선
223218 })
224219 .map (mc -> RoutineConverter .toCategoryDTO (
225220 mc .getConsumptionCategory ().getBudgetCategoryName (),
@@ -228,8 +223,19 @@ public RoutineResponse.ApplyRoutineInfoDTO getRoutineApplyInfo(Long userId, Long
228223 )
229224 .collect (Collectors .toList ());
230225
231- // 9. 요청에 없는 기존 카테고리 → 금액 0으로 초기화
232- // (루틴 반영 applyRoutineToBudget 로직과 동일한 컨셉 적용)
226+ // 9. 기존 루틴 카테고리인데 이번 루틴에 빠진 경우 → CUSTOM + 0원으로 변경
227+ myCategories .stream ()
228+ .filter (mc -> mc .getConsumptionCategory ().getBudgetCategoryType () == CategoryType .ROUTINE_CATEGORY )
229+ .filter (mc -> !routineCategoryNames .contains (mc .getConsumptionCategory ().getBudgetCategoryName ()))
230+ .forEach (mc -> customCategoryBudgets .add (
231+ RoutineConverter .toCategoryDTO (
232+ mc .getConsumptionCategory ().getBudgetCategoryName (),
233+ 0 , // 빠졌으므로 0원
234+ CategoryType .CUSTOM // ROUTINE_CATEGORY → CUSTOM 변경
235+ )
236+ ));
237+
238+ // 10. 요청에 없는 기존 카테고리 → 금액 0으로 초기화 (applyRoutineToBudget 로직과 동일)
233239 Set <String > requestCategoryNames = new HashSet <>();
234240 requestCategoryNames .addAll (defaultCategoryBudgets .stream ()
235241 .map (RoutineResponse .ApplyCategoryBudgetDTO ::getCategoryName )
@@ -254,5 +260,4 @@ public RoutineResponse.ApplyRoutineInfoDTO getRoutineApplyInfo(Long userId, Long
254260 routineCategoryBudgets
255261 );
256262 }
257-
258263}
0 commit comments