Skip to content

Commit

Permalink
Merge pull request #43 from marinesnow34/current
Browse files Browse the repository at this point in the history
Feat: 결제 상태 구현 완료
  • Loading branch information
marinesnow34 authored Nov 21, 2023
2 parents 18f55da + cbf3aba commit a2fd535
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/readyvery/readyverydemo/domain/Order.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -70,6 +72,9 @@ public class Order extends BaseTimeEntity {
@Column
private Boolean payStatus; // 결제 성공 실패 여부

@Column
private LocalDateTime estimatedTime;

// 가게 아이템 연관 관계
// @OneToMany(mappedBy = "order")
// @Builder.Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() // 해당 요청은 인증이 필요함
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +77,12 @@ public ResponseEntity<HistoryRes> getHistories(@AuthenticationPrincipal CustomUs
return new ResponseEntity<>(historyRes, HttpStatus.OK);
}

@GetMapping("/current")
public ResponseEntity<CurrentRes> getCurrent(@RequestParam("orderId") String orderId) {
CurrentRes currentRes = orderService.getCurrent(orderId);
return new ResponseEntity<>(currentRes, HttpStatus.OK);
}

@PostMapping("/cart")
public ResponseEntity<CartAddRes> addCart(@AuthenticationPrincipal CustomUserDetails userDetails,
@RequestBody CartAddReq cartAddReq) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Order> getOrders(UserInfo user) {
return ordersRepository.findAllByUserInfo(user).orElseThrow(
() -> new BusinessLogicException(ExceptionCode.ORDER_NOT_FOUND));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -214,4 +215,15 @@ 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() != null
? order.getEstimatedTime().format(DateTimeFormatter.ofPattern(TIME_FORMAT)) : null)
.build();
}
}

0 comments on commit a2fd535

Please sign in to comment.