From 31cafa7a3e866df2bbba1f9de7ad0bc7a11bf247 Mon Sep 17 00:00:00 2001 From: marinesnow34 Date: Tue, 21 Nov 2023 17:12:37 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Feat:=20=EA=B2=B0=EC=A0=9C=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EA=B5=AC=ED=98=84=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../readyvery/readyverydemo/domain/Order.java | 5 +++++ .../global/exception/ExceptionCode.java | 3 ++- .../security/config/SpringSecurityConfig.java | 3 ++- .../src/order/OrderController.java | 7 +++++++ .../readyverydemo/src/order/OrderService.java | 3 +++ .../src/order/OrderServiceImpl.java | 18 ++++++++++++++++++ .../src/order/dto/CurrentRes.java | 16 ++++++++++++++++ .../src/order/dto/OrderMapper.java | 13 +++++++++++++ 8 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/readyvery/readyverydemo/src/order/dto/CurrentRes.java diff --git a/src/main/java/com/readyvery/readyverydemo/domain/Order.java b/src/main/java/com/readyvery/readyverydemo/domain/Order.java index 9a0e0ae..beeb015 100644 --- a/src/main/java/com/readyvery/readyverydemo/domain/Order.java +++ b/src/main/java/com/readyvery/readyverydemo/domain/Order.java @@ -1,5 +1,7 @@ package com.readyvery.readyverydemo.domain; +import java.time.LocalDateTime; + import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -70,6 +72,9 @@ public class Order extends BaseTimeEntity { @Column private Boolean payStatus; // 결제 성공 실패 여부 + @Column + private LocalDateTime estimatedTime; + // 가게 아이템 연관 관계 // @OneToMany(mappedBy = "order") // @Builder.Default diff --git a/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java b/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java index d4947fd..5e0a852 100644 --- a/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java +++ b/src/main/java/com/readyvery/readyverydemo/global/exception/ExceptionCode.java @@ -16,7 +16,8 @@ public enum ExceptionCode { ITEM_NOT_SAME_STORE(400, "Item is not same store."), TOSS_PAYMENT_SUCCESS_FAIL(400, "Toss payment success fail."), ORDER_NOT_FOUND(400, "Order does not exists."), - TOSS_PAYMENT_AMOUNT_NOT_MATCH(400, "Toss payment amount not match."); + TOSS_PAYMENT_AMOUNT_NOT_MATCH(400, "Toss payment amount not match."), + ORDER_NOT_CURRENT(400, "Order is not current."); private int status; private String message; diff --git a/src/main/java/com/readyvery/readyverydemo/security/config/SpringSecurityConfig.java b/src/main/java/com/readyvery/readyverydemo/security/config/SpringSecurityConfig.java index a489d4d..59d3c15 100644 --- a/src/main/java/com/readyvery/readyverydemo/security/config/SpringSecurityConfig.java +++ b/src/main/java/com/readyvery/readyverydemo/security/config/SpringSecurityConfig.java @@ -58,7 +58,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { "/oauth2/**", "/login", "/api/v1/store/**", - "/api/v1/board/**" + "/api/v1/board/**", + "/api/v1/order/current" ).permitAll() // 위를 제외한 나머지는 모두 허용 .anyRequest().authenticated() // 해당 요청은 인증이 필요함 ) diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderController.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderController.java index b5e0bf7..2f44874 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderController.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderController.java @@ -22,6 +22,7 @@ import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteReq; import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteRes; import com.readyvery.readyverydemo.src.order.dto.CartResetRes; +import com.readyvery.readyverydemo.src.order.dto.CurrentRes; import com.readyvery.readyverydemo.src.order.dto.FailDto; import com.readyvery.readyverydemo.src.order.dto.FoodyDetailRes; import com.readyvery.readyverydemo.src.order.dto.HistoryRes; @@ -76,6 +77,12 @@ public ResponseEntity getHistories(@AuthenticationPrincipal CustomUs return new ResponseEntity<>(historyRes, HttpStatus.OK); } + @GetMapping("/current") + public ResponseEntity getCurrent(@RequestParam("orderId") String orderId) { + CurrentRes currentRes = orderService.getCurrent(orderId); + return new ResponseEntity<>(currentRes, HttpStatus.OK); + } + @PostMapping("/cart") public ResponseEntity addCart(@AuthenticationPrincipal CustomUserDetails userDetails, @RequestBody CartAddReq cartAddReq) { diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderService.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderService.java index a8a5635..48bca2e 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderService.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderService.java @@ -10,6 +10,7 @@ import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteReq; import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteRes; import com.readyvery.readyverydemo.src.order.dto.CartResetRes; +import com.readyvery.readyverydemo.src.order.dto.CurrentRes; import com.readyvery.readyverydemo.src.order.dto.FailDto; import com.readyvery.readyverydemo.src.order.dto.FoodyDetailRes; import com.readyvery.readyverydemo.src.order.dto.HistoryRes; @@ -36,4 +37,6 @@ public interface OrderService { FailDto tossPaymentFail(String code, String orderId, String message) throws BusinessLogicException; HistoryRes getHistories(CustomUserDetails userDetails); + + CurrentRes getCurrent(String orderId); } diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java index 63d4101..7d2bfae 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java @@ -49,6 +49,7 @@ import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteReq; import com.readyvery.readyverydemo.src.order.dto.CartItemDeleteRes; import com.readyvery.readyverydemo.src.order.dto.CartResetRes; +import com.readyvery.readyverydemo.src.order.dto.CurrentRes; import com.readyvery.readyverydemo.src.order.dto.FailDto; import com.readyvery.readyverydemo.src.order.dto.FoodyDetailRes; import com.readyvery.readyverydemo.src.order.dto.HistoryRes; @@ -201,6 +202,23 @@ public HistoryRes getHistories(CustomUserDetails userDetails) { return orderMapper.ordersToHistoryRes(orders); } + @Override + public CurrentRes getCurrent(String orderId) { + Order order = getOrder(orderId); + verifyOrderCurrent(order); + return orderMapper.orderToCurrentRes(order); + } + + private void verifyOrderCurrent(Order order) { + if (order.getProgress().equals(Progress.ORDER) || + order.getProgress().equals(Progress.MAKE) || + order.getProgress().equals(Progress.COMPLETE) || + order.getProgress().equals(Progress.PICKUP)) { + return; + } + throw new BusinessLogicException(ExceptionCode.ORDER_NOT_CURRENT); + } + private List getOrders(UserInfo user) { return ordersRepository.findAllByUserInfo(user).orElseThrow( () -> new BusinessLogicException(ExceptionCode.ORDER_NOT_FOUND)); diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/dto/CurrentRes.java b/src/main/java/com/readyvery/readyverydemo/src/order/dto/CurrentRes.java new file mode 100644 index 0000000..3a0bb9f --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/src/order/dto/CurrentRes.java @@ -0,0 +1,16 @@ +package com.readyvery.readyverydemo.src.order.dto; + +import com.readyvery.readyverydemo.domain.Progress; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class CurrentRes { + private String name; + private Long orderNum; + private Progress progress; + private String orderName; + private String estimatedTime; +} diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java index 0ce2191..6e4bc9c 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java @@ -1,6 +1,7 @@ package com.readyvery.readyverydemo.src.order.dto; import static com.readyvery.readyverydemo.global.Constant.*; +import static org.hibernate.type.descriptor.java.JdbcTimeJavaType.*; import java.time.format.DateTimeFormatter; import java.util.List; @@ -214,4 +215,16 @@ private ReceiptHistoryDto orderToReceiptHistoryDto(Order order) { .orderId(order.getOrderId()) .build(); } + + public CurrentRes orderToCurrentRes(Order order) { + return CurrentRes.builder() + .name(order.getStore().getName()) + .orderNum(order.getId()) + .progress(order.getProgress()) + .orderName(order.getOrderName()) + // .estimatedTime(order.getEstimatedTime().format(DateTimeFormatter.ofPattern(TIME_FORMAT))) + .estimatedTime(order.getEstimatedTime() != null ? + order.getEstimatedTime().format(DateTimeFormatter.ofPattern(TIME_FORMAT)) : null) + .build(); + } } From cbf3abac44d1437c592a85ae583987ac9533d507 Mon Sep 17 00:00:00 2001 From: marinesnow34 Date: Tue, 21 Nov 2023 17:14:19 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Fix:=20build=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../readyverydemo/src/order/OrderServiceImpl.java | 8 ++++---- .../readyverydemo/src/order/dto/OrderMapper.java | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java index 7d2bfae..7f25ec3 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/OrderServiceImpl.java @@ -210,10 +210,10 @@ public CurrentRes getCurrent(String orderId) { } private void verifyOrderCurrent(Order order) { - if (order.getProgress().equals(Progress.ORDER) || - order.getProgress().equals(Progress.MAKE) || - order.getProgress().equals(Progress.COMPLETE) || - order.getProgress().equals(Progress.PICKUP)) { + if (order.getProgress().equals(Progress.ORDER) + || order.getProgress().equals(Progress.MAKE) + || order.getProgress().equals(Progress.COMPLETE) + || order.getProgress().equals(Progress.PICKUP)) { return; } throw new BusinessLogicException(ExceptionCode.ORDER_NOT_CURRENT); diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java index 6e4bc9c..686275a 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java @@ -222,9 +222,8 @@ public CurrentRes orderToCurrentRes(Order order) { .orderNum(order.getId()) .progress(order.getProgress()) .orderName(order.getOrderName()) - // .estimatedTime(order.getEstimatedTime().format(DateTimeFormatter.ofPattern(TIME_FORMAT))) - .estimatedTime(order.getEstimatedTime() != null ? - order.getEstimatedTime().format(DateTimeFormatter.ofPattern(TIME_FORMAT)) : null) + .estimatedTime(order.getEstimatedTime() != null + ? order.getEstimatedTime().format(DateTimeFormatter.ofPattern(TIME_FORMAT)) : null) .build(); } }