diff --git a/src/main/java/com/pos/app/service/impl/OrderServiceImpl.java b/src/main/java/com/pos/app/service/impl/OrderServiceImpl.java index fd3b99b..732d73f 100644 --- a/src/main/java/com/pos/app/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/pos/app/service/impl/OrderServiceImpl.java @@ -195,12 +195,26 @@ public ResponseIdQr generateQROrder() { @Override public ResponseEnum createOrderViaQr(String code, ReqCreateOrderViaQrCode req) { + Optional findQrCode = qrCodeRepository.findByCode(code); + if (findQrCode.isEmpty()) { throw new BadRequestException(ResponseEnum.REQUEST_INVALID.name()); } + + QrCode qrCode = findQrCode.get(); String clientId = qrCode.getClient().getId(); + + Optional checkOrder = orderRepository.findById(qrCode.getOrder().getId()); + if (checkOrder.isEmpty()) { + throw new NotFoundException(ResponseEnum.ORDER_NOT_FOUND.name()); + } + + if (!checkOrder.get().getStatus().equals(OrderStatusEnum.PENDING)) { + throw new BadRequestException(ResponseEnum.REQUEST_INVALID.name()); + } + Optional findOrder = orderRepository.findById(qrCode.getOrder().getId()); if (findOrder.isEmpty()) { throw new NotFoundException(ResponseEnum.ORDER_NOT_FOUND.name());