Skip to content

Commit

Permalink
FEAT:add api order complete
Browse files Browse the repository at this point in the history
  • Loading branch information
rivopelu committed Nov 28, 2024
1 parent 8d495a4 commit 1d536f3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/pos/app/controller/OrderController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public interface OrderController {

@PatchMapping("v1/order-ready/{id}")
BaseResponse readyToTakeOrder(@PathVariable("id") String id);

@PatchMapping("v1/order-complete/{id}")
BaseResponse completeOrder(@PathVariable("id") String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public BaseResponse getOrderList(Pageable pageable) {
public BaseResponse readyToTakeOrder(String id) {
return ResponseHelper.createBaseResponse(orderService.readyToTakeOrder(id));
}

@Override
public BaseResponse completeOrder(String id) {
return ResponseHelper.createBaseResponse(orderService.completeOrder(id));
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/pos/app/service/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface OrderService {
Page<ResListOrder> getOrderList(Pageable pageable);

ResponseEnum readyToTakeOrder(String id);

ResponseEnum completeOrder(String id);
}
16 changes: 16 additions & 0 deletions src/main/java/com/pos/app/service/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ public ResponseEnum readyToTakeOrder(String id) {
}
}

@Override
public ResponseEnum completeOrder(String id) {
Optional<Order> findOrder = orderRepository.findById(id);
if (findOrder.isEmpty()) {
throw new NotFoundException(ResponseEnum.ORDER_NOT_FOUND.name());
}
Order order = findOrder.get();
order.setStatus(OrderStatusEnum.COMPLETED);
try {
orderRepository.save(order);
return ResponseEnum.SUCCESS;
} catch (Exception e) {
throw new SystemErrorException(e);
}
}

private BigInteger getListTotalTransaction(String orderId) {
List<Transaction> transactionList = transactionRepository.findAllByOrderId(orderId);
BigInteger totalTransaction = BigInteger.ZERO;
Expand Down

0 comments on commit 1d536f3

Please sign in to comment.