Skip to content

Commit

Permalink
Merge pull request #96 from ClothingStoreService/refactor/#95-order-d…
Browse files Browse the repository at this point in the history
…esign

Refactor/#95 order design
  • Loading branch information
axhtl authored Jul 13, 2024
2 parents f5c0e31 + 4600430 commit 0138753
Show file tree
Hide file tree
Showing 37 changed files with 631 additions and 558 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.store.clothstar.orderDetail.controller;
package org.store.clothstar.order.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -9,8 +9,8 @@
import org.springframework.web.bind.annotation.*;
import org.store.clothstar.common.dto.MessageDTO;
import org.store.clothstar.common.dto.SaveResponseDTO;
import org.store.clothstar.orderDetail.dto.request.AddOrderDetailRequest;
import org.store.clothstar.orderDetail.service.OrderDetailService;
import org.store.clothstar.order.dto.request.AddOrderDetailRequest;
import org.store.clothstar.order.service.OrderDetailService;

@Tag(name = "OrderDetail", description = "주문 내 개별 상품에 대한 옵션, 수량 등을 나타내는, 주문상세(OrderDetail) 정보 관리에 대한 API 입니다.")
@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Tag(name = "OrderSeller", description = "판매자(OrderSeller)의 주문 정보 관리에 대한 API 입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/orders")
@RequestMapping("/v1/orders/seller")
public class OrderSellerController {

private final OrderSellerService orderSellerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/orders")
public class OrderController {
public class OrderUserController {

private final OrderService orderService;
private final OrderApplicationService orderApplicationService;
Expand Down Expand Up @@ -58,13 +58,20 @@ public ResponseEntity<SaveResponseDTO> saveOrder(@RequestBody @Validated OrderRe
orderId, HttpStatus.OK.value(), "주문이 정상적으로 생성되었습니다."));
}

@Operation(summary = "구매 확정", description = "구매자가 구매 확정 시, 주문상태가 '구매확정'으로 변경된다.")
@PatchMapping("{orderId}")
public ResponseEntity<MessageDTO> deliveredToConfirmOrder(@PathVariable Long orderId) {
orderService.deliveredToConfirmOrder(orderId);
@Operation(summary = "(구매자)구매 확정", description = "구매자가 구매 확정 시, 주문상태가 '구매확정'으로 변경된다(단, 주문상태가 '배송완료'일 때만 가능).")
@PatchMapping("{orderId}/confirm")
public ResponseEntity<MessageDTO> confirmOrder(@PathVariable Long orderId) {
orderService.confirmOrder(orderId);
return ResponseEntity.ok(new MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 구매 확정 되었습니다."));
}

@Operation(summary = "(구매자)주문 취소", description = "구매자가 주문 취소 시, 주문상태가 '주문취소'로 변경된다(단, 주문상태가 '승인대기' 또는 '주문승인'일 때만 가능).")
@PatchMapping("{orderId}/cancel")
public ResponseEntity<MessageDTO> cancelOrder(@PathVariable Long orderId) {
orderService.cancelOrder(orderId);
return ResponseEntity.ok(new MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 취소되었습니다."));
}

@Operation(summary = "주문 삭제", description = "주문 삭제시간을 현재시간으로 업데이트 한다.")
@DeleteMapping("{orderId}")
public ResponseEntity<MessageDTO> deleteOrder(@PathVariable Long orderId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.store.clothstar.order.entity;
package org.store.clothstar.order.domain;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.store.clothstar.common.entity.BaseEntity;
import org.store.clothstar.order.type.PaymentMethod;
import org.store.clothstar.order.type.Status;
import org.store.clothstar.orderDetail.entity.OrderDetailEntity;
import org.store.clothstar.order.domain.type.PaymentMethod;
import org.store.clothstar.order.domain.type.Status;
import org.store.clothstar.order.domain.vo.TotalPrice;

import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -18,39 +18,32 @@
@Getter
@Builder
@Entity(name = "orders")
public class OrderEntity extends BaseEntity {
public class Order extends BaseEntity {
@Id
private Long orderId;

@Column(name = "member_id")
private Long memberId;

@Column(name = "address_id")
private Long addressId;

@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true)
private List<OrderDetailEntity> orderDetails;
private List<OrderDetail> orderDetails;

@Enumerated(EnumType.STRING)
private Status status;

@Column(name = "total_shipping_price")
private int totalShippingPrice;

@Column(name = "total_products_price")
private int totalProductsPrice;

@Enumerated(EnumType.STRING)
@Column(name = "payment_method")
private PaymentMethod paymentMethod;

@Column(name = "total_payment_price")
private int totalPaymentPrice;
@Embedded
TotalPrice totalPrice;


@Column(name = "member_id")
private Long memberId;

@Column(name = "address_id")
private Long addressId;

public void updatePrices(int totalProductsPrice, int totalPaymentPrice) {
this.totalProductsPrice = totalProductsPrice;
this.totalPaymentPrice = totalPaymentPrice;
}

public void updateDeletedAt() {
this.deletedAt = LocalDateTime.now();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.store.clothstar.orderDetail.entity;
package org.store.clothstar.order.domain;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.store.clothstar.common.entity.BaseEntity;
import org.store.clothstar.order.entity.OrderEntity;
import org.store.clothstar.order.domain.vo.Price;

import java.time.LocalDateTime;

Expand All @@ -15,28 +15,25 @@
@NoArgsConstructor
@Builder
@Entity(name = "order_detail")
public class OrderDetailEntity extends BaseEntity {
public class OrderDetail extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long orderDetailId;

private int quantity;
@Column(name = "product_line_id")
private Long productLineId;

@Column(name = "fixed_price")
private int fixedPrice; // 고정된 상품 가격 ( 주문 당시 가격 )
@Column(name = "product_id")
private Long productId;

private int quantity;

@Column(name = "onekind_total_price")
private int oneKindTotalPrice; // 상품 종류 하나당 총 가격
@Embedded
Price price;

@ManyToOne
@JoinColumn(name = "order_id")
private OrderEntity order;

@JoinColumn(name = "product_line_id")
private Long productLineId;

@JoinColumn(name = "product_id")
private Long productId;
private Order order;

public void updateDeletedAt() {
this.deletedAt = LocalDateTime.now();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.store.clothstar.order.type;
package org.store.clothstar.order.domain.type;

public enum ApprovalStatus {
APPROVE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.store.clothstar.order.type;
package org.store.clothstar.order.domain.type;

public enum PaymentMethod {
CARD,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.store.clothstar.order.type;
package org.store.clothstar.order.domain.type;

public enum Status {
WAITING,
APPROVE,
DELIVERING,
DELIVERED,
CONFIRM,
CANCEL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.store.clothstar.order.dto.reponse;
package org.store.clothstar.order.domain.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.store.clothstar.order.domain.vo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.store.clothstar.order.domain.OrderDetail;
import org.store.clothstar.product.entity.ProductEntity;
import org.store.clothstar.productLine.entity.ProductLineEntity;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class OrderDetailDTO {

private Long orderDetailId;
private String productName; // 상품명
private String optionName;
private String brandName;
private int productPrice; // 고정된 상품 가격 ( 주문 당시 가격 )
private int extraCharge;
private int quantity;
private int totalPrice; // 상품 종류 하나당 총 가격

public static OrderDetailDTO from(OrderDetail orderDetail, ProductEntity productEntity, ProductLineEntity productLineEntity){

return OrderDetailDTO.builder()
.orderDetailId(orderDetail.getOrderDetailId())
.productName(productLineEntity.getName())
.optionName(productEntity.getName())
.brandName(productLineEntity.getSeller().getBrandName())
.productPrice(productLineEntity.getPrice())
.extraCharge(productEntity.getExtraCharge())
.quantity(orderDetail.getQuantity())
.totalPrice(orderDetail.getPrice().getOneKindTotalPrice())
.build();
}
}

20 changes: 20 additions & 0 deletions src/main/java/org/store/clothstar/order/domain/vo/Price.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.store.clothstar.order.domain.vo;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Embeddable
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Price {
@Column(name = "fixed_price")
private int fixedPrice; // 고정된 상품 가격 ( 주문 당시 가격 )
@Column(name = "onekind_total_price")
private int oneKindTotalPrice; // 상품 종류 하나당 총 가격
}
27 changes: 27 additions & 0 deletions src/main/java/org/store/clothstar/order/domain/vo/TotalPrice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.store.clothstar.order.domain.vo;

import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Embeddable
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TotalPrice {
@Column(name = "total_shipping_price")
private int shipping;
@Column(name = "total_products_price")
private int products;
@Column(name = "total_payment_price")
private int payment;

public void updatePrices(int totalProductsPrice, int totalPaymentPrice) {
this.products = totalProductsPrice;
this.payment = totalPaymentPrice;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.store.clothstar.orderDetail.dto.response;
package org.store.clothstar.order.dto.reponse;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
Expand Down Expand Up @@ -44,22 +44,4 @@ public class OrderDetailResponse {

@Schema(description = "브랜드 이름", example = "나이키")
private String brandName;


// public static OrderDetailResponse fromOrderDetailEntity(OrderDetailEntity orderDetailEntity, ProductLineEntity productLineEntity, ProductEntity productEntity) {
// return OrderDetailResponse.builder()
// .orderDetailId(orderDetailEntity.getOrderDetailId())
// .orderId(orderDetailEntity.getOrder().getOrderId())
// .productLineId(orderDetailEntity.getProductLineId())
// .productId(orderDetailEntity.getProductId())
// .quantity(orderDetailEntity.getQuantity())
// .fixedPrice(orderDetailEntity.getFixedPrice())
// .oneKindTotalPrice(orderDetailEntity.getOneKindTotalPrice())
// .name(orderDetailEntity.getName())
// .stock(orderDetailEntity.getStock())
// .optionName(orderDetailEntity.getName())
// .extraCharge(orderDetailEntity.getExtraCharge())
// .brandName(orderDetailEntity.getSeller().getBrandName())
// .build();
// }
}
Loading

0 comments on commit 0138753

Please sign in to comment.