Skip to content

Commit

Permalink
FEAT:add new status order
Browse files Browse the repository at this point in the history
  • Loading branch information
rivopelu committed Nov 28, 2024
1 parent 13cd79d commit 8d495a4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/pos/app/controller/OrderController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import com.pos.app.model.request.ReqCreateOrder;
import com.pos.app.model.response.BaseResponse;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.*;

@BaseController("order")
public interface OrderController {
Expand All @@ -16,4 +14,7 @@ public interface OrderController {

@GetMapping("v1/order-list")
BaseResponse getOrderList(Pageable pageable);

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

@Override
public BaseResponse readyToTakeOrder(String id) {
return ResponseHelper.createBaseResponse(orderService.readyToTakeOrder(id));
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/pos/app/enums/OrderStatusEnum.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.pos.app.enums;

public enum OrderStatusEnum {
OPEN_BILL, COMPLETED, CREATED, IN_PROGRESS
COMPLETED, CREATED, IN_PROGRESS, READY
}
2 changes: 1 addition & 1 deletion src/main/java/com/pos/app/enums/ResponseEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public enum ResponseEnum {
ACCOUNT_DELETED_SUCCESSFULLY,
UNAUTHORIZED,
NUMBER_ALREADY_EXIST,
CLIENT_REQUIRED, CLIENT_CATEGORY_ALREADY_EXIST, CATEGORY_NOT_FOUND, PRODUCTS_NOT_FOUND, ORDER_NOT_FOUND, ACCESS_DENIED
CLIENT_REQUIRED, CLIENT_CATEGORY_ALREADY_EXIST, CATEGORY_NOT_FOUND, PRODUCTS_NOT_FOUND, ORDER_NOT_FOUND, ORDER_COMPLETED, ACCESS_DENIED
}
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 @@ -12,4 +12,6 @@ public interface OrderService {
ResponseEnum createOrder(ReqCreateOrder req);

Page<ResListOrder> getOrderList(Pageable pageable);

ResponseEnum readyToTakeOrder(String id);
}
22 changes: 20 additions & 2 deletions src/main/java/com/pos/app/service/impl/OrderServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.pos.app.service.impl;

import com.pos.app.controller.OrderController;
import com.pos.app.entities.Order;
import com.pos.app.entities.OrderProduct;
import com.pos.app.entities.Product;
Expand All @@ -26,7 +25,6 @@

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -147,6 +145,26 @@ public Page<ResListOrder> getOrderList(Pageable pageable) {
}
}

@Override
public ResponseEnum readyToTakeOrder(String id) {
Optional<Order> findOrder = orderRepository.findById(id);
if (findOrder.isEmpty()) {
throw new NotFoundException(ResponseEnum.ORDER_NOT_FOUND.name());
}
Order order = findOrder.get();
if (order.getStatus() != OrderStatusEnum.IN_PROGRESS) {
throw new BadRequestException(ResponseEnum.ORDER_COMPLETED.name());
}
order.setStatus(OrderStatusEnum.READY);
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 8d495a4

Please sign in to comment.