22
33import com .closetnangam .be .domain .catalog .enums .ClothesColor ;
44import com .closetnangam .be .domain .clothes .entity .Clothes ;
5+ import com .closetnangam .be .domain .clothes .entity .ClothingColor ;
6+ import com .closetnangam .be .domain .clothes .entity .WardrobeClothes ;
7+ import com .closetnangam .be .domain .clothes .enums .ColorRole ;
58import com .closetnangam .be .domain .clothes .enums .SourceType ;
69
710import java .time .LocalDateTime ;
811import java .util .List ;
912
1013public record ClothesResponse (
1114 Long clothesId ,
15+ Long wardrobeClothesId ,
1216 Long wardrobeId ,
1317 Long userId ,
1418 String name ,
@@ -17,69 +21,115 @@ public record ClothesResponse(
1721 String imageUrl ,
1822 String category ,
1923 String itemType ,
20- String color ,
21- ColorDisplayResponse colorDisplay ,
24+ String primaryColor ,
25+ ColorDisplayResponse primaryColorDisplay ,
26+ List <SecondaryColorResponse > secondaryColors ,
2227 List <StyleTagResponse > styles ,
2328 SourceType sourceType ,
2429 String externalSource ,
2530 String externalProductId ,
2631 String externalProductUrl ,
2732 Boolean isVerified ,
2833 Boolean isFavorite ,
34+ String size ,
35+ String season ,
36+ String userImageUrl ,
2937 LocalDateTime createdAt ,
3038 LocalDateTime updatedAt
3139) {
3240
3341 public static ClothesResponse from (Clothes clothes ) {
34- ClothesColor clothesColor = ClothesColor .fromCode (clothes .getColor ());
42+ return from (clothes , null );
43+ }
44+
45+ public static ClothesResponse from (Clothes clothes , WardrobeClothes wardrobeClothes ) {
46+ ClothingColor primaryColorTag = clothes .getSortedColorTags ().stream ()
47+ .filter (color -> color .getColorRole () == ColorRole .PRIMARY )
48+ .findFirst ()
49+ .orElse (null );
3550
36- List <StyleTagResponse > styles = clothes .getStyleTags ().stream ()
51+ String primaryColorCode = primaryColorTag != null ? primaryColorTag .getColorCode () : null ;
52+ ColorDisplayResponse primaryColorDisplay = primaryColorCode != null
53+ ? toColorDisplay (primaryColorCode )
54+ : null ;
55+
56+ List <SecondaryColorResponse > secondaryColors = clothes .getSortedColorTags ().stream ()
57+ .filter (color -> color .getColorRole () == ColorRole .SECONDARY )
58+ .map (color -> new SecondaryColorResponse (
59+ color .getColorCode (),
60+ toColorDisplay (color .getColorCode ()),
61+ color .getSortOrder ()
62+ ))
63+ .toList ();
64+
65+ List <StyleTagResponse > styles = clothes .getSortedStyleTags ().stream ()
3766 .map (tag -> new StyleTagResponse (
3867 tag .getStyle ().getId (),
3968 tag .getStyle ().getCode (),
40- tag .getStyle ().getName ()
69+ tag .getStyle ().getName (),
70+ tag .getStyleRole ().name (),
71+ tag .getSortOrder ()
4172 ))
4273 .toList ();
4374
4475 return new ClothesResponse (
4576 clothes .getId (),
46- clothes .getWardrobe ().getId (),
47- clothes .getWardrobe ().getUser ().getId (),
77+ wardrobeClothes != null ? wardrobeClothes .getId () : null ,
78+ wardrobeClothes != null ? wardrobeClothes .getWardrobe ().getId () : null ,
79+ wardrobeClothes != null ? wardrobeClothes .getWardrobe ().getUser ().getId () : null ,
4880 clothes .getName (),
4981 clothes .getBrandName (),
5082 clothes .getProductCode (),
5183 clothes .getImageUrl (),
5284 clothes .getCategory (),
5385 clothes .getItemType (),
54- clothes .getColor (),
55- new ColorDisplayResponse (
56- clothesColor .name (),
57- clothesColor .getLabel (),
58- clothesColor .getHex ()
59- ),
86+ primaryColorCode ,
87+ primaryColorDisplay ,
88+ secondaryColors ,
6089 styles ,
6190 clothes .getSourceType (),
6291 clothes .getExternalSource (),
6392 clothes .getExternalProductId (),
6493 clothes .getExternalProductUrl (),
6594 clothes .getIsVerified (),
66- clothes .getIsFavorite (),
95+ wardrobeClothes != null ? wardrobeClothes .getFavorite () : null ,
96+ wardrobeClothes != null ? wardrobeClothes .getSize () : null ,
97+ wardrobeClothes != null ? wardrobeClothes .getSeason () : null ,
98+ wardrobeClothes != null ? wardrobeClothes .getUserImageUrl () : null ,
6799 clothes .getCreatedAt (),
68100 clothes .getUpdatedAt ()
69101 );
70102 }
71103
104+ private static ColorDisplayResponse toColorDisplay (String colorCode ) {
105+ ClothesColor clothesColor = ClothesColor .fromCode (colorCode );
106+ return new ColorDisplayResponse (
107+ clothesColor .name (),
108+ clothesColor .getLabel (),
109+ clothesColor .getHex ()
110+ );
111+ }
112+
72113 public record ColorDisplayResponse (
73114 String code ,
74115 String name ,
75116 String hex
76117 ) {
77118 }
78119
120+ public record SecondaryColorResponse (
121+ String code ,
122+ ColorDisplayResponse colorDisplay ,
123+ Byte sortOrder
124+ ) {
125+ }
126+
79127 public record StyleTagResponse (
80128 Long styleId ,
81129 String code ,
82- String name
130+ String name ,
131+ String styleRole ,
132+ Byte sortOrder
83133 ) {
84134 }
85135}
0 commit comments