-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from chjcode/feat/user-setting-color
Feat/user setting color
- Loading branch information
Showing
12 changed files
with
230 additions
and
16 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/chzzk/grassdiary/domain/color/controller/ColorCodeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package chzzk.grassdiary.domain.color.controller; | ||
|
||
import chzzk.grassdiary.domain.color.dto.ColorCodeResponseDTO; | ||
import chzzk.grassdiary.domain.color.service.ColorCodeService; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/colors") | ||
@Tag(name = "색상 컨트롤러") | ||
public class ColorCodeController { | ||
|
||
private final ColorCodeService colorCodeService; | ||
|
||
@GetMapping | ||
public List<ColorCodeResponseDTO> getAllColors() { | ||
return colorCodeService.getAllColors(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/chzzk/grassdiary/domain/color/dto/ColorCodeResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package chzzk.grassdiary.domain.color.dto; | ||
|
||
import chzzk.grassdiary.domain.color.entity.ColorCode; | ||
|
||
public record ColorCodeResponseDTO( | ||
Long id, | ||
String colorName, | ||
String rgb, | ||
int price | ||
) { | ||
public static ColorCodeResponseDTO from(ColorCode colorCode) { | ||
return new ColorCodeResponseDTO( | ||
colorCode.getId(), | ||
colorCode.getColorName(), | ||
colorCode.getRgb(), | ||
colorCode.getPrice() | ||
); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...zk/grassdiary/domain/color/ColorCode.java → ...sdiary/domain/color/entity/ColorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...grassdiary/domain/color/ColorCodeDAO.java → ...ary/domain/color/entity/ColorCodeDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/chzzk/grassdiary/domain/color/service/ColorCodeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package chzzk.grassdiary.domain.color.service; | ||
|
||
import chzzk.grassdiary.domain.color.dto.ColorCodeResponseDTO; | ||
import chzzk.grassdiary.domain.color.entity.ColorCode; | ||
import chzzk.grassdiary.domain.color.entity.ColorCodeDAO; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ColorCodeService { | ||
|
||
private final ColorCodeDAO colorCodeDAO; | ||
|
||
@Transactional(readOnly = true) | ||
public List<ColorCodeResponseDTO> getAllColors() { | ||
List<ColorCode> colorCodes = colorCodeDAO.findAll(); | ||
return colorCodes.stream() | ||
.map(ColorCodeResponseDTO::from) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/chzzk/grassdiary/domain/member/dto/EquipColorResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package chzzk.grassdiary.domain.member.dto; | ||
|
||
import chzzk.grassdiary.domain.member.entity.Member; | ||
import chzzk.grassdiary.domain.color.entity.ColorCode; | ||
|
||
public record EquipColorResponseDTO( | ||
Long memberId, | ||
Long colorCodeId, | ||
String colorName, | ||
String rgb | ||
) { | ||
public static EquipColorResponseDTO from(Member member) { | ||
ColorCode currentColorCode = member.getCurrentColorCode(); | ||
return new EquipColorResponseDTO( | ||
member.getId(), | ||
currentColorCode.getId(), | ||
currentColorCode.getColorName(), | ||
currentColorCode.getRgb() | ||
); | ||
} | ||
} |
30 changes: 20 additions & 10 deletions
30
src/main/java/chzzk/grassdiary/domain/member/dto/MemberPurchasedColorResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,31 @@ | ||
package chzzk.grassdiary.domain.member.dto; | ||
|
||
|
||
import chzzk.grassdiary.domain.color.entity.ColorCode; | ||
import chzzk.grassdiary.domain.member.entity.MemberPurchasedColor; | ||
|
||
public record MemberPurchasedColorResponseDTO( | ||
Long id, | ||
Long memberId, | ||
Long colorCodeId, | ||
String colorName, | ||
String rgb | ||
String rgb, | ||
int price | ||
) { | ||
public MemberPurchasedColorResponseDTO(MemberPurchasedColor memberPurchasedColor) { | ||
this( | ||
memberPurchasedColor.getId(), | ||
memberPurchasedColor.getMember().getId(), | ||
memberPurchasedColor.getColorCode().getId(), | ||
memberPurchasedColor.getColorCode().getColorName(), | ||
memberPurchasedColor.getColorCode().getRgb() | ||
public static MemberPurchasedColorResponseDTO from(MemberPurchasedColor memberPurchasedColor) { | ||
ColorCode colorCode = memberPurchasedColor.getColorCode(); | ||
return new MemberPurchasedColorResponseDTO( | ||
colorCode.getId(), | ||
colorCode.getColorName(), | ||
colorCode.getRgb(), | ||
colorCode.getPrice() | ||
); | ||
} | ||
|
||
public static MemberPurchasedColorResponseDTO from(ColorCode colorCode) { | ||
return new MemberPurchasedColorResponseDTO( | ||
colorCode.getId(), | ||
colorCode.getColorName(), | ||
colorCode.getRgb(), | ||
colorCode.getPrice() | ||
); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/chzzk/grassdiary/domain/member/dto/MemberPurchasedColorsResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package chzzk.grassdiary.domain.member.dto; | ||
|
||
|
||
import java.util.List; | ||
|
||
public record MemberPurchasedColorsResponseDTO( | ||
List<MemberPurchasedColorResponseDTO> colors | ||
) { | ||
public static MemberPurchasedColorsResponseDTO from(List<MemberPurchasedColorResponseDTO> colors) { | ||
return new MemberPurchasedColorsResponseDTO(colors); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters