Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REFACTOR] RoutineVO 적용 #303

Merged
merged 6 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -22,12 +19,13 @@ public class RoutineFinder {

private final RoutineRepository routineRepository;

public List<Routine> findDailyRoutinesByThemeIds(List<Long> themeIds) {
return routineRepository.findByTypeAndThemeIds(DAILY, themeIds);
public List<RoutineVO> findAllByTypeAndThemeIds(RoutineType type, List<Long> themeIds) {
return routineRepository.findByTypeAndThemeIds(type, themeIds).stream().map(RoutineVO::from).toList();
}

public List<Routine> findDailyRoutinesByThemeAndNotMember(Theme theme, Member member) {
return routineRepository.findByTypeAndThemeAndNotMember(DAILY, theme, member);
public List<RoutineVO> findAllNotInMemberByTypeAndThemeId(long memberId, RoutineType type, long themeId) {
return routineRepository.findByTypeAndThemeAndNotMember(memberId, type, themeId)
.stream().map(RoutineVO::from).toList();
}

public Routine findById(long id) {
Chan531 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -36,10 +34,10 @@ public Routine findById(long id) {
}

public List<Routine> findChallengeRoutinesByTheme(Long themeId) {
return routineRepository.findByTypeAndThemeId(CHALLENGE, themeId);
return routineRepository.findByTypeAndThemeId(RoutineType.CHALLENGE, themeId);
}

public List<RoutineVO> findAllByTypeAndThemeId(RoutineType type, long themeId) {
public List<RoutineVO> findAllByTypeAndThemeId(RoutineType type, Long themeId) {
return routineRepository.findByTypeAndThemeId(type, themeId).stream().map(RoutineVO::from).toList();
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand All @@ -30,24 +26,28 @@
public class DailyRoutineController implements DailyRoutineControllerDocs {

private final RoutineService routineService;
private final ThemeService themeService;

@GetMapping
public ResponseEntity<SuccessResponse<DailyRoutineListByThemesGetResponse>> getRoutinesByThemes(
public ResponseEntity<SuccessResponse<DailyRoutineListAcquireResponse>> acquireAllByThemes(
@RequestParam List<Long> 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(
Chan531 marked this conversation as resolved.
Show resolved Hide resolved
RoutineSuccessMessage.SUCCESS_GET_ROUTINE.getMessage(),
DailyRoutineListAcquireResponse.from(response)));
}

@GetMapping("/theme/{themeId}")
public ResponseEntity<SuccessResponse<DailyRoutineListByThemeGetResponse>> getRoutinesByTheme(
public ResponseEntity<SuccessResponse<DailyRoutineListAcquireResponse>> 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)));
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -29,18 +26,22 @@ public class HappinessRoutineController implements HappinessRoutineControllerDoc
private final RoutineService routineService;

@GetMapping
public ResponseEntity<SuccessResponse<HappinessRoutineListGetResponse>> 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<SuccessResponse<HappinessRoutineListAcquireResponse>> 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<SuccessResponse<HappinessSubRoutineListGetResponse>> 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<SuccessResponse<HappinessSubRoutineListAcquireResponse>> 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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +36,7 @@ public interface DailyRoutineControllerDocs {
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<SuccessResponse<DailyRoutineListByThemesGetResponse>> getRoutinesByThemes(
ResponseEntity<SuccessResponse<DailyRoutineListAcquireResponse>> acquireAllByThemes(
@Parameter(
name = "themes",
description = "조회할 데일리 루틴 테마 id 목록",
Expand All @@ -60,7 +59,7 @@ ResponseEntity<SuccessResponse<DailyRoutineListByThemesGetResponse>> getRoutines
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<SuccessResponse<DailyRoutineListByThemeGetResponse>> getRoutinesByTheme(
ResponseEntity<SuccessResponse<DailyRoutineListAcquireResponse>> acquireAllByTheme(
@Parameter(hidden = true) Principal principal,
@Parameter(
name = "themeId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +34,7 @@ public interface HappinessRoutineControllerDocs {
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<SuccessResponse<HappinessRoutineListGetResponse>> getHappinessRoutinesByThemes(
ResponseEntity<SuccessResponse<HappinessRoutineListAcquireResponse>> acquireAllByTheme(
@Parameter(
name = "themeId",
description = "조회할 행복 루틴 테마 id",
Expand All @@ -57,7 +57,7 @@ ResponseEntity<SuccessResponse<HappinessRoutineListGetResponse>> getHappinessRou
description = "서버 내부 오류",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))}
)
ResponseEntity<SuccessResponse<HappinessSubRoutineListGetResponse>> getHappinessSubRoutinesByRoutineOfTheme(
ResponseEntity<SuccessResponse<HappinessSubRoutineListAcquireResponse>> acquireAllInSubByRoutine(
@Parameter(
name = "routineId",
description = "조회할 서브 행복 루틴 id",
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DailyRoutineResponse> routines
) {

public static DailyRoutineListAcquireResponse from(ThemeVO theme, List<RoutineVO> routines) {
return DailyRoutineListAcquireResponse.builder()
.backgroundImageUrl(theme.imageLinks().backgroundImageUrl())
.routines(routines.stream().map(DailyRoutineResponse::from).toList())
.build();
}

public static DailyRoutineListAcquireResponse from(List<RoutineVO> 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();
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<HappinessRoutineResponse> routines
) {

public static HappinessRoutineListAcquireResponse from(List<RoutineVO> 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();
}
}
}
Loading
Loading