Skip to content

Commit 4f320b7

Browse files
authored
Merge pull request #133 from IT-Cotato/feature/132
[Fix] 카테고리별 사이즈표 타입 필드 추가
2 parents ffb7479 + 50d5bf3 commit 4f320b7

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

src/main/java/com/ongil/backend/domain/category/entity/Category.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6+
import com.ongil.backend.domain.category.enums.SizeChartType;
67
import com.ongil.backend.global.common.entity.BaseEntity;
78

89
import jakarta.persistence.*;
@@ -28,6 +29,10 @@ public class Category extends BaseEntity {
2829
@Column(name = "icon_url", length = 500)
2930
private String iconUrl;
3031

32+
@Enumerated(EnumType.STRING)
33+
@Column(name = "size_chart_type", length = 20)
34+
private SizeChartType sizeChartType;
35+
3136
@Column(name = "display_order", nullable = false)
3237
private Integer displayOrder;
3338

@@ -39,15 +44,16 @@ public class Category extends BaseEntity {
3944
private List<Category> subCategories = new ArrayList<>();
4045

4146
@Builder
42-
public Category(String name, String iconUrl, Integer displayOrder, Category parentCategory) {
47+
public Category(String name, String iconUrl, Integer displayOrder, Category parentCategory, SizeChartType sizeChartType) {
4348
this.name = name;
4449
this.iconUrl = iconUrl;
4550
this.displayOrder = displayOrder;
4651
this.parentCategory = parentCategory;
52+
this.sizeChartType = sizeChartType;
4753
}
4854

4955
// 카테고리 정보 수정
50-
public void updateCategory(String name, String iconUrl, Integer displayOrder, Category parentCategory) {
56+
public void updateCategory(String name, String iconUrl, Integer displayOrder, Category parentCategory, SizeChartType sizeChartType) {
5157
if (name != null) {
5258
this.name = name;
5359
}
@@ -66,5 +72,8 @@ public void updateCategory(String name, String iconUrl, Integer displayOrder, Ca
6672
}
6773
this.parentCategory = parentCategory;
6874
}
75+
if (sizeChartType != null) {
76+
this.sizeChartType = sizeChartType;
77+
}
6978
}
7079
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.ongil.backend.domain.category.enums;
2+
3+
import lombok.Getter;
4+
import lombok.RequiredArgsConstructor;
5+
6+
@Getter
7+
@RequiredArgsConstructor
8+
public enum SizeChartType {
9+
TOP_OUTERWEAR("상의 및 아우터"),
10+
PANTS("바지"),
11+
SKIRT("스커트"),
12+
DRESS("원피스");
13+
14+
private final String description;
15+
}

src/main/java/com/ongil/backend/domain/product/converter/ProductConverter.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import org.springframework.stereotype.Component;
99

10+
import com.ongil.backend.domain.category.entity.Category;
11+
import com.ongil.backend.domain.category.enums.SizeChartType;
1012
import com.ongil.backend.domain.product.dto.response.ProductDetailResponse;
1113
import com.ongil.backend.domain.product.dto.response.ProductOptionResponse;
1214
import com.ongil.backend.domain.product.dto.response.ProductSimpleResponse;
@@ -38,6 +40,7 @@ public ProductDetailResponse toDetailResponse(Product product, List<ProductOptio
3840
.brandName(product.getBrand().getName())
3941
.categoryId(product.getCategory().getId())
4042
.categoryName(product.getCategory().getName())
43+
.sizeChartType(getSizeChartType(product))
4144
.onSale(product.getOnSale())
4245
.productType(product.getProductType())
4346
.reviewCount(product.getReviewCount())
@@ -150,4 +153,17 @@ private String getFirstImage(String imageUrls) {
150153
List<String> images = parseStringToList(imageUrls);
151154
return images.isEmpty() ? null : images.get(0);
152155
}
156+
157+
// 사이즈표 타입 가져오기
158+
private SizeChartType getSizeChartType(Product product) {
159+
Category category = product.getCategory();
160+
161+
// 하위 카테고리라면 상위 카테고리의 타입 사용
162+
if (category.getParentCategory() != null) {
163+
return category.getParentCategory().getSizeChartType();
164+
}
165+
166+
// 상위 카테고리라면 자기 자신의 타입 사용
167+
return category.getSizeChartType();
168+
}
153169
}

src/main/java/com/ongil/backend/domain/product/dto/response/ProductDetailResponse.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.List;
44

5+
import com.ongil.backend.domain.category.enums.SizeChartType;
56
import com.ongil.backend.domain.product.enums.ProductType;
67

78
import io.swagger.v3.oas.annotations.media.Schema;
@@ -60,6 +61,9 @@ public class ProductDetailResponse {
6061
@Schema(description = "카테고리명")
6162
private String categoryName;
6263

64+
@Schema(description = "사이즈표 타입")
65+
private SizeChartType sizeChartType;
66+
6367
// 상태
6468
@Schema(description = "판매 중 여부")
6569
private Boolean onSale;

0 commit comments

Comments
 (0)