Skip to content

Commit

Permalink
feat: ABLY 형태의 옵션 구조 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Ogu1208 committed Jul 20, 2024
1 parent f177414 commit 4af04a6
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/org/store/clothstar/product/domain/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import lombok.NoArgsConstructor;
import org.hibernate.annotations.BatchSize;
import org.store.clothstar.product.dto.request.UpdateProductRequest;
import org.store.clothstar.productLine.domain.ProductLine;
import org.store.clothstar.product.entity.ProductEntity;

@Entity
@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -32,6 +32,9 @@ public class Product {

private Long stock;

@OneToMany(mappedBy = "product", cascade = CascadeType.ALL)
private List<Option> Options;

public void updateOption(UpdateProductRequest updateProductRequest) {
this.name = updateProductRequest.getName();
this.extraCharge = updateProductRequest.getExtraCharge();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.store.clothstar.productLine.domain;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity(name = "goods_option")
public class GoodsOption {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private List<String> optionNames;
private int originalPrice;
private int price;
private int stock;
private String deliveryType;

@ManyToOne
@JoinColumn(name = "product_option_id")
private Option option;
}
52 changes: 52 additions & 0 deletions src/main/java/org/store/clothstar/productLine/domain/Option.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.store.clothstar.productLine.domain;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

/**
* 옵션 그룹 내의 개별 옵션을 관리한.
* ex) 색상의 경우 “연청”, “중청”
*
* {
* "id": 1,
* "productOptionGroup": 1,
* "name": "연청",
* "depth": 1,
* "goodsOptionSno": 157877069
* },
* {
* "id": 2,
* "productOptionGroup": 1,
* "name": "중청",
* "depth": 1,
* "goodsOptionSno": 157877085
* }
*
*/

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity(name = "option_group")
public class Option {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long optionId;
private String name;
private int depth;
private Long goodsOptionSno;

@ManyToOne
@JoinColumn(name = "option_group_id")
private OptionGroup optionGroup;

@OneToMany(mappedBy = "productOption", cascade = CascadeType.ALL)
private List<GoodsOption> goodsOptions;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.store.clothstar.productLine.domain;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

/**
* 제품의 옵션 그룹을 관리한다.
* ex) 색상, 기장, 사이즈
*
* {
* "id": 1,
* "productLine": 1,
* "name": "색상",
* "depth": 1
* },
* {
* "id": 2,
* "productLine": 1,
* "name": "기장",
* "depth": 2
* }
*/

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity(name = "option_group")
public class OptionGroup {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long optionGroupId;
private String name;
private int depth;

@ManyToOne
@JoinColumn(name = "product_line_id")
private ProductLine productLine;

@OneToMany(mappedBy = "OptionGroup", cascade = CascadeType.ALL)
private List<Option> options;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.time.LocalDateTime;
import java.util.List;

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
Expand Down Expand Up @@ -56,6 +57,19 @@ public class ProductLine extends BaseTimeEntity {
@JsonIgnore
private List<Product> products;

@Enumerated(EnumType.STRING)
private ProductLineStatus status;

@OneToMany(mappedBy = "productLine", cascade = CascadeType.ALL)
private List<OptionGroup> productOptionGroups;


@OneToMany(mappedBy = "productLine", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
// @JsonBackReference
@JsonIgnore
private List<Product> products;
>>>>>>> Stashed changes

public void updateProductLine(UpdateProductLineRequest updateProductLineRequest) {
this.name = updateProductLineRequest.getName();
this.content = updateProductLineRequest.getContent();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.store.clothstar.productLine.domain.type;

public enum Color {
BLACK, WHITE, GREY, BLUE, BROWN, BEIGE, IVORY, PINK, GREEN, SKY_BLUE, NAVY,
YELLOW, PURPLE, DARK_GREY, DARK_GREEN, ORANGE, MINT, LIGHT_PINK, RED
}

0 comments on commit 4af04a6

Please sign in to comment.