From 679924df74733658900efaf3d64917b8a3ad021f Mon Sep 17 00:00:00 2001 From: thguss Date: Thu, 27 Jun 2024 17:35:43 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[REFACTOR]=20RoutineControllerV1=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/routine/adapter/RoutineFinder.java | 11 ++- .../controller/v1/DailyRoutineController.java | 29 ++++--- .../v1/docs/DailyRoutineControllerDocs.java | 7 +- .../DailyRoutineListAcquireResponse.java | 44 +++++++++++ .../DailyRoutineListByThemeGetResponse.java | 39 ---------- .../DailyRoutineListByThemesGetResponse.java | 37 --------- .../repository/RoutineCustomRepository.java | 6 +- .../repository/RoutineRepositoryImpl.java | 10 +-- .../routine/service/RoutineService.java | 15 +--- .../server/theme/service/ThemeService.java | 4 + .../RoutineServiceIntegrationTest.java | 78 ++++++------------- 11 files changed, 102 insertions(+), 178 deletions(-) create mode 100644 src/main/java/com/soptie/server/routine/controller/v1/dto/response/DailyRoutineListAcquireResponse.java delete mode 100644 src/main/java/com/soptie/server/routine/controller/v1/dto/response/DailyRoutineListByThemeGetResponse.java delete mode 100644 src/main/java/com/soptie/server/routine/controller/v1/dto/response/DailyRoutineListByThemesGetResponse.java 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..ed280726 100644 --- a/src/main/java/com/soptie/server/routine/adapter/RoutineFinder.java +++ b/src/main/java/com/soptie/server/routine/adapter/RoutineFinder.java @@ -6,13 +6,11 @@ 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 +20,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) { 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..dbf9ecab 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,27 @@ 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)); + return ResponseEntity.ok(SuccessResponse.success( + RoutineSuccessMessage.SUCCESS_GET_ROUTINE.getMessage(), + DailyRoutineListAcquireResponse.from(routineService.acquireAllInDailyByThemeIds(themes)))); } @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)); + return ResponseEntity.ok(SuccessResponse.success( + RoutineSuccessMessage.SUCCESS_GET_ROUTINE.getMessage(), + DailyRoutineListAcquireResponse.from( + themeService.acquireById(themeId), + routineService.acquireAllInDailyNotInMemberByThemeId(memberId, themeId)))); } } 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/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/repository/RoutineCustomRepository.java b/src/main/java/com/soptie/server/routine/repository/RoutineCustomRepository.java index 1467362d..70f73d9d 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); + 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..12cc67cf 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,25 +33,25 @@ 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(); } - public List findByTypeAndThemeId(RoutineType type, Long themeId) { + public List findByTypeAndThemeId(RoutineType type, long themeId) { return queryFactory .selectFrom(routine) .where( 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 7659b323..04beee26 100644 --- a/src/main/java/com/soptie/server/routine/service/RoutineService.java +++ b/src/main/java/com/soptie/server/routine/service/RoutineService.java @@ -12,11 +12,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.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; @@ -35,16 +32,12 @@ public class RoutineService { private final MemberFinder memberFinder; private final ChallengeFinder challengeFinder; - 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( 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/test/java/com/soptie/server/routine/service/integration/RoutineServiceIntegrationTest.java b/src/test/java/com/soptie/server/routine/service/integration/RoutineServiceIntegrationTest.java index 7aa114c5..fee54993 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 @@ -22,12 +22,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.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; @@ -97,15 +93,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()); } @@ -130,58 +124,30 @@ void acquireAllWithThemeIds() { List routineIdsForTheme2 = actual.get(theme2.getId()).stream().map(RoutineVO::routineId).toList(); Assertions.assertThat(routineIdsForTheme2).containsExactlyInAnyOrder(routineOfTheme2.getId()); } - } - } + @Test + @DisplayName("[성공] 회원에게 없으면서, 주어진 테마에 속하는 데일리 루틴 목록을 조회한다.") + void acquireAllNotInMemberByThemeId() { + // given + Member member = memberRepository.save(MemberFixture.member().build()); - @Nested - class AcquireDailyRoutineByThemes { + 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()); - 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()); + memberRoutineRepository.save(MemberRoutineFixture.memberRoutine() + .type(RoutineType.DAILY).routineId(routineOfTheme1.getId()).member(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(RoutineType.CHALLENGE).content("관계 도전").theme(theme).build()); - - memberRoutineRepository.save( - MemberRoutineFixture.memberRoutine() - .type(RoutineType.DAILY) - .routineId(routineMemberHas.getId()) - .member(member) - .build()); - } - - @Test - @DisplayName("[성공] 회원에게 없으면서, 주어진 테마에 속하는 데일리 루틴 목록을 조회한다.") - void getDailyRoutinesByThemeMemberNotHas() { - // given - DailyRoutineListByThemeGetServiceRequest request = DailyRoutineListByThemeGetServiceRequest.of( - member.getId(), theme.getId()); - - // 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()); + } } } From c40c6152c3d75e63834a7602c907322196724e09 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 28 Jun 2024 14:09:24 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[REFACTOR]=20RoutineVO=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/routine/adapter/RoutineFinder.java | 7 +-- .../v1/HappinessRoutineController.java | 31 ++++++------- .../docs/HappinessRoutineControllerDocs.java | 8 ++-- .../HappinessRoutineListAcquireResponse.java | 42 ++++++++++++++++++ .../HappinessRoutineListGetResponse.java | 38 ---------------- ...ppinessSubRoutineListAcquireResponse.java} | 31 +++++++------ .../repository/RoutineCustomRepository.java | 2 +- .../repository/RoutineRepositoryImpl.java | 2 +- .../routine/service/RoutineService.java | 13 +----- ...lyRoutineListByThemeGetServiceRequest.java | 19 -------- ...yRoutineListByThemesGetServiceRequest.java | 19 -------- ...HappinessRoutineListGetServiceRequest.java | 17 ------- .../DailyRoutineListGetServiceResponse.java | 44 ------------------- ...appinessRoutineListGetServiceResponse.java | 37 ---------------- .../server/routine/service/vo/RoutineVO.java | 14 +++++- .../server/theme/service/vo/ThemeVO.java | 28 ++++++------ .../RoutineServiceIntegrationTest.java | 12 ++--- .../server/support/fixture/ThemeFixture.java | 2 +- 18 files changed, 117 insertions(+), 249 deletions(-) create mode 100644 src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessRoutineListAcquireResponse.java delete mode 100644 src/main/java/com/soptie/server/routine/controller/v1/dto/response/HappinessRoutineListGetResponse.java rename src/main/java/com/soptie/server/routine/controller/v1/dto/response/{HappinessSubRoutineListGetResponse.java => HappinessSubRoutineListAcquireResponse.java} (57%) delete mode 100644 src/main/java/com/soptie/server/routine/service/dto/request/DailyRoutineListByThemeGetServiceRequest.java delete mode 100644 src/main/java/com/soptie/server/routine/service/dto/request/DailyRoutineListByThemesGetServiceRequest.java delete mode 100644 src/main/java/com/soptie/server/routine/service/dto/request/HappinessRoutineListGetServiceRequest.java delete mode 100644 src/main/java/com/soptie/server/routine/service/dto/response/DailyRoutineListGetServiceResponse.java delete mode 100644 src/main/java/com/soptie/server/routine/service/dto/response/HappinessRoutineListGetServiceResponse.java 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 ed280726..082a3d0b 100644 --- a/src/main/java/com/soptie/server/routine/adapter/RoutineFinder.java +++ b/src/main/java/com/soptie/server/routine/adapter/RoutineFinder.java @@ -1,6 +1,5 @@ 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; @@ -34,11 +33,7 @@ public Routine findById(long id) { .orElseThrow(() -> new RoutineException(INVALID_ROUTINE)); } - public List findChallengeRoutinesByTheme(Long themeId) { - return routineRepository.findByTypeAndThemeId(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/HappinessRoutineController.java b/src/main/java/com/soptie/server/routine/controller/v1/HappinessRoutineController.java index 10eb3a3e..813bede7 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> getHappinessRoutinesByThemes( + @RequestParam(required = false) Long themeId + ) { + return ResponseEntity.ok(SuccessResponse.success( + RoutineSuccessMessage.SUCCESS_GET_HAPPINESS_ROUTINE.getMessage(), + HappinessRoutineListAcquireResponse.from(routineService.acquireAllInHappinessByThemeId(themeId)))); } @GetMapping("/routine/{routineId}") - public ResponseEntity> getHappinessSubRoutinesByRoutineOfTheme( - @PathVariable long routineId) { - val response = HappinessSubRoutineListGetResponse.of( + public ResponseEntity> getHappinessSubRoutinesByRoutineOfTheme( + @PathVariable long routineId + ) { + val response = HappinessSubRoutineListAcquireResponse.of( routineService.getHappinessSubRoutines(HappinessSubRoutineListGetServiceRequest.of(routineId))); - return ResponseEntity.ok(success(SUCCESS_GET_HAPPINESS_SUB_ROUTINES.getMessage(), response)); + return ResponseEntity.ok(SuccessResponse.success( + RoutineSuccessMessage.SUCCESS_GET_HAPPINESS_SUB_ROUTINES.getMessage(), + response)); } } 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..8363357a 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> getHappinessRoutinesByThemes( @Parameter( name = "themeId", description = "조회할 행복 루틴 테마 id", @@ -57,7 +57,7 @@ ResponseEntity> getHappinessRou description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))} ) - ResponseEntity> getHappinessSubRoutinesByRoutineOfTheme( + ResponseEntity> getHappinessSubRoutinesByRoutineOfTheme( @Parameter( name = "routineId", description = "조회할 서브 행복 루틴 id", 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/repository/RoutineCustomRepository.java b/src/main/java/com/soptie/server/routine/repository/RoutineCustomRepository.java index 70f73d9d..e2ad3010 100644 --- a/src/main/java/com/soptie/server/routine/repository/RoutineCustomRepository.java +++ b/src/main/java/com/soptie/server/routine/repository/RoutineCustomRepository.java @@ -10,5 +10,5 @@ public interface RoutineCustomRepository { List findByTypeAndThemeAndNotMember(long memberId, RoutineType type, long themeId); - List findByTypeAndThemeId(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 12cc67cf..150f0984 100644 --- a/src/main/java/com/soptie/server/routine/repository/RoutineRepositoryImpl.java +++ b/src/main/java/com/soptie/server/routine/repository/RoutineRepositoryImpl.java @@ -51,7 +51,7 @@ public List findByTypeAndThemeAndNotMember(long memberId, RoutineType t .fetch(); } - public List findByTypeAndThemeId(RoutineType type, long themeId) { + public List findByTypeAndThemeId(RoutineType type, Long themeId) { return queryFactory .selectFrom(routine) .where( 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 04beee26..26b3ca9e 100644 --- a/src/main/java/com/soptie/server/routine/service/RoutineService.java +++ b/src/main/java/com/soptie/server/routine/service/RoutineService.java @@ -8,16 +8,12 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.soptie.server.member.adapter.MemberFinder; 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.HappinessRoutineListGetServiceRequest; import com.soptie.server.routine.service.dto.request.HappinessSubRoutineListGetServiceRequest; -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; import lombok.RequiredArgsConstructor; import lombok.val; @@ -28,8 +24,6 @@ public class RoutineService { private final RoutineFinder routineFinder; - private final ThemeFinder themeFinder; - private final MemberFinder memberFinder; private final ChallengeFinder challengeFinder; public List acquireAllInDailyByThemeIds(List themeIds) { @@ -40,11 +34,8 @@ public List acquireAllInDailyNotInMemberByThemeId(long memberId, long 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( 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/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 fee54993..05701304 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 @@ -22,10 +22,7 @@ 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.HappinessRoutineListGetServiceRequest; import com.soptie.server.routine.service.dto.request.HappinessSubRoutineListGetServiceRequest; -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; @@ -176,15 +173,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://..."); From 1de20aeabc5249a4e5aab9f606db58cba4d11062 Mon Sep 17 00:00:00 2001 From: thguss Date: Fri, 28 Jun 2024 14:13:27 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[FIX]=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routine/controller/v1/HappinessRoutineController.java | 4 ++-- .../controller/v1/docs/HappinessRoutineControllerDocs.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 813bede7..573b03cc 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 @@ -26,7 +26,7 @@ public class HappinessRoutineController implements HappinessRoutineControllerDoc private final RoutineService routineService; @GetMapping - public ResponseEntity> getHappinessRoutinesByThemes( + public ResponseEntity> acquireAllByTheme( @RequestParam(required = false) Long themeId ) { return ResponseEntity.ok(SuccessResponse.success( @@ -35,7 +35,7 @@ public ResponseEntity> getH } @GetMapping("/routine/{routineId}") - public ResponseEntity> getHappinessSubRoutinesByRoutineOfTheme( + public ResponseEntity> acquireAllInSubByRoutine( @PathVariable long routineId ) { val response = HappinessSubRoutineListAcquireResponse.of( 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 8363357a..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 @@ -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> getHappines description = "서버 내부 오류", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))} ) - ResponseEntity> getHappinessSubRoutinesByRoutineOfTheme( + ResponseEntity> acquireAllInSubByRoutine( @Parameter( name = "routineId", description = "조회할 서브 행복 루틴 id", From 4fd783ece5e14b5d826056d3c7a3b6c35130ebad Mon Sep 17 00:00:00 2001 From: thguss Date: Sun, 30 Jun 2024 05:45:37 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[FIX]=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EB=82=B4=20response=20=ED=95=9C=20=EC=A4=84=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routine/controller/v1/DailyRoutineController.java | 9 +++++---- .../controller/v1/HappinessRoutineController.java | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) 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 dbf9ecab..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 @@ -32,9 +32,10 @@ public class DailyRoutineController implements DailyRoutineControllerDocs { public ResponseEntity> acquireAllByThemes( @RequestParam List themes ) { + val response = routineService.acquireAllInDailyByThemeIds(themes); return ResponseEntity.ok(SuccessResponse.success( RoutineSuccessMessage.SUCCESS_GET_ROUTINE.getMessage(), - DailyRoutineListAcquireResponse.from(routineService.acquireAllInDailyByThemeIds(themes)))); + DailyRoutineListAcquireResponse.from(response))); } @GetMapping("/theme/{themeId}") @@ -43,10 +44,10 @@ public ResponseEntity> acquireA @PathVariable long themeId ) { val memberId = Long.parseLong(principal.getName()); + val themeResponse = themeService.acquireById(themeId); + val routinesResponse = routineService.acquireAllInDailyNotInMemberByThemeId(memberId, themeId); return ResponseEntity.ok(SuccessResponse.success( RoutineSuccessMessage.SUCCESS_GET_ROUTINE.getMessage(), - DailyRoutineListAcquireResponse.from( - themeService.acquireById(themeId), - routineService.acquireAllInDailyNotInMemberByThemeId(memberId, themeId)))); + 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 573b03cc..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 @@ -29,19 +29,19 @@ public class HappinessRoutineController implements HappinessRoutineControllerDoc 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(routineService.acquireAllInHappinessByThemeId(themeId)))); + HappinessRoutineListAcquireResponse.from(response))); } @GetMapping("/routine/{routineId}") public ResponseEntity> acquireAllInSubByRoutine( @PathVariable long routineId ) { - val response = HappinessSubRoutineListAcquireResponse.of( - routineService.getHappinessSubRoutines(HappinessSubRoutineListGetServiceRequest.of(routineId))); + val response = routineService.getHappinessSubRoutines(HappinessSubRoutineListGetServiceRequest.of(routineId)); return ResponseEntity.ok(SuccessResponse.success( RoutineSuccessMessage.SUCCESS_GET_HAPPINESS_SUB_ROUTINES.getMessage(), - response)); + HappinessSubRoutineListAcquireResponse.of(response))); } } From 798156023451e77865bc74793c838fb1dd540021 Mon Sep 17 00:00:00 2001 From: thguss Date: Sun, 30 Jun 2024 05:47:01 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[FIX]=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EB=82=B4=20response=20=ED=95=9C=20=EC=A4=84=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/routine/controller/v2/DailyRoutineControllerV2.java | 1 + 1 file changed, 1 insertion(+) 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))); } + }