Skip to content
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
13 changes: 13 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,17 @@ dependencies {

tasks.named('test') {
useJUnitPlatform()

def envFile = rootProject.file('.env')
if (envFile.exists()) {
envFile.readLines().each { line ->
line = line.trim()
if (!line.startsWith('#') && line.contains('=')) {
def idx = line.indexOf('=')
def key = line.substring(0, idx).trim()
def value = line.substring(idx + 1).trim()
environment key, value
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.BatchSize;

@BatchSize(size = 100)
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@Service
Expand Down Expand Up @@ -49,9 +51,15 @@ public CategoryUsageGuideResponse getUsageGuide() {
"SHORT_SLEEVE"
),
new GuideFieldResponse(
"color",
"컬러",
"색상 코드(code)를 DB에 저장하고, 화면에는 hex 값으로 색상 원(swatch)을 표시합니다.",
"primaryColor",
"주 색상",
"색상 코드(code)를 clothing_colors 테이블 PRIMARY 역할로 저장합니다.",
"WHITE"
),
new GuideFieldResponse(
"secondaryColors",
"보조 색상",
"색상 코드 배열입니다. clothing_colors 테이블 SECONDARY 역할로 저장합니다.",
"NAVY"
),
new GuideFieldResponse(
Expand All @@ -73,7 +81,8 @@ public CategoryUsageGuideResponse getUsageGuide() {
Map.of(
"category", "TOP",
"item_type", "SHORT_SLEEVE",
"color", "WHITE",
"primaryColor", "WHITE",
"secondaryColors", List.of("NAVY"),
"styles", List.of("CASUAL", "MINIMAL")
),
"colorDisplay",
Expand Down Expand Up @@ -120,7 +129,8 @@ public String getAiClassificationGuide() {
{
"category": "TOP",
"item_type": "SHORT_SLEEVE",
"color": "WHITE",
"primaryColor": "WHITE",
"secondaryColors": ["NAVY"],
"styles": ["CASUAL", "MINIMAL"]
}
""");
Expand All @@ -129,19 +139,48 @@ public String getAiClassificationGuide() {
}

public void validateClothesClassification(String categoryCode, String itemTypeCode, String colorCode) {
validateCategoryAndItemType(categoryCode, itemTypeCode);
validateColorCode(colorCode);
}

public void validateCategoryAndItemType(String categoryCode, String itemTypeCode) {
ClothesCategory.fromCode(categoryCode);
if (!ClothesItemType.matchesCategory(categoryCode, itemTypeCode)) {
throw new IllegalArgumentException("item_type이 category와 일치하지 않습니다.");
}
}

public void validateColorCode(String colorCode) {
ClothesColor.fromCode(colorCode);
}

public void validateClothesColors(String primaryColor, List<String> secondaryColors) {
validateColorCode(primaryColor);
if (secondaryColors == null || secondaryColors.isEmpty()) {
return;
}
Set<String> seen = new HashSet<>();
for (String secondaryColor : secondaryColors) {
validateColorCode(secondaryColor);
if (primaryColor.equals(secondaryColor)) {
throw new IllegalArgumentException("주 색상과 보조 색상은 같을 수 없습니다.");
}
if (!seen.add(secondaryColor)) {
throw new IllegalArgumentException("보조 색상에 중복된 값이 있습니다: " + secondaryColor);
}
}
}

public void validateStyleCodes(List<String> styleCodes) {
if (styleCodes == null || styleCodes.isEmpty()) {
throw new IllegalArgumentException("스타일은 1개 이상 선택해야 합니다.");
}
Set<String> seen = new HashSet<>();
for (String styleCode : styleCodes) {
StyleCode.fromCode(styleCode);
if (!seen.add(styleCode)) {
throw new IllegalArgumentException("스타일에 중복된 값이 있습니다: " + styleCode);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

public record ClothesConvertToOwnedRequest(
@NotBlank @Size(max = 100) String productCode,
@NotBlank @Size(max = 50) String size,
@Size(max = 50) String season,
@NotBlank @Size(max = 500) String userImageUrl,
@NotNull Boolean isVerified
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ public record ClothesCreateRequest(
@NotBlank @Size(max = 500) String imageUrl,
@NotBlank @Size(max = 50) String category,
@NotBlank @Size(max = 50) String itemType,
@NotBlank @Size(max = 50) String color,
@NotEmpty List<@NotBlank String> styles,
@NotBlank @Size(max = 50) String primaryColor,
@Size(max = 10) List<@NotBlank String> secondaryColors,
@NotEmpty @Size(max = 10) List<@NotBlank String> styles,
@NotBlank @Size(max = 50) String size,
@Size(max = 50) String season,
@NotNull Boolean isVerified
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ public record ClothesUpdateRequest(
@NotBlank @Size(max = 500) String imageUrl,
@NotBlank @Size(max = 50) String category,
@NotBlank @Size(max = 50) String itemType,
@NotBlank @Size(max = 50) String color,
@NotEmpty List<@NotBlank String> styles,
@NotBlank @Size(max = 50) String primaryColor,
@Size(max = 10) List<@NotBlank String> secondaryColors,
@NotEmpty @Size(max = 10) List<@NotBlank String> styles,
@NotBlank @Size(max = 50) String size,
@Size(max = 50) String season,
@NotNull Boolean isVerified
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ public record WishlistClothesCreateRequest(
@NotBlank @Size(max = 500) String imageUrl,
@NotBlank @Size(max = 50) String category,
@NotBlank @Size(max = 50) String itemType,
@NotBlank @Size(max = 50) String color,
@NotEmpty List<@NotBlank String> styles,
@NotBlank @Size(max = 50) String primaryColor,
@Size(max = 10) List<@NotBlank String> secondaryColors,
@NotEmpty @Size(max = 10) List<@NotBlank String> styles,
@NotBlank @Size(max = 50) String size,
@Size(max = 50) String season,
@NotBlank @Size(max = 50) String externalSource,
@NotBlank @Size(max = 255) String externalProductId,
@NotBlank @Size(max = 500) String externalProductUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import com.closetnangam.be.domain.catalog.enums.ClothesColor;
import com.closetnangam.be.domain.clothes.entity.Clothes;
import com.closetnangam.be.domain.clothes.entity.ClothingColor;
import com.closetnangam.be.domain.clothes.entity.WardrobeClothes;
import com.closetnangam.be.domain.clothes.enums.ColorRole;
import com.closetnangam.be.domain.clothes.enums.SourceType;

import java.time.LocalDateTime;
import java.util.List;

public record ClothesResponse(
Long clothesId,
Long wardrobeClothesId,
Long wardrobeId,
Long userId,
String name,
Expand All @@ -17,69 +21,115 @@ public record ClothesResponse(
String imageUrl,
String category,
String itemType,
String color,
ColorDisplayResponse colorDisplay,
String primaryColor,
ColorDisplayResponse primaryColorDisplay,
List<SecondaryColorResponse> secondaryColors,
List<StyleTagResponse> styles,
SourceType sourceType,
String externalSource,
String externalProductId,
String externalProductUrl,
Boolean isVerified,
Boolean isFavorite,
String size,
String season,
String userImageUrl,
LocalDateTime createdAt,
LocalDateTime updatedAt
) {

public static ClothesResponse from(Clothes clothes) {
ClothesColor clothesColor = ClothesColor.fromCode(clothes.getColor());
return from(clothes, null);
}

public static ClothesResponse from(Clothes clothes, WardrobeClothes wardrobeClothes) {
ClothingColor primaryColorTag = clothes.getSortedColorTags().stream()
.filter(color -> color.getColorRole() == ColorRole.PRIMARY)
.findFirst()
.orElse(null);

List<StyleTagResponse> styles = clothes.getStyleTags().stream()
String primaryColorCode = primaryColorTag != null ? primaryColorTag.getColorCode() : null;
ColorDisplayResponse primaryColorDisplay = primaryColorCode != null
? toColorDisplay(primaryColorCode)
: null;

List<SecondaryColorResponse> secondaryColors = clothes.getSortedColorTags().stream()
.filter(color -> color.getColorRole() == ColorRole.SECONDARY)
.map(color -> new SecondaryColorResponse(
color.getColorCode(),
toColorDisplay(color.getColorCode()),
color.getSortOrder()
))
.toList();

List<StyleTagResponse> styles = clothes.getSortedStyleTags().stream()
.map(tag -> new StyleTagResponse(
tag.getStyle().getId(),
tag.getStyle().getCode(),
tag.getStyle().getName()
tag.getStyle().getName(),
tag.getStyleRole().name(),
tag.getSortOrder()
))
.toList();

return new ClothesResponse(
clothes.getId(),
clothes.getWardrobe().getId(),
clothes.getWardrobe().getUser().getId(),
wardrobeClothes != null ? wardrobeClothes.getId() : null,
wardrobeClothes != null ? wardrobeClothes.getWardrobe().getId() : null,
wardrobeClothes != null ? wardrobeClothes.getWardrobe().getUser().getId() : null,
clothes.getName(),
clothes.getBrandName(),
clothes.getProductCode(),
clothes.getImageUrl(),
clothes.getCategory(),
clothes.getItemType(),
clothes.getColor(),
new ColorDisplayResponse(
clothesColor.name(),
clothesColor.getLabel(),
clothesColor.getHex()
),
primaryColorCode,
primaryColorDisplay,
secondaryColors,
styles,
clothes.getSourceType(),
clothes.getExternalSource(),
clothes.getExternalProductId(),
clothes.getExternalProductUrl(),
clothes.getIsVerified(),
clothes.getIsFavorite(),
wardrobeClothes != null ? wardrobeClothes.getFavorite() : null,
wardrobeClothes != null ? wardrobeClothes.getSize() : null,
wardrobeClothes != null ? wardrobeClothes.getSeason() : null,
wardrobeClothes != null ? wardrobeClothes.getUserImageUrl() : null,
clothes.getCreatedAt(),
clothes.getUpdatedAt()
);
}

private static ColorDisplayResponse toColorDisplay(String colorCode) {
ClothesColor clothesColor = ClothesColor.fromCode(colorCode);
return new ColorDisplayResponse(
clothesColor.name(),
clothesColor.getLabel(),
clothesColor.getHex()
);
}

public record ColorDisplayResponse(
String code,
String name,
String hex
) {
}

public record SecondaryColorResponse(
String code,
ColorDisplayResponse colorDisplay,
Byte sortOrder
) {
}

public record StyleTagResponse(
Long styleId,
String code,
String name
String name,
String styleRole,
Byte sortOrder
) {
}
}
Loading
Loading