Skip to content

Commit

Permalink
Merge pull request #80 from ClothingStoreService/refactor/order
Browse files Browse the repository at this point in the history
Refactor/order
  • Loading branch information
axhtl authored Jul 10, 2024
2 parents 31998dd + c3d6424 commit bf4bea0
Show file tree
Hide file tree
Showing 28 changed files with 850 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.store.clothstar.order.dto.reponse;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.ConstructorExpression;
import javax.annotation.processing.Generated;

/**
* org.store.clothstar.order.dto.reponse.QOrderResponse is a Querydsl Projection type for OrderResponse
*/
@Generated("com.querydsl.codegen.DefaultProjectionSerializer")
public class QOrderResponse extends ConstructorExpression<OrderResponse> {

private static final long serialVersionUID = -1258133913L;

public QOrderResponse(com.querydsl.core.types.Expression<? extends org.store.clothstar.order.entity.OrderEntity> orderEntity, com.querydsl.core.types.Expression<? extends org.store.clothstar.orderDetail.entity.OrderDetailEntity> orderDetailEntity, com.querydsl.core.types.Expression<? extends org.store.clothstar.member.entity.MemberEntity> memberEntity, com.querydsl.core.types.Expression<? extends org.store.clothstar.member.entity.AddressEntity> addressEntity, com.querydsl.core.types.Expression<? extends org.store.clothstar.productLine.entity.ProductLineEntity> productLineEntity) {
super(OrderResponse.class, new Class<?>[]{org.store.clothstar.order.entity.OrderEntity.class, org.store.clothstar.orderDetail.entity.OrderDetailEntity.class, org.store.clothstar.member.entity.MemberEntity.class, org.store.clothstar.member.entity.AddressEntity.class, org.store.clothstar.productLine.entity.ProductLineEntity.class}, orderEntity, orderDetailEntity, memberEntity, addressEntity, productLineEntity);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.store.clothstar.orderDetail.dto;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.ConstructorExpression;
import javax.annotation.processing.Generated;

/**
* org.store.clothstar.orderDetail.dto.QOrderDetailDTO is a Querydsl Projection type for OrderDetailDTO
*/
@Generated("com.querydsl.codegen.DefaultProjectionSerializer")
public class QOrderDetailDTO extends ConstructorExpression<OrderDetailDTO> {

private static final long serialVersionUID = -767891785L;

public QOrderDetailDTO(com.querydsl.core.types.Expression<? extends org.store.clothstar.orderDetail.entity.OrderDetailEntity> orderDetailEntity) {
super(OrderDetailDTO.class, new Class<?>[]{org.store.clothstar.orderDetail.entity.OrderDetailEntity.class}, orderDetailEntity);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
, "/v1/members/login", "/signup", "/v1/members/email/**", "/v1/access",
"/v1/categories/**", "/v1/products/**", "/v1/productLines/**", "/v2/productLines/**",
"/v1/orderdetails", "/v1/orders", "membersPagingOffset", "membersPagingSlice",
"/v1/seller/orders/**", "/v1/seller/orders", "/v1/orders/**",
"/v1/orderdetails", "/v1/orders", "/v2/orders", "/v3/orders", "/v1/orders/list",
"/v1/orders/list","/ordersPagingOffset","/ordersPagingSlice","/v2/orders/list",
"/v1/seller/orders/**", "/v1/seller/orders", "/v1/orders/**", "/v1/orderdetails/**",
"/swagger-resources/**", "/swagger-ui/**", "/v3/api-docs/**", "/v1/members/auth/**"
).permitAll()
.requestMatchers(HttpMethod.POST, "/v1/members").permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.store.clothstar.common.dto.MessageDTO;
import org.store.clothstar.common.dto.SaveResponseDTO;
import org.store.clothstar.order.dto.reponse.OrderResponse;
import org.store.clothstar.order.dto.request.OrderRequestWrapper;
import org.store.clothstar.order.service.OrderApplicationService;
import org.store.clothstar.order.service.OrderService;
import org.store.clothstar.order.utils.URIBuilder;

import java.net.URI;



@Tag(name = "Order", description = "주문(Order) 정보 관리에 대한 API 입니다.")
@RestController
Expand All @@ -29,25 +29,48 @@ public class OrderController {

@Operation(summary = "단일 주문 조회", description = "단일 주문의 정보를 조회한다.")
@GetMapping("/{orderId}")
public ResponseEntity<OrderResponse> getOrder(@Validated @PathVariable Long orderId) {
public ResponseEntity<OrderResponse> getOrder(@PathVariable Long orderId) {
OrderResponse orderResponse = orderService.getOrder(orderId);
return ResponseEntity.ok(orderResponse);
}

@Operation(summary = "전체 주문 조회 offset 페이징", description = "전체 주문 리스트를 offset 페이징 형식으로 가져온다.")
@GetMapping("/offset")
public ResponseEntity<Page<OrderResponse>> getAllOrderOffsetPaging(
@PageableDefault(size = 15) Pageable pageable) {
Page<OrderResponse> orderPages = orderService.getAllOrderOffsetPaging(pageable);
return ResponseEntity.ok(orderPages);
}

@Operation(summary = "전체 주문 조회 slice 페이징", description = "전체 주문 리스트를 slice 페이징 형식으로 가져온다.")
@GetMapping("/slice")
public ResponseEntity<Slice<OrderResponse>> getAllOrderSlicePaging(
@PageableDefault(size = 15) Pageable pageable) {
Slice<OrderResponse> orderPages = orderService.getAllOrderSlicePaging(pageable);
return ResponseEntity.ok(orderPages);
}

@Operation(summary = "주문 생성", description = "단일 주문을 생성한다.")
@PostMapping
public ResponseEntity<URI> saveOrder(@RequestBody @Validated OrderRequestWrapper orderRequestWrapper) {
public ResponseEntity<SaveResponseDTO> saveOrder(@RequestBody @Validated OrderRequestWrapper orderRequestWrapper) {
Long orderId = orderApplicationService.saveOrderWithTransaction(orderRequestWrapper);
URI location = URIBuilder.buildURI(orderId);
return ResponseEntity.created(location).build();
return ResponseEntity.ok(new SaveResponseDTO(
orderId, HttpStatus.OK.value(), "주문이 정상적으로 생성되었습니다."));
}

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

@Operation(summary = "주문 삭제", description = "주문 삭제시간을 현재시간으로 업데이트 한다.")
@DeleteMapping("{orderId}")
public ResponseEntity<MessageDTO> deleteOrder(@PathVariable Long orderId) {
orderService.updateDeleteAt(orderId);
return ResponseEntity.ok(new MessageDTO(HttpStatus.OK.value(), "주문이 정상적으로 삭제되었습니다."));
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.store.clothstar.order.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class OrderViewController {
@GetMapping("/ordersPagingOffset")
public String ordersPagingOffset() {
return "orderOffsetList";
}

@GetMapping("/ordersPagingSlice")
public String ordersPagingSlice() {
return "orderSliceList";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.store.clothstar.order.dto.reponse;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "배송지 정보")
public class AddressDTO {
@Schema(description = "수령인 이름", example = "수빈")
private String receiverName;

@Schema(description = "기본 주소", example = "서울시 강남구")
private String addressBasic;

@Schema(description = "상세 주소", example = "123-456")
private String addressDetail;

@Schema(description = "전화번호", example = "010-1234-5678")
private String telNo;

@Schema(description = "배송 요청 사항", example = "문 앞에 놓아주세요.")
private String deliveryRequest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ public class OrderResponse {
@Schema(description = "주문 상태", example = "WAITING")
private Status status;

//address
private String receiverName;
private String addressBasic;
private String addressDetail;
private String telNo;
private String deliveryRequest;
@Schema(description = "주소 정보")
private AddressDTO address;

@Schema(description = "결제 수단", example = "CARD")
private PaymentMethod paymentMethod;
Expand All @@ -60,15 +56,6 @@ public class OrderResponse {
@Builder.Default
private List<OrderDetailDTO> orderDetailList = new ArrayList<>();

public OrderResponse(OrderEntity orderEntity, OrderDetailEntity orderDetailEntity, MemberEntity memberEntity, AddressEntity addressEntity,
ProductLineEntity productLineEntity, List<OrderDetailDTO> orderDetailList) {
this(orderEntity,
orderDetailEntity,
memberEntity, addressEntity, productLineEntity);
this.orderDetailList = orderDetailList != null ? orderDetailList : new ArrayList<>();
}


@QueryProjection
public OrderResponse(OrderEntity orderEntity,
OrderDetailEntity orderDetailEntity,
Expand All @@ -82,15 +69,17 @@ public OrderResponse(OrderEntity orderEntity,
this.totalProductsPrice = orderEntity.getTotalProductsPrice();
this.paymentMethod = orderEntity.getPaymentMethod();
this.totalPaymentPrice = orderEntity.getTotalPaymentPrice();
this.receiverName = addressEntity.getReceiverName();
this.addressBasic = addressEntity.getAddressBasic();
this.addressDetail = addressEntity.getAddressDetail();
this.telNo = addressEntity.getTelNo();
this.deliveryRequest = addressEntity.getDeliveryRequest();
this.address = AddressDTO.builder()
.receiverName(addressEntity.getReceiverName())
.addressBasic(addressEntity.getAddressBasic())
.addressDetail(addressEntity.getAddressDetail())
.telNo(addressEntity.getTelNo())
.deliveryRequest(addressEntity.getDeliveryRequest())
.build();
this.orderDetailList = new ArrayList<>();
}

public static OrderResponse fromOrderEntity(OrderEntity orderEntity) {
public static OrderResponse from(OrderEntity orderEntity) {
return OrderResponse.builder()
.orderId(orderEntity.getOrderId())
.ordererName(orderEntity.getMember().getName())
Expand All @@ -100,6 +89,13 @@ public static OrderResponse fromOrderEntity(OrderEntity orderEntity) {
.totalProductsPrice(orderEntity.getTotalProductsPrice())
.paymentMethod(orderEntity.getPaymentMethod())
.totalPaymentPrice(orderEntity.getTotalPaymentPrice())
.address(AddressDTO.builder()
.receiverName(orderEntity.getAddress().getReceiverName())
.addressBasic(orderEntity.getAddress().getAddressBasic())
.addressDetail(orderEntity.getAddress().getAddressDetail())
.telNo(orderEntity.getAddress().getTelNo())
.deliveryRequest(orderEntity.getAddress().getDeliveryRequest())
.build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import org.store.clothstar.order.type.Status;
import org.store.clothstar.order.utils.GenerateOrderId;

import java.time.LocalDateTime;

@Getter
@Builder
@NoArgsConstructor
Expand All @@ -40,7 +38,6 @@ public OrderEntity toOrderEntity(MemberEntity memberEntity, AddressEntity addres
.orderId(GenerateOrderId.generateOrderId())
.member(memberEntity)
.address(addressEntity)
.createdAt(LocalDateTime.now())
.status(Status.WAITING)
.totalShippingPrice(3000)
.totalProductsPrice(0)
Expand Down
23 changes: 6 additions & 17 deletions src/main/java/org/store/clothstar/order/entity/OrderEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.store.clothstar.common.entity.BaseEntity;
import org.store.clothstar.member.entity.AddressEntity;
import org.store.clothstar.member.entity.MemberEntity;
import org.store.clothstar.order.type.PaymentMethod;
Expand All @@ -19,17 +20,13 @@
@Getter
@Builder
@Entity(name = "orders")
public class OrderEntity {
public class OrderEntity extends BaseEntity {
@Id
private Long orderId;

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

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "created_at")
private LocalDateTime createdAt;


@Enumerated(EnumType.STRING)
private Status status;

Expand All @@ -53,21 +50,13 @@ public class OrderEntity {
@OneToOne
@JoinColumn(name = "address_id")
private AddressEntity address;
//
// @ManyToOne
// private OrderDetailEntity orderDetail;

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

public void setTotalPaymentPrice(int totalPaymentPrice) {
this.totalPaymentPrice = totalPaymentPrice;
}

public void updatePrices(int totalProductsPrice, int totalPaymentPrice) {
this.totalProductsPrice = totalProductsPrice;
this.totalPaymentPrice = totalPaymentPrice;
public void updateDeletedAt() {
this.deletedAt = LocalDateTime.now();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.store.clothstar.order.repository.order;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.store.clothstar.order.repository.order;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.store.clothstar.order.dto.reponse.OrderResponse;
import org.store.clothstar.order.entity.OrderEntity;

import java.util.List;
import java.util.Optional;

public interface OrderRepository {
Expand All @@ -11,8 +15,11 @@ public interface OrderRepository {

OrderResponse findOrderWithDetails(Long orderId);

Page<OrderResponse> findAllOffsetPaging(Pageable pageable);

Slice<OrderResponse> findAllSlicePaging(Pageable pageable);

OrderEntity save(OrderEntity orderEntity);

void deliveredToConfirmOrder(Long orderId);

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package org.store.clothstar.order.repository.orderSeller;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.store.clothstar.order.dto.reponse.OrderResponse;
import org.store.clothstar.order.entity.OrderEntity;

import java.util.List;

public interface OrderEntityRepositoryCustom {
//Order 관련 메서드
OrderResponse findOrderWithDetails(Long orderId);

Page<OrderResponse> findAllOffsetPaging(Pageable pageable);

Slice<OrderResponse> findAllSlicePaging(Pageable pageable);

//OrderSeller 관련 메서드
List<OrderResponse> findWaitingOrders();
}
Loading

0 comments on commit bf4bea0

Please sign in to comment.