Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: 바로 주문 추가 #119

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public class Constant {
public static final String IMG_URL = "/images/";
public static final String USER_CANCEL_RESON = "단순 변심";
public static final Integer EMPTY_CART = 0;
public static final Integer MAX_FASTORDER_SIZE = 5;
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public ResponseEntity<FailDto> tossPaymentFail(
return new ResponseEntity<>(result, HttpStatus.OK);
}

@GetMapping("/history/fast")
public ResponseEntity<HistoryRes> getFastHistories(@AuthenticationPrincipal CustomUserDetails userDetails) {
HistoryRes historyRes = orderService.getFastHistories(userDetails);
return new ResponseEntity<>(historyRes, HttpStatus.OK);
}

@GetMapping("/history/old")
public ResponseEntity<HistoryRes> getHistories(@AuthenticationPrincipal CustomUserDetails userDetails) {
HistoryRes historyRes = orderService.getHistories(userDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ public interface OrderService {
CartCountRes getCartCount(CustomUserDetails userDetails);

HistoryRes getNewHistories(CustomUserDetails userDetails);

HistoryRes getFastHistories(CustomUserDetails userDetails);
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@ public HistoryRes getNewHistories(CustomUserDetails userDetails) {

}

@Override
public HistoryRes getFastHistories(CustomUserDetails userDetails) {
UserInfo user = getUserInfo(userDetails);
List<Order> orders = getOrders(user);
return orderMapper.ordersToFastOrderRes(orders);
}

private void verifyReceipt(Order order, UserInfo user) {
verifyOrderReceipt(order);
verifyOrederUser(order, user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class HistoryDetailRes {
private String orderId;
private String storePhone;
private CartGetRes cart;
private String salePrice;
private Long salePrice;
private String method;
private String orderNumber;
private Object cancelReason;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,34 @@ public HistoryRes ordersToHistoryRes(List<Order> orders) {
.receipts(
orders
.stream()
.filter(order -> order.getProgress() == PICKUP)
.filter(order -> order.getProgress() == PICKUP
|| order.getProgress() == FAIL
|| order.getProgress() == CANCEL)
.map(this::orderToReceiptHistoryDto)
.toList())
.build();
}

public HistoryRes ordersToFastOrderRes(List<Order> orders) {
return HistoryRes.builder()
.receipts(
orders
.stream()
.filter(order -> order.getProgress() == COMPLETE
|| order.getProgress() == PICKUP)
.map(this::orderToReceiptHistoryDto)
.toList().subList(Math.max(orders.size() - MAX_FASTORDER_SIZE, 0), orders.size()))
.build();
}

public HistoryRes ordersToNewHistoryRes(List<Order> orders) {
return HistoryRes.builder()
.receipts(
orders
.stream()
.filter(order -> order.getProgress() != REQUEST)
.filter(order -> order.getProgress() != CANCEL)
.filter(order -> order.getProgress() != PICKUP)
.filter(order -> order.getProgress() != FAIL)
.filter(order -> order.getProgress() == ORDER
|| order.getProgress() == MAKE
|| order.getProgress() == COMPLETE)
.map(this::orderToReceiptHistoryDto)
.toList())
.build();
Expand Down Expand Up @@ -301,9 +314,9 @@ public HistoryDetailRes orderToHistoryDetailRes(Order order) {
.storePhone(order.getStore().getPhone())
.cart(cartToCartGetRes(order.getCart()))
.salePrice(
String.valueOf(order.getCoupon() != null
order.getCoupon() != null
? order.getCoupon().getCouponDetail().getSalePrice()
: null))
: 0L)
.method(order.getMethod())
.build();
}
Expand Down