From 53b4df0743540f5467d313389fd215ec50ac5e06 Mon Sep 17 00:00:00 2001 From: toki-ai Date: Fri, 1 Nov 2024 03:44:20 +0700 Subject: [PATCH] [PBS-84][Anh Dao] fix: update amenity quatity --- .../PodBookingSystem/service/OrderDetailAmenityService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailAmenityService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailAmenityService.java index da36ab9a..85f9d29f 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailAmenityService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailAmenityService.java @@ -75,7 +75,11 @@ public void createOrderDetailAmenity(OrderDetailAmenityRequest request) { } public void updateAmenityQuantityAfterCreateODA(OrderDetailAmenity orderDetailAmenity) { - Amenity amenity = orderDetailAmenity.getAmenity(); + Optional amenityOptional = amenityRepository.findById(orderDetailAmenity.getAmenity().getId()); + if(amenityOptional.isEmpty()) { + throw new RuntimeException("Amenity not found"); + } + Amenity amenity = amenityOptional.get(); if(amenity.getQuantity() < orderDetailAmenity.getQuantity()) { throw new RuntimeException("Not enough quantity"); }