Skip to content

Commit 4e5aa21

Browse files
authored
Merge pull request #55 from Gachigage/feature/product
[Feature/product] 상품 수정시 기존 priceTable 정보 DEPRECATED 상태로 변경
2 parents d7da3bb + 08d85f4 commit 4e5aa21

File tree

4 files changed

+43
-30
lines changed

4 files changed

+43
-30
lines changed

src/main/java/com/gachigage/product/domain/PriceTableStatus.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
public enum PriceTableStatus {
44
ACTIVE,
5-
INACTIVE
5+
INACTIVE,
6+
DEPRECATED
67
}

src/main/java/com/gachigage/product/domain/Product.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void modify(
224224
}
225225

226226
private void changePrices(List<ProductPrice> newPrices) {
227-
this.prices.forEach(ProductPrice::inActive);
227+
this.prices.forEach(ProductPrice::deprecated);
228228
for (ProductPrice price : newPrices) {
229229
addPrice(price);
230230
}
Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
package com.gachigage.product.domain;
22

3-
import jakarta.persistence.*;
3+
import jakarta.persistence.Column;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.FetchType;
6+
import jakarta.persistence.GeneratedValue;
7+
import jakarta.persistence.GenerationType;
8+
import jakarta.persistence.Id;
9+
import jakarta.persistence.JoinColumn;
10+
import jakarta.persistence.ManyToOne;
11+
import jakarta.persistence.Table;
412
import lombok.AccessLevel;
513
import lombok.Builder;
614
import lombok.Getter;
@@ -12,37 +20,41 @@
1220
@Table(name = "product_price")
1321
public class ProductPrice {
1422

15-
@Id
16-
@GeneratedValue(strategy = GenerationType.IDENTITY)
17-
@Column(name = "id")
18-
private Long id;
23+
@Id
24+
@GeneratedValue(strategy = GenerationType.IDENTITY)
25+
@Column(name = "id")
26+
private Long id;
1927

20-
@ManyToOne(fetch = FetchType.LAZY)
21-
@JoinColumn(name = "product_id", nullable = false)
22-
private Product product;
28+
@ManyToOne(fetch = FetchType.LAZY)
29+
@JoinColumn(name = "product_id", nullable = false)
30+
private Product product;
2331

24-
@Column(name = "quantity", nullable = false)
25-
private int quantity;
32+
@Column(name = "quantity", nullable = false)
33+
private int quantity;
2634

27-
@Column(name = "price", nullable = false)
28-
private int price;
35+
@Column(name = "price", nullable = false)
36+
private int price;
2937

30-
@Column(name = "status", nullable = false)
31-
private PriceTableStatus status;
38+
@Column(name = "status", nullable = false)
39+
private PriceTableStatus status;
3240

33-
@Builder
34-
public ProductPrice(Product product, int quantity, int price, PriceTableStatus status) {
35-
this.product = product;
36-
this.quantity = quantity;
37-
this.price = price;
38-
this.status = status;
39-
}
41+
@Builder
42+
public ProductPrice(Product product, int quantity, int price, PriceTableStatus status) {
43+
this.product = product;
44+
this.quantity = quantity;
45+
this.price = price;
46+
this.status = status;
47+
}
4048

41-
public void setProduct(Product product) {
42-
this.product = product;
43-
}
49+
public void setProduct(Product product) {
50+
this.product = product;
51+
}
4452

45-
public void inActive() {
46-
this.status = PriceTableStatus.INACTIVE;
47-
}
53+
public void inActive() {
54+
this.status = PriceTableStatus.INACTIVE;
55+
}
56+
57+
public void deprecated() {
58+
this.status = PriceTableStatus.DEPRECATED;
59+
}
4860
}

src/main/java/com/gachigage/product/dto/ProductDetailResponseDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static ProductDetailResponseDto fromEntity(Product product, boolean isPro
5454
.toList())
5555
.stock(product.getStock())
5656
.priceTable(product.getPrices().stream()
57-
// .filter(price -> price.getStatus() == PriceTableStatus.ACTIVE)
57+
.filter(price -> price.getStatus() != PriceTableStatus.DEPRECATED)
5858
.map(price -> ProductPriceDto.builder()
5959
.quantity(price.getQuantity())
6060
.price(price.getPrice())

0 commit comments

Comments
 (0)