Skip to content

Commit

Permalink
chore: resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Kang1221 committed Sep 11, 2024
2 parents 2e2da2b + c13875c commit 53bc09c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/co/orange/ddanzi/common/error/Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum Error {
ACCOUNT_NAME_DOES_NOT_MATCH(HttpStatus.BAD_REQUEST, "The account name does not match to user name."),
DUE_DATE_IS_INCORRECT(HttpStatus.BAD_REQUEST, "The due date is incorrect."),
ITEM_IS_NOT_ON_SALE(HttpStatus.BAD_REQUEST, "The item is not on sale."),
INVALID_ORDER_STATUS(HttpStatus.BAD_REQUEST,"잘못된 주문 상태입니다."),

//402 Payment Required
PAYMENT_REQUIRED(HttpStatus.PAYMENT_REQUIRED, "Payment is required to place the order."),
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/co/orange/ddanzi/service/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;

@Slf4j
Expand Down Expand Up @@ -103,21 +104,23 @@ public ApiResponse<?> saveOrder(SaveOrderRequestDto requestDto){

@Transactional
public ApiResponse<?> getOrder(String orderId){
User user = authUtils.getUser();
Order order = orderRepository.findById(orderId).orElseThrow(() -> new OrderNotFoundException());
Item item = order.getItem();
Payment payment = paymentRepository.findByOrder(order);
return ApiResponse.onSuccess(Success.GET_ORDER_DETAIL_SUCCESS, setOrderResponseDto(user, order, item, payment));
return ApiResponse.onSuccess(Success.GET_ORDER_DETAIL_SUCCESS, setOrderResponseDto(order, item, payment));
}

@Transactional
public ApiResponse<?> confirmedOrderToBuy(String orderId){
User user = authUtils.getUser();
Order order = orderRepository.findById(orderId).orElseThrow(() -> new OrderNotFoundException());

if(!order.getBuyer().equals(user) || !(order.getStatus()==OrderStatus.SHIPPING || order.getStatus()==OrderStatus.DELAYED_SHIPPING || order.getStatus() ==OrderStatus.WARNING))
if(!order.getBuyer().equals(user))
return ApiResponse.onFailure(Error.UNAUTHORIZED_USER,null);

if(!(order.getStatus()==OrderStatus.SHIPPING || order.getStatus()==OrderStatus.DELAYED_SHIPPING || order.getStatus() ==OrderStatus.WARNING))
return ApiResponse.onFailure(Error.INVALID_ORDER_STATUS,Map.of("orderStatus", order.getStatus()));

order.updateStatus(OrderStatus.COMPLETED);
historyService.createOrderHistory(order);

Expand All @@ -133,9 +136,12 @@ public ApiResponse<?> confirmedOrderToSale(String orderId){
User user = authUtils.getUser();
Order order = orderRepository.findById(orderId).orElseThrow(() -> new OrderNotFoundException());

if(!order.getItem().getSeller().equals(user) || order.getStatus()!=OrderStatus.ORDER_PLACE)
if(!order.getItem().getSeller().equals(user))
return ApiResponse.onFailure(Error.UNAUTHORIZED_USER,null);

if(order.getStatus()!=OrderStatus.ORDER_PLACE)
return ApiResponse.onFailure(Error.INVALID_ORDER_STATUS, Map.of("orderStatus", order.getStatus()));

order.updateStatus(OrderStatus.SHIPPING);
historyService.createOrderHistory(order);
fcmService.sendMessageToUser(order.getBuyer(), FcmCase.B2, order);
Expand Down Expand Up @@ -232,7 +238,7 @@ private String createOrderId(String itemId){
return orderId;
}

private OrderResponseDto setOrderResponseDto(User user, Order order, Item item, Payment payment){
private OrderResponseDto setOrderResponseDto(Order order, Item item, Payment payment){
Product product = item.getProduct();
Discount discount = discountRepository.findById(product.getId()).orElseThrow(() -> new DiscountNotFoundException());

Expand All @@ -242,7 +248,7 @@ private OrderResponseDto setOrderResponseDto(User user, Order order, Item item,
.productName(product.getName())
.imgUrl(product.getImgUrl())
.originPrice(product.getOriginPrice())
.addressInfo(addressService.setAddressInfo(user))
.addressInfo(addressService.setAddressInfo(order.getBuyer()))
.sellerNickname(item.getSeller().getNickname())
.paymentMethod(payment.getMethod().getDescription())
.paidAt(payment.getEndedAt())
Expand Down

0 comments on commit 53bc09c

Please sign in to comment.