Skip to content

Commit

Permalink
Merge pull request #291 from Team-Sopetit/refactor/#290-v1-theme-api
Browse files Browse the repository at this point in the history
[REFACTOR] theme v1 기능 리팩토링
  • Loading branch information
thguss authored Jun 21, 2024
2 parents e74dd2f + 65f4164 commit 40d7c09
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public record DollImageResponse(
) {

public static DollImageResponse of(Doll doll) {
return new DollImageResponse(doll.getImageInfo().getFaceImageUrl());
return new DollImageResponse(doll.getImageLinks().getFaceImageUrl());
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/soptie/server/doll/entity/Doll.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public class Doll {
private DollType dollType;

@Embedded
private DollImage imageInfo;
private DollImageLinks imageLinks;

public Doll(DollType dollType, DollImage imageInfo) {
public Doll(DollType dollType, DollImageLinks imageLinks) {
this.dollType = dollType;
this.imageInfo = imageInfo;
this.imageLinks = imageLinks;
}

public Doll(Long id, DollType dollType, String faceImageUrl) {
this.id = id;
this.dollType = dollType;
this.imageInfo = new DollImage(faceImageUrl, "", "");
this.imageLinks = new DollImageLinks(faceImageUrl, "", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PACKAGE)
@Getter
public class DollImage {
public class DollImageLinks {

private String faceImageUrl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static MemberHomeInfoGetServiceResponse of(Member member, List<String> co
return MemberHomeInfoGetServiceResponse.builder()
.name(member.getMemberDoll().getName())
.dollType(member.getMemberDoll().getDoll().getDollType())
.frameImageUrl(member.getMemberDoll().getDoll().getImageInfo().getFrameImageUrl())
.frameImageUrl(member.getMemberDoll().getDoll().getImageLinks().getFrameImageUrl())
.dailyCottonCount(member.getCottonInfo().getDailyCottonCount())
.happinessCottonCount(member.getCottonInfo().getHappinessCottonCount())
.conversations(conversations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public MemberRoutineResponse(MemberRoutine memberRoutine, Routine routine) {
this(
memberRoutine.getId(),
routine.getContent(),
routine.getTheme().getImageInfo().getIconImageUrl(),
routine.getTheme().getImageInfo().getDailyIconImageUrl(),
routine.getTheme().getImageLinks().getIconImageUrl(),
routine.getTheme().getImageLinks().getDailyIconImageUrl(),
memberRoutine.getAchieveCount(),
memberRoutine.isAchieve()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public record ThemeServiceResponse(

private static ThemeServiceResponse of(Theme theme) {
return ThemeServiceResponse.builder()
.iconImageUrl(theme.getImageInfo().getIconImageUrl())
.cardImageUrl(theme.getImageInfo().getHappinessCardImageUrl())
.iconImageUrl(theme.getImageLinks().getIconImageUrl())
.cardImageUrl(theme.getImageLinks().getHappinessCardImageUrl())
.name(theme.getName())
.color(theme.getColor())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static DailyRoutineListGetServiceResponse of(List<Routine> routines) {
public static DailyRoutineListGetServiceResponse of(List<Routine> routines, Theme theme) {
return DailyRoutineListGetServiceResponse.builder()
.routines(routines.stream().map(DailyRoutineServiceResponse::of).toList())
.backgroundImageUrl(theme.getImageInfo().getDailyCardImageUrl())
.backgroundImageUrl(theme.getImageLinks().getDailyCardImageUrl())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static HappinessRoutineServiceResponse of(Routine routine) {
.themeName(routine.getTheme().getName())
.themeColor(routine.getTheme().getColor())
.content(routine.getContent())
.iconImageUrl(routine.getTheme().getImageInfo().getIconImageUrl())
.iconImageUrl(routine.getTheme().getImageLinks().getIconImageUrl())
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public static HappinessSubRoutineListGetServiceResponse of(Routine routine, List
.routineContent(routine.getContent())
.themeName(routine.getTheme().getName())
.themeColor(routine.getTheme().getColor())
.iconImageUrl(routine.getTheme().getImageInfo().getIconImageUrl())
.backgroundImageUrl(routine.getTheme().getImageInfo().getHappinessCardImageUrl())
.iconImageUrl(routine.getTheme().getImageLinks().getIconImageUrl())
.backgroundImageUrl(routine.getTheme().getImageLinks().getHappinessCardImageUrl())
.challenges(challenges.stream().map(HappinessSubRoutineServiceResponse::of).toList())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class DailyThemeControllerV1 implements DailyThemeApiV1 {
private final ThemeService themeService;

@GetMapping
public ResponseEntity<SuccessResponse<DailyThemeListGetResponse>> getThemes() {
val response = DailyThemeListGetResponse.of(themeService.getThemes());
public ResponseEntity<SuccessResponse<DailyThemeListGetResponse>> acquireAllInBasic() {
val response = DailyThemeListGetResponse.from(themeService.acquireAllInBasic());
return ResponseEntity.ok(success(SUCCESS_GET_THEME.getMessage(), response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class HappinessThemeControllerV1 implements HappinessThemeApiV1 {
private final ThemeService themeService;

@GetMapping
public ResponseEntity<SuccessResponse<HappinessThemeListGetResponse>> getHappinessThemes() {
val response = HappinessThemeListGetResponse.of(themeService.getThemes());
public ResponseEntity<SuccessResponse<HappinessThemeListGetResponse>> acquireAllInBasic() {
val response = HappinessThemeListGetResponse.from(themeService.acquireAllInBasic());
return ResponseEntity.ok(success(SUCCESS_GET_HAPPINESS_THEME.getMessage(), response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ public interface DailyThemeApiV1 {
)
}
)
ResponseEntity<SuccessResponse<DailyThemeListGetResponse>> getThemes();
ResponseEntity<SuccessResponse<DailyThemeListGetResponse>> acquireAllInBasic();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public interface HappinessThemeApiV1 {
)
}
)
ResponseEntity<SuccessResponse<HappinessThemeListGetResponse>> getHappinessThemes();
ResponseEntity<SuccessResponse<HappinessThemeListGetResponse>> acquireAllInBasic();

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import java.util.List;

import com.soptie.server.theme.service.dto.response.ThemeListGetServiceResponse;
import com.soptie.server.theme.service.dto.response.ThemeListGetServiceResponse.ThemeServiceResponse;
import com.soptie.server.theme.service.vo.ThemeVO;

import lombok.Builder;
import lombok.NonNull;
Expand All @@ -15,26 +14,26 @@ public record DailyThemeListGetResponse(
@NonNull List<DailyThemeResponse> themes
) {

public static DailyThemeListGetResponse of(ThemeListGetServiceResponse response) {
public static DailyThemeListGetResponse from(List<ThemeVO> themes) {
return DailyThemeListGetResponse.builder()
.themes(response.themes().stream().map(DailyThemeResponse::of).toList())
.themes(themes.stream().map(DailyThemeResponse::from).toList())
.build();
}

@Builder(access = PRIVATE)
public record DailyThemeResponse(
private record DailyThemeResponse(
long themeId,
@NonNull String name,
@NonNull String iconImageUrl,
@NonNull String backgroundImageUrl
) {

private static DailyThemeResponse of(ThemeServiceResponse response) {
private static DailyThemeResponse from(ThemeVO theme) {
return DailyThemeResponse.builder()
.themeId(response.themeId())
.name(response.name())
.iconImageUrl(response.dailyIconImageUrl())
.backgroundImageUrl(response.dailyBackgroundImageUrl())
.themeId(theme.themeId())
.name(theme.name())
.iconImageUrl(theme.imageLinks().dailyIconImageUrl())
.backgroundImageUrl(theme.imageLinks().dailyCardImageUrl())
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import static lombok.AccessLevel.PRIVATE;

import com.soptie.server.theme.service.dto.response.ThemeListGetServiceResponse;
import com.soptie.server.theme.service.dto.response.ThemeListGetServiceResponse.ThemeServiceResponse;
import com.soptie.server.theme.service.vo.ThemeVO;

import lombok.Builder;
import lombok.NonNull;
Expand All @@ -15,9 +14,9 @@ public record HappinessThemeListGetResponse(
@NonNull List<HappinessThemeResponse> themes
) {

public static HappinessThemeListGetResponse of(ThemeListGetServiceResponse response) {
public static HappinessThemeListGetResponse from(List<ThemeVO> themes) {
return HappinessThemeListGetResponse.builder()
.themes(response.themes().stream().map(HappinessThemeResponse::of).toList())
.themes(themes.stream().map(HappinessThemeResponse::from).toList())
.build();
}

Expand All @@ -27,10 +26,10 @@ public record HappinessThemeResponse(
@NonNull String name
) {

private static HappinessThemeResponse of(ThemeServiceResponse response) {
private static HappinessThemeResponse from(ThemeVO theme) {
return HappinessThemeResponse.builder()
.themeId(response.themeId())
.name(response.name())
.themeId(theme.themeId())
.name(theme.name())
.build();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/soptie/server/theme/entity/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Theme {
private String modifier;

@Embedded
private ThemeImageInfo imageInfo;
private ThemeImageLinks imageLinks;

private String color;

Expand All @@ -47,14 +47,14 @@ public Theme(
String description,
String color,
ThemeType type,
ThemeImageInfo imageInfo
ThemeImageLinks imageLinks
) {
this.id = id;
this.name = name;
this.modifier = modifier;
this.description = description;
this.color = color;
this.type = type;
this.imageInfo = imageInfo;
this.imageLinks = imageLinks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Embeddable
@NoArgsConstructor
@Getter
public class ThemeImageInfo {
public class ThemeImageLinks {

private String iconImageUrl;

Expand All @@ -19,7 +19,7 @@ public class ThemeImageInfo {

private String happinessCardImageUrl;

public ThemeImageInfo(String iconImageUrl, String backgroundImageUrl, String dailyCardImageUrl, String dailyIconImageUrl, String happinessCardImageUrl) {
public ThemeImageLinks(String iconImageUrl, String backgroundImageUrl, String dailyCardImageUrl, String dailyIconImageUrl, String happinessCardImageUrl) {
this.iconImageUrl = iconImageUrl;
this.backgroundImageUrl = backgroundImageUrl;
this.dailyCardImageUrl = dailyCardImageUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.transaction.annotation.Transactional;

import com.soptie.server.theme.adapter.ThemeFinder;
import com.soptie.server.theme.service.dto.response.ThemeListGetServiceResponse;
import com.soptie.server.theme.service.vo.ThemeVO;

import lombok.RequiredArgsConstructor;
Expand All @@ -19,11 +18,6 @@ public class ThemeService {

private final ThemeFinder themeFinder;

public ThemeListGetServiceResponse getThemes() {
val themes = themeFinder.findAllOrderByNameAsc();
return ThemeListGetServiceResponse.of(themes);
}

public List<ThemeVO> acquireAllInBasic() {
val themes = themeFinder.findAllInBasic();
return themes.stream().map(ThemeVO::from).toList();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.soptie.server.theme.service.vo;

import com.soptie.server.theme.entity.ThemeImageLinks;
import lombok.Builder;

import static lombok.AccessLevel.PRIVATE;

@Builder(access = PRIVATE)
public record ThemeImageLinksVO(
String iconImageUrl,
String backgroundImageUrl,
String dailyCardImageUrl,
String dailyIconImageUrl,
String happinessCardImageUrl
) {

public static ThemeImageLinksVO from(ThemeImageLinks imageLinks) {
return ThemeImageLinksVO.builder()
.iconImageUrl(imageLinks.getIconImageUrl())
.backgroundImageUrl(imageLinks.getBackgroundImageUrl())
.dailyCardImageUrl(imageLinks.getDailyCardImageUrl())
.dailyIconImageUrl(imageLinks.getDailyIconImageUrl())
.happinessCardImageUrl(imageLinks.getHappinessCardImageUrl())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public record ThemeVO(
@NonNull String name,
@NonNull String modifier,
@NonNull String description,
@NonNull ThemeType themeType
@NonNull ThemeType themeType,
@NonNull ThemeImageLinksVO imageLinks
) {

public static ThemeVO from(Theme theme) {
Expand All @@ -24,6 +25,7 @@ public static ThemeVO from(Theme theme) {
.modifier(theme.getModifier())
.description(theme.getDescription())
.themeType(theme.getType())
.imageLinks(ThemeImageLinksVO.from(theme.getImageLinks()))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.soptie.server.support.fixture;

import com.soptie.server.theme.entity.ThemeImageInfo;
import com.soptie.server.theme.entity.ThemeImageLinks;
import com.soptie.server.theme.entity.Theme;
import com.soptie.server.theme.entity.ThemeType;

Expand All @@ -12,7 +12,7 @@ public class ThemeFixture {
private String description = "default";
private String color;
private ThemeType type = ThemeType.BASIC;
private final ThemeImageInfo imageInfo = new ThemeImageInfo("https://...", "https://...", "https://...", "https://...", "https://...");
private final ThemeImageLinks imageLinks = new ThemeImageLinks("https://...", "https://...", "https://...", "https://...", "https://...");

private ThemeFixture() {
}
Expand Down Expand Up @@ -52,6 +52,6 @@ public ThemeFixture type(ThemeType type) {
}

public Theme build() {
return new Theme(id, name, modifier, description, color, type, imageInfo);
return new Theme(id, name, modifier, description, color, type, imageLinks);
}
}
Loading

0 comments on commit 40d7c09

Please sign in to comment.