Skip to content

Commit f741e25

Browse files
authored
Merge pull request #33 from UruruLab/fix/30-editProductProductoptionProductnoticeEntity
Product, ProductOption, ProductNotice Entity 수정
2 parents f0256ff + 165637c commit f741e25

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

src/main/java/com/ururulab/ururu/product/domain/entity/Product.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class Product extends BaseEntity {
4040
@OneToMany(mappedBy = "product", orphanRemoval = true)
4141
private List<ProductCategory> productCategories = new ArrayList<>();
4242

43+
@OneToOne(mappedBy = "product", cascade = CascadeType.ALL, orphanRemoval = true)
44+
private ProductNotice productNotice;
45+
4346
public static Product of(
4447
//Seller seller,
4548
String name,

src/main/java/com/ururulab/ururu/product/domain/entity/ProductNotice.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ public class ProductNotice extends BaseEntity {
1717
private Long id;
1818

1919
@OneToOne(fetch = FetchType.LAZY)
20-
@JoinColumn(name = "product_option_id")
21-
private ProductOption productOption;
20+
@JoinColumn(name = "product_id")
21+
private Product product;
2222

2323
@Column(nullable = false, length = 50)
2424
private String capacity; //용량
2525

26+
@Column(nullable = false, length = 50)
27+
private String spec; // 제품 주요 사양
28+
2629
@Column(nullable = false, length = 100)
2730
private String expiry; // 사용기한
2831

@@ -38,9 +41,6 @@ public class ProductNotice extends BaseEntity {
3841
@Column(nullable = false, length = 50)
3942
private String countryOfOrigin; //제조국
4043

41-
@Column(nullable = false, columnDefinition = "TEXT")
42-
private String fullIngredients; // 전성분
43-
4444
@Column(nullable = false)
4545
private boolean functionalCosmetics; // 기능성 여부
4646

@@ -54,28 +54,28 @@ public class ProductNotice extends BaseEntity {
5454
private String customerServiceNumber; //고객센터 번호
5555

5656
public static ProductNotice of(
57-
ProductOption productOption,
57+
Product product,
5858
String capacity,
59+
String spec,
5960
String expiry,
6061
String usage,
6162
String manufacturer,
6263
String responsibleSeller,
6364
String countryOfOrigin,
64-
String fullIngredients,
6565
boolean functionalCosmetics,
6666
String caution,
6767
String warranty,
6868
String customerServiceNumber
6969
){
7070
ProductNotice productNotice = new ProductNotice();
71-
productNotice.productOption = productOption;
71+
productNotice.product = product;
7272
productNotice.capacity = capacity;
73+
productNotice.spec = spec;
7374
productNotice.expiry = expiry;
7475
productNotice.usage = usage;
7576
productNotice.manufacturer = manufacturer;
7677
productNotice.responsibleSeller = responsibleSeller;
7778
productNotice.countryOfOrigin = countryOfOrigin;
78-
productNotice.fullIngredients = fullIngredients;
7979
productNotice.functionalCosmetics = functionalCosmetics;
8080
productNotice.caution = caution;
8181
productNotice.warranty = warranty;

src/main/java/com/ururulab/ururu/product/domain/entity/ProductOption.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
import lombok.AccessLevel;
66
import lombok.Getter;
77
import lombok.NoArgsConstructor;
8-
import org.hibernate.annotations.JdbcTypeCode;
9-
import org.hibernate.type.SqlTypes;
10-
11-
import java.util.Map;
128

139
@Entity
1410
@Getter
@@ -32,29 +28,25 @@ public class ProductOption extends BaseEntity {
3228
@Column(nullable = true)
3329
private String imageUrl;
3430

35-
@JdbcTypeCode(SqlTypes.JSON)
36-
@Column(nullable = true, columnDefinition = "JSON")
37-
private Map<String, String> specifications;
38-
3931
@Column(nullable = false)
4032
private boolean isDeleted = false;
4133

42-
@OneToOne(mappedBy = "productOption", cascade = CascadeType.ALL, orphanRemoval = true)
43-
private ProductNotice productNotice;
34+
@Column(nullable = false, columnDefinition = "TEXT")
35+
private String fullIngredients; // 전성분
4436

4537
public static ProductOption of(
4638
Product product,
4739
String name,
4840
int price,
4941
String imageUrl,
50-
Map<String,String> specifications
42+
String fullIngredients
5143
){
5244
ProductOption productOption = new ProductOption();
5345
productOption.product = product;
5446
productOption.name = name;
5547
productOption.price = price;
5648
productOption.imageUrl = imageUrl;
57-
productOption.specifications = specifications;
49+
productOption.fullIngredients = fullIngredients;
5850

5951
return productOption;
6052
}

src/main/java/com/ururulab/ururu/product/domain/repository/ProductRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public interface ProductRepository extends JpaRepository<Product, Long> {
3333
@Query("SELECT p FROM Product p LEFT JOIN FETCH p.productOptions po WHERE p.id = :productId AND po.isDeleted = false")
3434
Optional<Product> findByIdWithOptions(@Param("productId") Long productId);
3535

36-
// 상품 + 정보고시 함께 조회 -> 엔티티 구조 변경 후 주석 제거
37-
// @Query("SELECT p FROM Product p LEFT JOIN FETCH p.productNotice WHERE p.id = :productId")
38-
// Optional<Product> findByIdWithNotice(@Param("productId") Long productId);
36+
//상품 + 정보고시 함께 조회 -> 엔티티 구조 변경 후 주석 제거
37+
@Query("SELECT p FROM Product p LEFT JOIN FETCH p.productNotice WHERE p.id = :productId")
38+
Optional<Product> findByIdWithNotice(@Param("productId") Long productId);
3939
}

0 commit comments

Comments
 (0)