diff --git a/src/main/java/com/soptie/server/routine/adapter/RoutineFinder.java b/src/main/java/com/soptie/server/routine/adapter/RoutineFinder.java index 24d7f106..e0beec6c 100644 --- a/src/main/java/com/soptie/server/routine/adapter/RoutineFinder.java +++ b/src/main/java/com/soptie/server/routine/adapter/RoutineFinder.java @@ -1,18 +1,15 @@ package com.soptie.server.routine.adapter; -import static com.soptie.server.routine.entity.RoutineType.*; import static com.soptie.server.routine.message.RoutineErrorCode.*; import java.util.List; import com.soptie.server.common.support.RepositoryAdapter; -import com.soptie.server.member.entity.Member; import com.soptie.server.routine.entity.Routine; import com.soptie.server.routine.entity.RoutineType; import com.soptie.server.routine.exception.RoutineException; import com.soptie.server.routine.repository.RoutineRepository; import com.soptie.server.routine.service.vo.RoutineVO; -import com.soptie.server.theme.entity.Theme; import lombok.RequiredArgsConstructor; @@ -22,12 +19,13 @@ public class RoutineFinder { private final RoutineRepository routineRepository; - public List findDailyRoutinesByThemeIds(List themeIds) { - return routineRepository.findByTypeAndThemeIds(DAILY, themeIds); + public List findAllByTypeAndThemeIds(RoutineType type, List themeIds) { + return routineRepository.findByTypeAndThemeIds(type, themeIds).stream().map(RoutineVO::from).toList(); } - public List findDailyRoutinesByThemeAndNotMember(Theme theme, Member member) { - return routineRepository.findByTypeAndThemeAndNotMember(DAILY, theme, member); + public List findAllNotInMemberByTypeAndThemeId(long memberId, RoutineType type, long themeId) { + return routineRepository.findByTypeAndThemeAndNotMember(memberId, type, themeId) + .stream().map(RoutineVO::from).toList(); } public Routine findById(long id) { @@ -36,10 +34,10 @@ public Routine findById(long id) { } public List findChallengeRoutinesByTheme(Long themeId) { - return routineRepository.findByTypeAndThemeId(CHALLENGE, themeId); + return routineRepository.findByTypeAndThemeId(RoutineType.CHALLENGE, themeId); } - public List findAllByTypeAndThemeId(RoutineType type, long themeId) { + public List findAllByTypeAndThemeId(RoutineType type, Long themeId) { return routineRepository.findByTypeAndThemeId(type, themeId).stream().map(RoutineVO::from).toList(); } } diff --git a/src/main/java/com/soptie/server/routine/controller/v1/DailyRoutineController.java b/src/main/java/com/soptie/server/routine/controller/v1/DailyRoutineController.java index 6352d204..8dc76a64 100644 --- a/src/main/java/com/soptie/server/routine/controller/v1/DailyRoutineController.java +++ b/src/main/java/com/soptie/server/routine/controller/v1/DailyRoutineController.java @@ -1,8 +1,5 @@ package com.soptie.server.routine.controller.v1; -import static com.soptie.server.common.dto.SuccessResponse.*; -import static com.soptie.server.routine.message.RoutineSuccessMessage.*; - import java.security.Principal; import java.util.List; @@ -15,11 +12,10 @@ import com.soptie.server.common.dto.SuccessResponse; import com.soptie.server.routine.controller.v1.docs.DailyRoutineControllerDocs; -import com.soptie.server.routine.controller.v1.dto.response.DailyRoutineListByThemeGetResponse; -import com.soptie.server.routine.controller.v1.dto.response.DailyRoutineListByThemesGetResponse; +import com.soptie.server.routine.controller.v1.dto.response.DailyRoutineListAcquireResponse; +import com.soptie.server.routine.message.RoutineSuccessMessage; import com.soptie.server.routine.service.RoutineService; -import com.soptie.server.routine.service.dto.request.DailyRoutineListByThemeGetServiceRequest; -import com.soptie.server.routine.service.dto.request.DailyRoutineListByThemesGetServiceRequest; +import com.soptie.server.theme.service.ThemeService; import lombok.RequiredArgsConstructor; import lombok.val; @@ -30,24 +26,28 @@ public class DailyRoutineController implements DailyRoutineControllerDocs { private final RoutineService routineService; + private final ThemeService themeService; @GetMapping - public ResponseEntity> getRoutinesByThemes( + public ResponseEntity> acquireAllByThemes( @RequestParam List themes ) { - val response = DailyRoutineListByThemesGetResponse - .of(routineService.getRoutinesByThemes(DailyRoutineListByThemesGetServiceRequest.of(themes))); - return ResponseEntity.ok(success(SUCCESS_GET_ROUTINE.getMessage(), response)); + val response = routineService.acquireAllInDailyByThemeIds(themes); + return ResponseEntity.ok(SuccessResponse.success( + RoutineSuccessMessage.SUCCESS_GET_ROUTINE.getMessage(), + DailyRoutineListAcquireResponse.from(response))); } @GetMapping("/theme/{themeId}") - public ResponseEntity> getRoutinesByTheme( + public ResponseEntity> acquireAllByTheme( Principal principal, @PathVariable long themeId ) { val memberId = Long.parseLong(principal.getName()); - val response = DailyRoutineListByThemeGetResponse - .of(routineService.getRoutinesByTheme(DailyRoutineListByThemeGetServiceRequest.of(memberId, themeId))); - return ResponseEntity.ok(success(SUCCESS_GET_ROUTINE.getMessage(), response)); + val themeResponse = themeService.acquireById(themeId); + val routinesResponse = routineService.acquireAllInDailyNotInMemberByThemeId(memberId, themeId); + return ResponseEntity.ok(SuccessResponse.success( + RoutineSuccessMessage.SUCCESS_GET_ROUTINE.getMessage(), + DailyRoutineListAcquireResponse.from(themeResponse, routinesResponse))); } } diff --git a/src/main/java/com/soptie/server/routine/controller/v1/HappinessRoutineController.java b/src/main/java/com/soptie/server/routine/controller/v1/HappinessRoutineController.java index 10eb3a3e..80795c8d 100644 --- a/src/main/java/com/soptie/server/routine/controller/v1/HappinessRoutineController.java +++ b/src/main/java/com/soptie/server/routine/controller/v1/HappinessRoutineController.java @@ -1,8 +1,5 @@ package com.soptie.server.routine.controller.v1; -import static com.soptie.server.common.dto.SuccessResponse.*; -import static com.soptie.server.routine.message.RoutineSuccessMessage.*; - import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -12,10 +9,10 @@ import com.soptie.server.common.dto.SuccessResponse; import com.soptie.server.routine.controller.v1.docs.HappinessRoutineControllerDocs; -import com.soptie.server.routine.controller.v1.dto.response.HappinessRoutineListGetResponse; -import com.soptie.server.routine.controller.v1.dto.response.HappinessSubRoutineListGetResponse; +import com.soptie.server.routine.controller.v1.dto.response.HappinessRoutineListAcquireResponse; +import com.soptie.server.routine.controller.v1.dto.response.HappinessSubRoutineListAcquireResponse; +import com.soptie.server.routine.message.RoutineSuccessMessage; import com.soptie.server.routine.service.RoutineService; -import com.soptie.server.routine.service.dto.request.HappinessRoutineListGetServiceRequest; import com.soptie.server.routine.service.dto.request.HappinessSubRoutineListGetServiceRequest; import lombok.RequiredArgsConstructor; @@ -29,18 +26,22 @@ public class HappinessRoutineController implements HappinessRoutineControllerDoc private final RoutineService routineService; @GetMapping - public ResponseEntity> getHappinessRoutinesByThemes( - @RequestParam(required = false) Long themeId) { - val response = HappinessRoutineListGetResponse.of( - routineService.getHappinessRoutinesByTheme(HappinessRoutineListGetServiceRequest.of(themeId))); - return ResponseEntity.ok(success(SUCCESS_GET_HAPPINESS_ROUTINE.getMessage(), response)); + public ResponseEntity> acquireAllByTheme( + @RequestParam(required = false) Long themeId + ) { + val response = routineService.acquireAllInHappinessByThemeId(themeId); + return ResponseEntity.ok(SuccessResponse.success( + RoutineSuccessMessage.SUCCESS_GET_HAPPINESS_ROUTINE.getMessage(), + HappinessRoutineListAcquireResponse.from(response))); } @GetMapping("/routine/{routineId}") - public ResponseEntity> getHappinessSubRoutinesByRoutineOfTheme( - @PathVariable long routineId) { - val response = HappinessSubRoutineListGetResponse.of( - routineService.getHappinessSubRoutines(HappinessSubRoutineListGetServiceRequest.of(routineId))); - return ResponseEntity.ok(success(SUCCESS_GET_HAPPINESS_SUB_ROUTINES.getMessage(), response)); + public ResponseEntity> acquireAllInSubByRoutine( + @PathVariable long routineId + ) { + val response = routineService.getHappinessSubRoutines(HappinessSubRoutineListGetServiceRequest.of(routineId)); + return ResponseEntity.ok(SuccessResponse.success( + RoutineSuccessMessage.SUCCESS_GET_HAPPINESS_SUB_ROUTINES.getMessage(), + HappinessSubRoutineListAcquireResponse.of(response))); } } diff --git a/src/main/java/com/soptie/server/routine/controller/v1/docs/DailyRoutineControllerDocs.java b/src/main/java/com/soptie/server/routine/controller/v1/docs/DailyRoutineControllerDocs.java index 6ee05127..7c77a77d 100644 --- a/src/main/java/com/soptie/server/routine/controller/v1/docs/DailyRoutineControllerDocs.java +++ b/src/main/java/com/soptie/server/routine/controller/v1/docs/DailyRoutineControllerDocs.java @@ -9,8 +9,7 @@ import com.soptie.server.common.dto.ErrorResponse; import com.soptie.server.common.dto.SuccessResponse; -import com.soptie.server.routine.controller.v1.dto.response.DailyRoutineListByThemeGetResponse; -import com.soptie.server.routine.controller.v1.dto.response.DailyRoutineListByThemesGetResponse; +import com.soptie.server.routine.controller.v1.dto.response.DailyRoutineListAcquireResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -37,7 +36,7 @@ public interface DailyRoutineControllerDocs { description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))} ) - ResponseEntity> getRoutinesByThemes( + ResponseEntity> acquireAllByThemes( @Parameter( name = "themes", description = "조회할 데일리 루틴 테마 id 목록", @@ -60,7 +59,7 @@ ResponseEntity> getRoutines description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))} ) - ResponseEntity> getRoutinesByTheme( + ResponseEntity> acquireAllByTheme( @Parameter(hidden = true) Principal principal, @Parameter( name = "themeId", diff --git a/src/main/java/com/soptie/server/routine/controller/v1/docs/HappinessRoutineControllerDocs.java b/src/main/java/com/soptie/server/routine/controller/v1/docs/HappinessRoutineControllerDocs.java index 8b97e1a8..43380c8b 100644 --- a/src/main/java/com/soptie/server/routine/controller/v1/docs/HappinessRoutineControllerDocs.java +++ b/src/main/java/com/soptie/server/routine/controller/v1/docs/HappinessRoutineControllerDocs.java @@ -6,8 +6,8 @@ import com.soptie.server.common.dto.ErrorResponse; import com.soptie.server.common.dto.SuccessResponse; -import com.soptie.server.routine.controller.v1.dto.response.HappinessRoutineListGetResponse; -import com.soptie.server.routine.controller.v1.dto.response.HappinessSubRoutineListGetResponse; +import com.soptie.server.routine.controller.v1.dto.response.HappinessRoutineListAcquireResponse; +import com.soptie.server.routine.controller.v1.dto.response.HappinessSubRoutineListAcquireResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -34,7 +34,7 @@ public interface HappinessRoutineControllerDocs { description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))} ) - ResponseEntity> getHappinessRoutinesByThemes( + ResponseEntity> acquireAllByTheme( @Parameter( name = "themeId", description = "조회할 행복 루틴 테마 id", @@ -57,7 +57,7 @@ ResponseEntity> getHappinessRou description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))} ) - ResponseEntity> getHappinessSubRoutinesByRoutineOfTheme( + ResponseEntity> acquireAllInSubByRoutine( @Parameter( name = "routineId", description = "조회할 서브 행복 루틴 id", diff --git a/src/main/java/com/soptie/server/routine/controller/v1/dto/response/DailyRoutineListAcquireResponse.java b/src/main/java/com/soptie/server/routine/controller/v1/dto/response/DailyRoutineListAcquireResponse.java new file mode 100644 index 00000000..fd0a372a --- /dev/null +++ b/src/main/java/com/soptie/server/routine/controller/v1/dto/response/DailyRoutineListAcquireResponse.java @@ -0,0 +1,44 @@ +package com.soptie.server.routine.controller.v1.dto.response; + +import java.util.List; + +import com.soptie.server.routine.service.vo.RoutineVO; +import com.soptie.server.theme.service.vo.ThemeVO; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.NonNull; + +@Builder(access = AccessLevel.PRIVATE) +public record DailyRoutineListAcquireResponse( + String backgroundImageUrl, + @NonNull List routines +) { + + public static DailyRoutineListAcquireResponse from(ThemeVO theme, List routines) { + return DailyRoutineListAcquireResponse.builder() + .backgroundImageUrl(theme.imageLinks().backgroundImageUrl()) + .routines(routines.stream().map(DailyRoutineResponse::from).toList()) + .build(); + } + + public static DailyRoutineListAcquireResponse from(List routines) { + return DailyRoutineListAcquireResponse.builder() + .routines(routines.stream().map(DailyRoutineResponse::from).toList()) + .build(); + } + + @Builder(access = AccessLevel.PRIVATE) + private record DailyRoutineResponse( + long routineId, + @NonNull String content + ) { + + private static DailyRoutineResponse from(RoutineVO routine) { + return DailyRoutineResponse.builder() + .routineId(routine.routineId()) + .content(routine.content()) + .build(); + } + } +} diff --git a/src/main/java/com/soptie/server/routine/controller/v1/dto/response/DailyRoutineListByThemeGetResponse.java b/src/main/java/com/soptie/server/routine/controller/v1/dto/response/DailyRoutineListByThemeGetResponse.java deleted file mode 100644 index 39047786..00000000 --- a/src/main/java/com/soptie/server/routine/controller/v1/dto/response/DailyRoutineListByThemeGetResponse.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.soptie.server.routine.controller.v1.dto.response; - -import static lombok.AccessLevel.*; - -import java.util.List; - -import com.soptie.server.routine.service.dto.response.DailyRoutineListGetServiceResponse; -import com.soptie.server.routine.service.dto.response.DailyRoutineListGetServiceResponse.DailyRoutineServiceResponse; - -import lombok.Builder; -import lombok.NonNull; - -@Builder(access = PRIVATE) -public record DailyRoutineListByThemeGetResponse( - @NonNull String backgroundImageUrl, - @NonNull List routines -) { - - public static DailyRoutineListByThemeGetResponse of(DailyRoutineListGetServiceResponse response) { - return DailyRoutineListByThemeGetResponse.builder() - .backgroundImageUrl(response.backgroundImageUrl()) - .routines(response.routines().stream().map(DailyRoutineResponse::of).toList()) - .build(); - } - - @Builder(access = PRIVATE) - public record DailyRoutineResponse( - long routineId, - @NonNull String content - ) { - - private static DailyRoutineResponse of(DailyRoutineServiceResponse response) { - return DailyRoutineResponse.builder() - .routineId(response.routineId()) - .content(response.content()) - .build(); - } - } -} diff --git a/src/main/java/com/soptie/server/routine/controller/v1/dto/response/DailyRoutineListByThemesGetResponse.java b/src/main/java/com/soptie/server/routine/controller/v1/dto/response/DailyRoutineListByThemesGetResponse.java deleted file mode 100644 index 6560b74a..00000000 --- a/src/main/java/com/soptie/server/routine/controller/v1/dto/response/DailyRoutineListByThemesGetResponse.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.soptie.server.routine.controller.v1.dto.response; - -import static lombok.AccessLevel.*; - -import java.util.List; - -import com.soptie.server.routine.service.dto.response.DailyRoutineListGetServiceResponse; -import com.soptie.server.routine.service.dto.response.DailyRoutineListGetServiceResponse.DailyRoutineServiceResponse; - -import lombok.Builder; -import lombok.NonNull; - -@Builder(access = PRIVATE) -public record DailyRoutineListByThemesGetResponse( - @NonNull List routines -) { - - public static DailyRoutineListByThemesGetResponse of(DailyRoutineListGetServiceResponse response) { - return DailyRoutineListByThemesGetResponse.builder() - .routines(response.routines().stream().map(DailyRoutineResponse::of).toList()) - .build(); - } - - @Builder(access = PRIVATE) - private record DailyRoutineResponse( - long routineId, - @NonNull String content - ) { - - private static DailyRoutineResponse of(DailyRoutineServiceResponse response) { - return DailyRoutineResponse.builder() - .routineId(response.routineId()) - .content(response.content()) - .build(); - } - } -} diff --git a/src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessRoutineListAcquireResponse.java b/src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessRoutineListAcquireResponse.java new file mode 100644 index 00000000..8764dfc3 --- /dev/null +++ b/src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessRoutineListAcquireResponse.java @@ -0,0 +1,42 @@ +package com.soptie.server.routine.controller.v1.dto.response; + +import java.util.List; +import java.util.Objects; + +import com.soptie.server.routine.service.vo.RoutineVO; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.NonNull; + +@Builder(access = AccessLevel.PRIVATE) +public record HappinessRoutineListAcquireResponse( + List routines +) { + + public static HappinessRoutineListAcquireResponse from(List routines) { + return HappinessRoutineListAcquireResponse.builder() + .routines(routines.stream().map(HappinessRoutineResponse::from).toList()) + .build(); + } + + @Builder(access = AccessLevel.PRIVATE) + private record HappinessRoutineResponse( + long routineId, + @NonNull String name, + @NonNull String nameColor, + @NonNull String title, + @NonNull String iconImageUrl + ) { + + private static HappinessRoutineResponse from(RoutineVO routine) { + return HappinessRoutineResponse.builder() + .routineId(routine.routineId()) + .name(Objects.nonNull(routine.theme()) ? routine.theme().name() : "알 수 없는 테마") + .nameColor(Objects.nonNull(routine.theme()) ? routine.theme().color() : "#FFFFFF") + .title(routine.content()) + .iconImageUrl(Objects.nonNull(routine.theme()) ? routine.theme().imageLinks().iconImageUrl() : "") + .build(); + } + } +} diff --git a/src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessRoutineListGetResponse.java b/src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessRoutineListGetResponse.java deleted file mode 100644 index bdb40249..00000000 --- a/src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessRoutineListGetResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.soptie.server.routine.controller.v1.dto.response; - -import static lombok.AccessLevel.*; - -import java.util.List; - -import com.soptie.server.routine.service.dto.response.HappinessRoutineListGetServiceResponse; -import com.soptie.server.routine.service.dto.response.HappinessRoutineListGetServiceResponse.HappinessRoutineServiceResponse; - -import lombok.Builder; -import lombok.NonNull; - -@Builder(access = PRIVATE) -public record HappinessRoutineListGetResponse(List routines) { - - public static HappinessRoutineListGetResponse of(HappinessRoutineListGetServiceResponse response) { - return HappinessRoutineListGetResponse.builder() - .routines(response.routines().stream().map(HappinessRoutineResponse::of).toList()) - .build(); - } - - @Builder(access = PRIVATE) - public record HappinessRoutineResponse( - long routineId, @NonNull String name, @NonNull String nameColor, - @NonNull String title, @NonNull String iconImageUrl - ) { - - public static HappinessRoutineResponse of(HappinessRoutineServiceResponse response) { - return HappinessRoutineResponse.builder() - .routineId(response.routineId()) - .name(response.themeName()) - .nameColor(response.themeColor()) - .title(response.content()) - .iconImageUrl(response.iconImageUrl()) - .build(); - } - } -} diff --git a/src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessSubRoutineListGetResponse.java b/src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessSubRoutineListAcquireResponse.java similarity index 57% rename from src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessSubRoutineListGetResponse.java rename to src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessSubRoutineListAcquireResponse.java index 34c8b1aa..80cffa9c 100644 --- a/src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessSubRoutineListGetResponse.java +++ b/src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessSubRoutineListAcquireResponse.java @@ -1,24 +1,26 @@ package com.soptie.server.routine.controller.v1.dto.response; -import static lombok.AccessLevel.*; - import java.util.List; import com.soptie.server.routine.service.dto.response.HappinessSubRoutineListGetServiceResponse; import com.soptie.server.routine.service.dto.response.HappinessSubRoutineListGetServiceResponse.HappinessSubRoutineServiceResponse; +import lombok.AccessLevel; import lombok.Builder; import lombok.NonNull; -@Builder(access = PRIVATE) -public record HappinessSubRoutineListGetResponse( - @NonNull String title, @NonNull String name, @NonNull String nameColor, - @NonNull String iconImageUrl, @NonNull String contentImageUrl, +@Builder(access = AccessLevel.PRIVATE) +public record HappinessSubRoutineListAcquireResponse( + @NonNull String title, + @NonNull String name, + @NonNull String nameColor, + @NonNull String iconImageUrl, + @NonNull String contentImageUrl, @NonNull List subRoutines ) { - public static HappinessSubRoutineListGetResponse of(HappinessSubRoutineListGetServiceResponse response) { - return HappinessSubRoutineListGetResponse.builder() + public static HappinessSubRoutineListAcquireResponse of(HappinessSubRoutineListGetServiceResponse response) { + return HappinessSubRoutineListAcquireResponse.builder() .title(response.routineContent()) .name(response.themeName()) .nameColor(response.themeColor()) @@ -28,13 +30,16 @@ public static HappinessSubRoutineListGetResponse of(HappinessSubRoutineListGetSe .build(); } - @Builder(access = PRIVATE) - public record HappinessSubRoutineResponse( - long subRoutineId, @NonNull String content, @NonNull String detailContent, - @NonNull String timeTaken, @NonNull String place + @Builder(access = AccessLevel.PRIVATE) + private record HappinessSubRoutineResponse( + long subRoutineId, + @NonNull String content, + @NonNull String detailContent, + @NonNull String timeTaken, + @NonNull String place ) { - public static HappinessSubRoutineResponse of(HappinessSubRoutineServiceResponse response) { + private static HappinessSubRoutineResponse of(HappinessSubRoutineServiceResponse response) { return HappinessSubRoutineResponse.builder() .subRoutineId(response.challengeId()) .content(response.content()) diff --git a/src/main/java/com/soptie/server/routine/controller/v2/DailyRoutineControllerV2.java b/src/main/java/com/soptie/server/routine/controller/v2/DailyRoutineControllerV2.java index b9a6f75b..53a6ab32 100644 --- a/src/main/java/com/soptie/server/routine/controller/v2/DailyRoutineControllerV2.java +++ b/src/main/java/com/soptie/server/routine/controller/v2/DailyRoutineControllerV2.java @@ -33,4 +33,5 @@ public ResponseEntity> acquir RoutineSuccessMessage.SUCCESS_GET_ROUTINE.getMessage(), DailyRoutineListAcquireResponseV2.from(response))); } + } diff --git a/src/main/java/com/soptie/server/routine/repository/RoutineCustomRepository.java b/src/main/java/com/soptie/server/routine/repository/RoutineCustomRepository.java index 1467362d..e2ad3010 100644 --- a/src/main/java/com/soptie/server/routine/repository/RoutineCustomRepository.java +++ b/src/main/java/com/soptie/server/routine/repository/RoutineCustomRepository.java @@ -2,15 +2,13 @@ import java.util.List; -import com.soptie.server.member.entity.Member; import com.soptie.server.routine.entity.Routine; import com.soptie.server.routine.entity.RoutineType; -import com.soptie.server.theme.entity.Theme; public interface RoutineCustomRepository { List findByTypeAndThemeIds(RoutineType type, List themeIds); - List findByTypeAndThemeAndNotMember(RoutineType type, Theme theme, Member member); + List findByTypeAndThemeAndNotMember(long memberId, RoutineType type, long themeId); List findByTypeAndThemeId(RoutineType type, Long themeId); } diff --git a/src/main/java/com/soptie/server/routine/repository/RoutineRepositoryImpl.java b/src/main/java/com/soptie/server/routine/repository/RoutineRepositoryImpl.java index d1503059..150f0984 100644 --- a/src/main/java/com/soptie/server/routine/repository/RoutineRepositoryImpl.java +++ b/src/main/java/com/soptie/server/routine/repository/RoutineRepositoryImpl.java @@ -11,10 +11,8 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; import com.soptie.server.common.support.ExpressionGenerator; -import com.soptie.server.member.entity.Member; import com.soptie.server.routine.entity.Routine; import com.soptie.server.routine.entity.RoutineType; -import com.soptie.server.theme.entity.Theme; import lombok.RequiredArgsConstructor; @@ -35,19 +33,19 @@ public List findByTypeAndThemeIds(RoutineType type, List themeIds .fetch(); } - public List findByTypeAndThemeAndNotMember(RoutineType type, Theme theme, Member member) { + public List findByTypeAndThemeAndNotMember(long memberId, RoutineType type, long themeId) { return queryFactory .selectFrom(routine) .leftJoin(memberRoutine) .on( routine.id.eq(memberRoutine.routineId), memberRoutine.type.eq(type), - memberRoutine.member.eq(member) + memberRoutine.member.id.eq(memberId) ) .where( memberRoutine.isNull(), routine.type.eq(type), - routine.theme.eq(theme) + routine.theme.id.eq(themeId) ) .orderBy(ExpressionGenerator.getFirstLetter(routine.content).asc()) .fetch(); diff --git a/src/main/java/com/soptie/server/routine/service/RoutineService.java b/src/main/java/com/soptie/server/routine/service/RoutineService.java index 6c8d59e7..225015a1 100644 --- a/src/main/java/com/soptie/server/routine/service/RoutineService.java +++ b/src/main/java/com/soptie/server/routine/service/RoutineService.java @@ -1,6 +1,6 @@ package com.soptie.server.routine.service; -import static com.soptie.server.common.config.ValueConfig.MEMBER_HAS_NOT_CHALLENGE; +import static com.soptie.server.common.config.ValueConfig.*; import java.util.LinkedHashMap; import java.util.List; @@ -17,13 +17,8 @@ import com.soptie.server.routine.adapter.ChallengeFinder; import com.soptie.server.routine.adapter.RoutineFinder; import com.soptie.server.routine.entity.RoutineType; -import com.soptie.server.routine.service.dto.request.DailyRoutineListByThemeGetServiceRequest; -import com.soptie.server.routine.service.dto.request.DailyRoutineListByThemesGetServiceRequest; -import com.soptie.server.routine.service.dto.request.HappinessRoutineListGetServiceRequest; import com.soptie.server.routine.service.dto.request.HappinessSubRoutineListGetServiceRequest; import com.soptie.server.routine.service.dto.response.ChallengeRoutineListAcquireServiceResponse; -import com.soptie.server.routine.service.dto.response.DailyRoutineListGetServiceResponse; -import com.soptie.server.routine.service.dto.response.HappinessRoutineListGetServiceResponse; import com.soptie.server.routine.service.dto.response.HappinessSubRoutineListGetServiceResponse; import com.soptie.server.routine.service.vo.RoutineVO; import com.soptie.server.theme.adapter.ThemeFinder; @@ -37,28 +32,21 @@ public class RoutineService { private final RoutineFinder routineFinder; - private final ThemeFinder themeFinder; - private final MemberFinder memberFinder; private final ChallengeFinder challengeFinder; private final MemberRoutineFinder memberRoutineFinder; + private final ThemeFinder themeFinder; + private final MemberFinder memberFinder; - public DailyRoutineListGetServiceResponse getRoutinesByThemes(DailyRoutineListByThemesGetServiceRequest request) { - val routines = routineFinder.findDailyRoutinesByThemeIds(request.themeIds()); - return DailyRoutineListGetServiceResponse.of(routines); + public List acquireAllInDailyByThemeIds(List themeIds) { + return routineFinder.findAllByTypeAndThemeIds(RoutineType.DAILY, themeIds); } - public DailyRoutineListGetServiceResponse getRoutinesByTheme(DailyRoutineListByThemeGetServiceRequest request) { - val theme = themeFinder.findById(request.themeId()); - val member = memberFinder.findById(request.memberId()); - val routines = routineFinder.findDailyRoutinesByThemeAndNotMember(theme, member); - return DailyRoutineListGetServiceResponse.of(routines, theme); + public List acquireAllInDailyNotInMemberByThemeId(long memberId, long themeId) { + return routineFinder.findAllNotInMemberByTypeAndThemeId(memberId, RoutineType.DAILY, themeId); } - public HappinessRoutineListGetServiceResponse getHappinessRoutinesByTheme( - HappinessRoutineListGetServiceRequest request - ) { - val routines = routineFinder.findChallengeRoutinesByTheme(request.themeId()); - return HappinessRoutineListGetServiceResponse.of(routines); + public List acquireAllInHappinessByThemeId(Long themeId) { + return routineFinder.findAllByTypeAndThemeId(RoutineType.CHALLENGE, themeId); } public HappinessSubRoutineListGetServiceResponse getHappinessSubRoutines( @@ -78,8 +66,10 @@ public Map> acquireAllInDailyWithThemeId(Set themeId return themeToRoutine; } - public Map acquireAllInChallengeWithThemeId(long memberId, - long themeId) { + public Map acquireAllInChallengeWithThemeId( + long memberId, + long themeId + ) { themeFinder.isExistById(themeId); val member = memberFinder.findById(memberId); val challengeIdByMember = getChallengeIdByMember(member); diff --git a/src/main/java/com/soptie/server/routine/service/dto/request/DailyRoutineListByThemeGetServiceRequest.java b/src/main/java/com/soptie/server/routine/service/dto/request/DailyRoutineListByThemeGetServiceRequest.java deleted file mode 100644 index 08adaeef..00000000 --- a/src/main/java/com/soptie/server/routine/service/dto/request/DailyRoutineListByThemeGetServiceRequest.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.soptie.server.routine.service.dto.request; - -import static lombok.AccessLevel.PRIVATE; - -import lombok.Builder; - -@Builder(access = PRIVATE) -public record DailyRoutineListByThemeGetServiceRequest( - long memberId, - long themeId -) { - - public static DailyRoutineListByThemeGetServiceRequest of(long memberId, long themeId) { - return DailyRoutineListByThemeGetServiceRequest.builder() - .memberId(memberId) - .themeId(themeId) - .build(); - } -} diff --git a/src/main/java/com/soptie/server/routine/service/dto/request/DailyRoutineListByThemesGetServiceRequest.java b/src/main/java/com/soptie/server/routine/service/dto/request/DailyRoutineListByThemesGetServiceRequest.java deleted file mode 100644 index c001417b..00000000 --- a/src/main/java/com/soptie/server/routine/service/dto/request/DailyRoutineListByThemesGetServiceRequest.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.soptie.server.routine.service.dto.request; - -import static lombok.AccessLevel.PRIVATE; - -import java.util.List; - -import lombok.Builder; - -@Builder(access = PRIVATE) -public record DailyRoutineListByThemesGetServiceRequest( - List themeIds -) { - - public static DailyRoutineListByThemesGetServiceRequest of(List themeIds) { - return DailyRoutineListByThemesGetServiceRequest.builder() - .themeIds(themeIds) - .build(); - } -} diff --git a/src/main/java/com/soptie/server/routine/service/dto/request/HappinessRoutineListGetServiceRequest.java b/src/main/java/com/soptie/server/routine/service/dto/request/HappinessRoutineListGetServiceRequest.java deleted file mode 100644 index 626adcb2..00000000 --- a/src/main/java/com/soptie/server/routine/service/dto/request/HappinessRoutineListGetServiceRequest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.soptie.server.routine.service.dto.request; - -import static lombok.AccessLevel.PRIVATE; - -import lombok.Builder; - -@Builder(access = PRIVATE) -public record HappinessRoutineListGetServiceRequest( - Long themeId -) { - - public static HappinessRoutineListGetServiceRequest of(Long themeId) { - return HappinessRoutineListGetServiceRequest.builder() - .themeId(themeId) - .build(); - } -} diff --git a/src/main/java/com/soptie/server/routine/service/dto/response/DailyRoutineListGetServiceResponse.java b/src/main/java/com/soptie/server/routine/service/dto/response/DailyRoutineListGetServiceResponse.java deleted file mode 100644 index 1fadcbc4..00000000 --- a/src/main/java/com/soptie/server/routine/service/dto/response/DailyRoutineListGetServiceResponse.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.soptie.server.routine.service.dto.response; - -import static lombok.AccessLevel.PRIVATE; - -import java.util.List; - -import com.soptie.server.routine.entity.Routine; -import com.soptie.server.theme.entity.Theme; - -import lombok.Builder; - -@Builder(access = PRIVATE) -public record DailyRoutineListGetServiceResponse( - List routines, - String backgroundImageUrl -) { - - public static DailyRoutineListGetServiceResponse of(List routines) { - return DailyRoutineListGetServiceResponse.builder() - .routines(routines.stream().map(DailyRoutineServiceResponse::of).toList()) - .build(); - } - - public static DailyRoutineListGetServiceResponse of(List routines, Theme theme) { - return DailyRoutineListGetServiceResponse.builder() - .routines(routines.stream().map(DailyRoutineServiceResponse::of).toList()) - .backgroundImageUrl(theme.getImageLinks().getDailyCardImageUrl()) - .build(); - } - - @Builder(access = PRIVATE) - public record DailyRoutineServiceResponse( - long routineId, - String content - ) { - - private static DailyRoutineServiceResponse of(Routine routine) { - return DailyRoutineServiceResponse.builder() - .routineId(routine.getId()) - .content(routine.getContent()) - .build(); - } - } -} diff --git a/src/main/java/com/soptie/server/routine/service/dto/response/HappinessRoutineListGetServiceResponse.java b/src/main/java/com/soptie/server/routine/service/dto/response/HappinessRoutineListGetServiceResponse.java deleted file mode 100644 index 097751fa..00000000 --- a/src/main/java/com/soptie/server/routine/service/dto/response/HappinessRoutineListGetServiceResponse.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.soptie.server.routine.service.dto.response; - -import static lombok.AccessLevel.*; - -import java.util.List; - -import com.soptie.server.routine.entity.Routine; - -import lombok.Builder; -import lombok.NonNull; - -@Builder(access = PRIVATE) -public record HappinessRoutineListGetServiceResponse(List routines) { - - public static HappinessRoutineListGetServiceResponse of(List routines) { - return HappinessRoutineListGetServiceResponse.builder() - .routines(routines.stream().map(HappinessRoutineServiceResponse::of).toList()) - .build(); - } - - @Builder - public record HappinessRoutineServiceResponse( - long routineId, @NonNull String themeName, @NonNull String themeColor, - @NonNull String content, @NonNull String iconImageUrl - ) { - - private static HappinessRoutineServiceResponse of(Routine routine) { - return HappinessRoutineServiceResponse.builder() - .routineId(routine.getId()) - .themeName(routine.getTheme().getName()) - .themeColor(routine.getTheme().getColor()) - .content(routine.getContent()) - .iconImageUrl(routine.getTheme().getImageLinks().getIconImageUrl()) - .build(); - } - } -} diff --git a/src/main/java/com/soptie/server/routine/service/vo/RoutineVO.java b/src/main/java/com/soptie/server/routine/service/vo/RoutineVO.java index 46ed452b..d91ecf84 100644 --- a/src/main/java/com/soptie/server/routine/service/vo/RoutineVO.java +++ b/src/main/java/com/soptie/server/routine/service/vo/RoutineVO.java @@ -2,6 +2,8 @@ import com.soptie.server.routine.entity.Routine; import com.soptie.server.routine.entity.RoutineType; +import com.soptie.server.theme.entity.Theme; +import com.soptie.server.theme.service.vo.ThemeVO; import jakarta.validation.constraints.NotNull; import lombok.AccessLevel; @@ -11,7 +13,8 @@ public record RoutineVO( long routineId, @NotNull String content, - @NotNull RoutineType routineType + @NotNull RoutineType routineType, + ThemeVO theme ) { public static RoutineVO from(Routine routine) { @@ -21,4 +24,13 @@ public static RoutineVO from(Routine routine) { .routineType(routine.getType()) .build(); } + + public static RoutineVO from(Routine routine, Theme theme) { + return RoutineVO.builder() + .routineId(routine.getId()) + .content(routine.getContent()) + .routineType(routine.getType()) + .theme(ThemeVO.from(theme)) + .build(); + } } diff --git a/src/main/java/com/soptie/server/theme/service/ThemeService.java b/src/main/java/com/soptie/server/theme/service/ThemeService.java index c0059f3f..67411865 100644 --- a/src/main/java/com/soptie/server/theme/service/ThemeService.java +++ b/src/main/java/com/soptie/server/theme/service/ThemeService.java @@ -22,4 +22,8 @@ public List acquireAllInBasic() { val themes = themeFinder.findAllInBasic(); return themes.stream().map(ThemeVO::from).toList(); } + + public ThemeVO acquireById(long themeId) { + return ThemeVO.from(themeFinder.findById(themeId)); + } } diff --git a/src/main/java/com/soptie/server/theme/service/vo/ThemeVO.java b/src/main/java/com/soptie/server/theme/service/vo/ThemeVO.java index d337d543..dd76da29 100644 --- a/src/main/java/com/soptie/server/theme/service/vo/ThemeVO.java +++ b/src/main/java/com/soptie/server/theme/service/vo/ThemeVO.java @@ -10,22 +10,24 @@ @Builder(access = PRIVATE) public record ThemeVO( - long themeId, - @NonNull String name, - @NonNull String modifier, - @NonNull String description, - @NonNull ThemeType themeType, - @NonNull ThemeImageLinksVO imageLinks + long themeId, + @NonNull String name, + @NonNull String modifier, + @NonNull String description, + @NonNull ThemeType themeType, + @NonNull ThemeImageLinksVO imageLinks, + @NonNull String color ) { public static ThemeVO from(Theme theme) { return ThemeVO.builder() - .themeId(theme.getId()) - .name(theme.getName()) - .modifier(theme.getModifier()) - .description(theme.getDescription()) - .themeType(theme.getType()) - .imageLinks(ThemeImageLinksVO.from(theme.getImageLinks())) - .build(); + .themeId(theme.getId()) + .name(theme.getName()) + .modifier(theme.getModifier()) + .description(theme.getDescription()) + .themeType(theme.getType()) + .imageLinks(ThemeImageLinksVO.from(theme.getImageLinks())) + .color(theme.getColor()) + .build(); } } diff --git a/src/test/java/com/soptie/server/routine/service/integration/RoutineServiceIntegrationTest.java b/src/test/java/com/soptie/server/routine/service/integration/RoutineServiceIntegrationTest.java index 8f8e42f4..b6ea59d6 100644 --- a/src/test/java/com/soptie/server/routine/service/integration/RoutineServiceIntegrationTest.java +++ b/src/test/java/com/soptie/server/routine/service/integration/RoutineServiceIntegrationTest.java @@ -1,6 +1,6 @@ package com.soptie.server.routine.service.integration; -import static com.soptie.server.routine.entity.RoutineType.CHALLENGE; +import static com.soptie.server.routine.entity.RoutineType.*; import java.util.LinkedHashSet; import java.util.List; @@ -25,15 +25,8 @@ import com.soptie.server.routine.repository.ChallengeRepository; import com.soptie.server.routine.repository.RoutineRepository; import com.soptie.server.routine.service.RoutineService; -import com.soptie.server.routine.service.dto.request.DailyRoutineListByThemeGetServiceRequest; -import com.soptie.server.routine.service.dto.request.DailyRoutineListByThemesGetServiceRequest; -import com.soptie.server.routine.service.dto.request.HappinessRoutineListGetServiceRequest; import com.soptie.server.routine.service.dto.request.HappinessSubRoutineListGetServiceRequest; import com.soptie.server.routine.service.dto.response.ChallengeRoutineListAcquireServiceResponse; -import com.soptie.server.routine.service.dto.response.DailyRoutineListGetServiceResponse; -import com.soptie.server.routine.service.dto.response.DailyRoutineListGetServiceResponse.DailyRoutineServiceResponse; -import com.soptie.server.routine.service.dto.response.HappinessRoutineListGetServiceResponse; -import com.soptie.server.routine.service.dto.response.HappinessRoutineListGetServiceResponse.HappinessRoutineServiceResponse; import com.soptie.server.routine.service.dto.response.HappinessSubRoutineListGetServiceResponse; import com.soptie.server.routine.service.dto.response.HappinessSubRoutineListGetServiceResponse.HappinessSubRoutineServiceResponse; import com.soptie.server.routine.service.vo.RoutineVO; @@ -101,15 +94,13 @@ void setUp() { void acquireAllByThemeIds() { // given List themeIds = List.of(theme1.getId(), theme2.getId()); - DailyRoutineListByThemesGetServiceRequest request = DailyRoutineListByThemesGetServiceRequest.of( - themeIds); // when - final DailyRoutineListGetServiceResponse actual = routineService.getRoutinesByThemes(request); + final List actual = routineService.acquireAllInDailyByThemeIds(themeIds); // then - Assertions.assertThat(actual.routines()).hasSize(2); - List routineIds = actual.routines().stream().map(DailyRoutineServiceResponse::routineId).toList(); + Assertions.assertThat(actual).hasSize(2); + List routineIds = actual.stream().map(RoutineVO::routineId).toList(); Assertions.assertThat(routineIds) .containsExactlyInAnyOrder(routineOfTheme1.getId(), routineOfTheme2.getId()); } @@ -134,58 +125,30 @@ void acquireAllWithThemeIds() { List routineIdsForTheme2 = actual.get(theme2.getId()).stream().map(RoutineVO::routineId).toList(); Assertions.assertThat(routineIdsForTheme2).containsExactlyInAnyOrder(routineOfTheme2.getId()); } - } - - } - - @Nested - class AcquireDailyRoutineByThemes { - Member member; - Theme theme; - Routine routine1; - Routine routine2; - Routine routineNoTheme; - Routine routineMemberHas; - Routine challengeRoutine; - - @BeforeEach - void setUp() { - member = memberRepository.save(MemberFixture.member().build()); - theme = themeRepository.save(ThemeFixture.theme().name("관계 쌓기").build()); + @Test + @DisplayName("[성공] 회원에게 없으면서, 주어진 테마에 속하는 데일리 루틴 목록을 조회한다.") + void acquireAllNotInMemberByThemeId() { + // given + Member member = memberRepository.save(MemberFixture.member().build()); - routine1 = routineRepository.save( - RoutineFixture.routine().type(RoutineType.DAILY).content("관계 쌓자").theme(theme).build()); - routine2 = routineRepository.save( - RoutineFixture.routine().type(RoutineType.DAILY).content("쌓자 관계").theme(theme).build()); - routineNoTheme = routineRepository.save( - RoutineFixture.routine().type(RoutineType.DAILY).content("테마 없음").build()); - routineMemberHas = routineRepository.save( - RoutineFixture.routine().type(RoutineType.DAILY).content("쌓자 관계").theme(theme).build()); - challengeRoutine = routineRepository.save( - RoutineFixture.routine().type(CHALLENGE).content("관계 도전").theme(theme).build()); - - memberRoutineRepository.save( - MemberRoutineFixture.memberRoutine() - .type(RoutineType.DAILY) - .routineId(routineMemberHas.getId()) - .member(member) - .build()); - } + Routine routineNotInMember1 = routineRepository.save(RoutineFixture.routine() + .type(RoutineType.DAILY).content("조회될 루틴1").theme(theme1).build()); + Routine routineNotInMember2 = routineRepository.save(RoutineFixture.routine() + .type(RoutineType.DAILY).content("조회될 루틴2").theme(theme1).build()); - @Test - @DisplayName("[성공] 회원에게 없으면서, 주어진 테마에 속하는 데일리 루틴 목록을 조회한다.") - void getDailyRoutinesByThemeMemberNotHas() { - // given - DailyRoutineListByThemeGetServiceRequest request = DailyRoutineListByThemeGetServiceRequest.of( - member.getId(), theme.getId()); + memberRoutineRepository.save(MemberRoutineFixture.memberRoutine() + .type(RoutineType.DAILY).routineId(routineOfTheme1.getId()).member(member).build()); - // when - final DailyRoutineListGetServiceResponse actual = routineService.getRoutinesByTheme(request); + // when + final List actual = routineService + .acquireAllInDailyNotInMemberByThemeId(member.getId(), theme1.getId()); - // then - List routineIds = actual.routines().stream().map(DailyRoutineServiceResponse::routineId).toList(); - Assertions.assertThat(routineIds).containsExactlyInAnyOrder(routine1.getId(), routine2.getId()); + // then + List routineIds = actual.stream().map(RoutineVO::routineId).toList(); + Assertions.assertThat(routineIds) + .containsExactlyInAnyOrder(routineNotInMember1.getId(), routineNotInMember2.getId()); + } } } @@ -214,15 +177,12 @@ void setUp() { @Test @DisplayName("[성공] 테마에 포함된 행복 루틴 목록을 조회한다.") void getHappinessRoutinesByTheme() { - // given - HappinessRoutineListGetServiceRequest request = HappinessRoutineListGetServiceRequest.of(theme1.getId()); - // when - final HappinessRoutineListGetServiceResponse actual = routineService.getHappinessRoutinesByTheme(request); + final List actual = routineService.acquireAllInHappinessByThemeId(theme1.getId()); // then - Assertions.assertThat(actual.routines()).hasSize(2); - List routineIds = actual.routines().stream().map(HappinessRoutineServiceResponse::routineId).toList(); + Assertions.assertThat(actual).hasSize(2); + List routineIds = actual.stream().map(RoutineVO::routineId).toList(); Assertions.assertThat(routineIds).containsExactlyInAnyOrder(routine1.getId(), routine2.getId()); } } diff --git a/src/test/java/com/soptie/server/support/fixture/ThemeFixture.java b/src/test/java/com/soptie/server/support/fixture/ThemeFixture.java index 473de5b1..b0ef8999 100644 --- a/src/test/java/com/soptie/server/support/fixture/ThemeFixture.java +++ b/src/test/java/com/soptie/server/support/fixture/ThemeFixture.java @@ -10,7 +10,7 @@ public class ThemeFixture { private String name = "default"; private String modifier = "default"; private String description = "default"; - private String color; + private String color = "#FFFFF"; private ThemeType type = ThemeType.BASIC; private final ThemeImageLinks imageLinks = new ThemeImageLinks("https://...", "https://...", "https://...", "https://...", "https://...");