From f7384529ad95e9938f4ae664a974f99fb23a32af Mon Sep 17 00:00:00 2001 From: Huynh Nguyen Date: Tue, 15 Oct 2024 23:01:05 +0700 Subject: [PATCH] [NguyenHCP] fix: error OrderDetailAmenity Entity --- .../controller/OrderDetailController.java | 115 +++--- .../OrderDetail/OrderDetailResponse.java | 30 +- .../entity/OrderDetailAmenity.java | 7 +- .../mapper/OrderDetailMapper.java | 4 +- .../service/OrderDetailAmenityService.java | 4 + .../service/OrderDetailService.java | 329 +++++++++--------- 6 files changed, 252 insertions(+), 237 deletions(-) diff --git a/src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java b/src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java index 5d936f84..a12ffd3a 100644 --- a/src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java +++ b/src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java @@ -1,66 +1,83 @@ - package com.swp.PodBookingSystem.controller; +package com.swp.PodBookingSystem.controller; - import com.swp.PodBookingSystem.dto.respone.OrderDetail.OrderDetailResponse; - import com.swp.PodBookingSystem.service.OrderDetailService; - import lombok.AccessLevel; - import lombok.RequiredArgsConstructor; - import lombok.experimental.FieldDefaults; - import lombok.extern.slf4j.Slf4j; - import org.springframework.beans.factory.annotation.Autowired; - import com.swp.PodBookingSystem.dto.respone.ApiResponse; +import com.swp.PodBookingSystem.dto.respone.Amenity.AmenityManagementResponse; +import com.swp.PodBookingSystem.dto.respone.OrderDetail.OrderDetailResponse; +import com.swp.PodBookingSystem.entity.OrderDetailAmenity; +import com.swp.PodBookingSystem.service.OrderDetailAmenityService; +import com.swp.PodBookingSystem.service.OrderDetailService; +import lombok.AccessLevel; +import lombok.RequiredArgsConstructor; +import lombok.experimental.FieldDefaults; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import com.swp.PodBookingSystem.dto.respone.ApiResponse; - import org.springframework.http.HttpStatus; - import org.springframework.security.core.context.SecurityContextHolder; - import org.springframework.web.bind.annotation.*; +import org.springframework.http.HttpStatus; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.bind.annotation.*; - import java.util.*; +import java.util.*; - @RestController - @RequestMapping("/order-detail") - @RequiredArgsConstructor - @FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) - @Slf4j - public class OrderDetailController { +@RestController +@RequestMapping("/order-detail") +@RequiredArgsConstructor +@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) +@Slf4j +public class OrderDetailController { - @Autowired - private OrderDetailService orderDetailService; + @Autowired + private OrderDetailService orderDetailService; + @Autowired + private OrderDetailAmenityService orderDetailAmenityService; - @GetMapping - public ApiResponse> getAllOrders() { - try{ - List orders = orderDetailService.getAllOrders(); - logOrders(orders); - return ApiResponse.>builder() - .data(orders) - .build(); - } - catch (Exception e){ - log.error("Error creating order detail: ", e); - return ApiResponse.>builder() - .message("Failed to create order detail: " + e.getMessage()) - .code(HttpStatus.INTERNAL_SERVER_ERROR.value()) - .build(); - } - } - - @GetMapping("/{customerId}") - public ApiResponse> getOrdersByCustomerId(@PathVariable String customerId) { - List orders = orderDetailService.getOrdersByCustomerId(customerId); + @GetMapping + public ApiResponse> getAllOrders() { + try { + List orders = orderDetailService.getAllOrders(); logOrders(orders); return ApiResponse.>builder() .data(orders) .build(); + } catch (Exception e) { + log.error("Error creating order detail: ", e); + return ApiResponse.>builder() + .message("Failed to create order detail: " + e.getMessage()) + .code(HttpStatus.INTERNAL_SERVER_ERROR.value()) + .build(); } + } + @GetMapping("/{customerId}") + public ApiResponse> getOrdersByCustomerId(@PathVariable String customerId) { + List orders = orderDetailService.getOrdersByCustomerId(customerId); + logOrders(orders); + return ApiResponse.>builder() + .data(orders) + .build(); + } +// @GetMapping("/order-amenity/{orderDetailId}") +// public ApiResponse> getAmenitiesByOrdersByCustomerId(@PathVariable String orderDetailId) { +// List orders = orderDetailAmenityService.getOrderDetailAmenitiesByOrderDetailId(orderDetailId); +// return ApiResponse.>builder() +// .data(orders) +// .build(); +// } +// @GetMapping("/order-amenitysAll") +// public ApiResponse> getAll() { +// List orders = orderDetailAmenityService.getAll(); +// return ApiResponse.>builder() +// .data(orders) +// .build(); +// } - private void logOrders(List orders) { - var authentication = SecurityContextHolder.getContext().getAuthentication(); - log.info("Username: {}", authentication.getName()); - log.info("Number of orders retrieved: {}", orders.size()); - orders.forEach(order -> log.info("Order ID: {}, Customer ID: {}", order.getId(), order.getCustomerId())); - } + private void logOrders(List orders) { + var authentication = SecurityContextHolder.getContext().getAuthentication(); + log.info("Username: {}", authentication.getName()); + log.info("Number of orders retrieved: {}", orders.size()); + orders.forEach(order -> log.info("Order ID: {}, Customer ID: {}", order.getId(), order.getCustomerId())); + } - } \ No newline at end of file +} \ No newline at end of file diff --git a/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailResponse.java b/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailResponse.java index f217c6f4..b1d641d5 100644 --- a/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailResponse.java +++ b/src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailResponse.java @@ -1,11 +1,14 @@ package com.swp.PodBookingSystem.dto.respone.OrderDetail; +import com.swp.PodBookingSystem.dto.respone.Amenity.AmenityManagementResponse; +import com.swp.PodBookingSystem.dto.respone.AmenityResponse; import com.swp.PodBookingSystem.enums.OrderStatus; import lombok.*; import lombok.experimental.FieldDefaults; import java.time.LocalDateTime; +import java.util.List; @Data @NoArgsConstructor @@ -13,17 +16,18 @@ @Builder @FieldDefaults(level = AccessLevel.PRIVATE) public class OrderDetailResponse { - private String id; - private String customerId; - private int buildingId; - private int roomId; - private String orderId; - private int servicePackageId; - private String orderHandledId; - private double priceRoom; - private OrderStatus status; - private LocalDateTime startTime; - private LocalDateTime endTime; - private LocalDateTime createdAt; - + String id; + String customerId; + int buildingId; + int roomId; + String roomName; + String orderId; + List amenities; + int servicePackageId; + String orderHandledId; + double priceRoom; + OrderStatus status; + LocalDateTime startTime; + LocalDateTime endTime; + LocalDateTime createdAt; } diff --git a/src/main/java/com/swp/PodBookingSystem/entity/OrderDetailAmenity.java b/src/main/java/com/swp/PodBookingSystem/entity/OrderDetailAmenity.java index 0d640f60..7f569861 100644 --- a/src/main/java/com/swp/PodBookingSystem/entity/OrderDetailAmenity.java +++ b/src/main/java/com/swp/PodBookingSystem/entity/OrderDetailAmenity.java @@ -1,5 +1,6 @@ package com.swp.PodBookingSystem.entity; +import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import lombok.*; import lombok.experimental.FieldDefaults; @@ -11,7 +12,7 @@ @AllArgsConstructor @FieldDefaults(level = AccessLevel.PRIVATE) @Entity -@Table(name = "orderDetailAmentity") +@Table(name = "orderDetailAmenity") public class OrderDetailAmenity { @Id @GeneratedValue(strategy = GenerationType.UUID) @@ -22,10 +23,12 @@ public class OrderDetailAmenity { double price; @ManyToOne + @JsonIgnore @JoinColumn(name = "orderDetailId", nullable = false) OrderDetail orderDetail; @ManyToOne - @JoinColumn(name = "amentityId", nullable = false) + @JsonIgnore + @JoinColumn(name = "amenityId", nullable = false) Amenity amenity; } diff --git a/src/main/java/com/swp/PodBookingSystem/mapper/OrderDetailMapper.java b/src/main/java/com/swp/PodBookingSystem/mapper/OrderDetailMapper.java index 433156ce..7a458859 100644 --- a/src/main/java/com/swp/PodBookingSystem/mapper/OrderDetailMapper.java +++ b/src/main/java/com/swp/PodBookingSystem/mapper/OrderDetailMapper.java @@ -13,7 +13,9 @@ public interface OrderDetailMapper { @Mapping(target = "roomId", source = "room.id") // Map room ID to response @Mapping(target = "servicePackageId", source = "servicePackage.id") // Map service package ID to response @Mapping(target = "orderId", source = "order.id") // Map order ID to response - @Mapping(target = "orderHandledId", source = "orderHandler.id") // Map order handled ID to response + @Mapping(target = "orderHandledId", source = "orderHandler.id") + @Mapping(target = "roomName", source = "room.name") + // Map order handled ID to response OrderDetailResponse toOrderDetailResponse(OrderDetail orderDetail); } diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailAmenityService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailAmenityService.java index 39aed0a1..b05cd71d 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailAmenityService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailAmenityService.java @@ -19,6 +19,10 @@ public class OrderDetailAmenityService { // return orderDetailAmenityRepository.findByOrderDetailId(orderDetailId); // } + public List getAll() { + return orderDetailAmenityRepository.findAll(); + } + public List getOrderDetailAmenitiesByOrderDetailId(String orderDetailId) { return orderDetailAmenityRepository.findByOrderDetailId(orderDetailId).stream().map(amenity -> { return AmenityManagementResponse.builder() diff --git a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java index 415843d7..64562660 100644 --- a/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java +++ b/src/main/java/com/swp/PodBookingSystem/service/OrderDetailService.java @@ -1,200 +1,185 @@ - package com.swp.PodBookingSystem.service; - - import com.swp.PodBookingSystem.dto.request.OrderDetail.OrderDetailCreationRequest; - import com.swp.PodBookingSystem.dto.respone.Amenity.AmenityManagementResponse; - import com.swp.PodBookingSystem.dto.respone.OrderDetail.OrderDetailManagementResponse; - import com.swp.PodBookingSystem.dto.respone.OrderDetail.OrderDetailResponse; - import com.swp.PodBookingSystem.entity.*; - import com.swp.PodBookingSystem.enums.OrderStatus; - import com.swp.PodBookingSystem.mapper.OrderDetailMapper; - import com.swp.PodBookingSystem.repository.*; - import org.slf4j.Logger; - import org.slf4j.LoggerFactory; - import org.springframework.beans.factory.annotation.Autowired; - import org.springframework.stereotype.Service; - import org.springframework.transaction.annotation.Transactional; - - import java.time.LocalDate; - import java.time.LocalDateTime; - import java.time.LocalTime; - import java.util.List; - import java.util.UUID; - import java.util.stream.Collectors; - - @Service - public class OrderDetailService { - - @Autowired - private OrderDetailRepository orderDetailRepository; - - @Autowired - private AccountRepository accountRepository; - - @Autowired - private BuildingRepository buildingRepository; - - @Autowired - private RoomRepository roomRepository; - - @Autowired - private ServicePackageRepository servicePackageRepository; - - @Autowired - private OrderRepository orderRepository; - - @Autowired - private OrderDetailMapper orderDetailMapper; - - @Autowired - private OrderDetailAmenityService orderDetailAmenityService; - - private static final Logger log = LoggerFactory.getLogger(OrderService.class); - @Autowired - private AccountService accountService; - @Autowired - private ServicePackageService servicePackageService; - - - public List getAllOrders() { - List orders = orderDetailRepository.findAll(); - return orders.stream() - .map(orderDetailMapper::toOrderDetailResponse) - .collect(Collectors.toList()); - } +package com.swp.PodBookingSystem.service; + +import com.swp.PodBookingSystem.dto.request.OrderDetail.OrderDetailCreationRequest; +import com.swp.PodBookingSystem.dto.respone.Amenity.AmenityManagementResponse; +import com.swp.PodBookingSystem.dto.respone.OrderDetail.OrderDetailManagementResponse; +import com.swp.PodBookingSystem.dto.respone.OrderDetail.OrderDetailResponse; +import com.swp.PodBookingSystem.entity.*; +import com.swp.PodBookingSystem.enums.OrderStatus; +import com.swp.PodBookingSystem.mapper.OrderDetailMapper; +import com.swp.PodBookingSystem.repository.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +@Service +public class OrderDetailService { + + @Autowired + private OrderDetailRepository orderDetailRepository; + + @Autowired + private AccountRepository accountRepository; + + @Autowired + private BuildingRepository buildingRepository; + + @Autowired + private RoomRepository roomRepository; + + @Autowired + private ServicePackageRepository servicePackageRepository; + + @Autowired + private OrderRepository orderRepository; + + @Autowired + private OrderDetailMapper orderDetailMapper; + + @Autowired + private OrderDetailAmenityService orderDetailAmenityService; + + private static final Logger log = LoggerFactory.getLogger(OrderService.class); + @Autowired + private AccountService accountService; + @Autowired + private ServicePackageService servicePackageService; + + + public List getAllOrders() { + List orders = orderDetailRepository.findAll(); + return orders.stream() + .map(orderDetailMapper::toOrderDetailResponse) + .collect(Collectors.toList()); + } - public List getOrdersByOrderId(String orderId) { - return orderDetailRepository.findByOrderId(orderId); - } + public List getOrdersByOrderId(String orderId) { + return orderDetailRepository.findByOrderId(orderId); + } - public List getOrderDetailById(String orderId) { - return orderDetailRepository.findByOrderId(orderId).stream().map(orderDetail -> { - List amenities = orderDetailAmenityService.getOrderDetailAmenitiesByOrderDetailId(orderDetail.getId()); - return OrderDetailManagementResponse.builder() - .id(orderDetail.getId()) - .roomId(orderDetail.getRoom().getId()) - .roomName(orderDetail.getRoom().getName()) - .roomPrice(orderDetail.getPriceRoom()) - .buildingAddress(orderDetail.getBuilding().getAddress()) - .buildingId(orderDetail.getBuilding().getId()) - .roomId(orderDetail.getRoom().getId()) - .orderHandler(accountService.toAccountResponse(orderDetail.getOrderHandler())) - .customer(accountService.toAccountResponse(orderDetail.getCustomer())) - .servicePackage(servicePackageService.toServicePackageResponse(orderDetail.getServicePackage())) - .status(orderDetail.getStatus().name()) - .startTime(orderDetail.getStartTime()) - .endTime(orderDetail.getEndTime()) - .amenities(amenities) - .build(); - }).collect(Collectors.toList()); - } + public List getOrderDetailById(String orderId) { + return orderDetailRepository.findByOrderId(orderId).stream().map(orderDetail -> { + List amenities = orderDetailAmenityService.getOrderDetailAmenitiesByOrderDetailId(orderDetail.getId()); + return OrderDetailManagementResponse.builder() + .id(orderDetail.getId()) + .roomId(orderDetail.getRoom().getId()) + .roomName(orderDetail.getRoom().getName()) + .roomPrice(orderDetail.getPriceRoom()) + .buildingAddress(orderDetail.getBuilding().getAddress()) + .buildingId(orderDetail.getBuilding().getId()) + .roomId(orderDetail.getRoom().getId()) + .orderHandler(accountService.toAccountResponse(orderDetail.getOrderHandler())) + .customer(accountService.toAccountResponse(orderDetail.getCustomer())) + .servicePackage(servicePackageService.toServicePackageResponse(orderDetail.getServicePackage())) + .status(orderDetail.getStatus().name()) + .startTime(orderDetail.getStartTime()) + .endTime(orderDetail.getEndTime()) + .amenities(amenities) + .build(); + }).collect(Collectors.toList()); + } - public List getOrdersByCustomerId(String customerId) { - List orderDetails = orderDetailRepository.findByCustomer_Id(customerId); - - System.out.println("Orders found for customer " + customerId + ": " + orderDetails.size()); - for (OrderDetail orderDetail : orderDetails) { - System.out.println("Order Detail ID: " + orderDetail.getId()); - System.out.println("Created At: " + orderDetail.getCreatedAt()); - System.out.println("Discount Percentage: " + orderDetail.getDiscountPercentage()); - System.out.println("End Time: " + orderDetail.getEndTime()); - System.out.println("Price Room: " + orderDetail.getPriceRoom()); - System.out.println("Start Time: " + orderDetail.getStartTime()); - System.out.println("Status: " + orderDetail.getStatus()); - System.out.println("Updated At: " + orderDetail.getUpdatedAt()); - System.out.println("Building Number: " + orderDetail.getBuilding().getId()); - System.out.println("Customer ID: " + orderDetail.getCustomerId()); - System.out.println("Order ID: " + orderDetail.getOrder().getId()); - System.out.println("Order Handler ID: " + orderDetail.getOrderHandler().getId()); - System.out.println("Room ID: " + orderDetail.getRoom().getId()); - System.out.println("Service Package ID: " + orderDetail.getServicePackage().getId()); - System.out.println("-------------------------------"); // Separator for better readability - } + public List getOrdersByCustomerId(String customerId) { + List orderDetails = orderDetailRepository.findByCustomer_Id(customerId); - return orderDetails.stream() - .map(orderDetailMapper::toOrderDetailResponse) // Use the mapper for conversion - .collect(Collectors.toList()); + System.out.println("Orders found for customer " + customerId + ": " + orderDetails.size()); + var orderDetailResponses = orderDetails.stream() + .map(orderDetailMapper::toOrderDetailResponse) // Use the mapper for conversion + .toList(); + for (OrderDetailResponse orderDetail : orderDetailResponses) { + System.out.println("Order Detail: " + orderDetailAmenityService.getOrderDetailAmenitiesByOrderDetailId(orderDetail.getOrderId())); + orderDetail.setAmenities(orderDetailAmenityService.getOrderDetailAmenitiesByOrderDetailId(orderDetail.getId())); } + return orderDetailResponses; + } - public OrderDetailResponse createOrderDetail(OrderDetailCreationRequest request, Order order, Room room, OrderStatus status, Account account, LocalDateTime startTime, LocalDateTime endTime) { - try { - - - // Step 1: Create a new OrderDetail entity - OrderDetail response = new OrderDetail(); - response.setCustomer(account); + public OrderDetailResponse createOrderDetail(OrderDetailCreationRequest request, Order order, Room room, OrderStatus status, Account account, LocalDateTime startTime, LocalDateTime endTime) { + try { - response.setId(UUID.randomUUID().toString()); + // Step 1: Create a new OrderDetail entity + OrderDetail response = new OrderDetail(); + response.setCustomer(account); - response.setOrder(order); - // Set building - Building building = buildingRepository.findById(request.getBuilding().getId()) - .orElseThrow(() -> new IllegalArgumentException("Building not found")); - response.setBuilding(building); - // Set selected room (assuming only one room is selected here for simplicity) - if (room != null) { - response.setRoom(room); - } + response.setId(UUID.randomUUID().toString()); - // Set service package - ServicePackage servicePackage = servicePackageRepository.findById(request.getServicePackage().getId()) - .orElseThrow(() -> new IllegalArgumentException("Service package not found")); - response.setServicePackage(servicePackage); + response.setOrder(order); + // Set building + Building building = buildingRepository.findById(request.getBuilding().getId()) + .orElseThrow(() -> new IllegalArgumentException("Building not found")); + response.setBuilding(building); - // Set order handler - if (request.getOrderHandler() != null) { - Account orderHandler = accountRepository.findById(request.getOrderHandler().getId()) - .orElseThrow(() -> new IllegalArgumentException("Order handler not found")); - response.setOrderHandler(orderHandler); - } + // Set selected room (assuming only one room is selected here for simplicity) + if (room != null) { + response.setRoom(room); + } + // Set service package + ServicePackage servicePackage = servicePackageRepository.findById(request.getServicePackage().getId()) + .orElseThrow(() -> new IllegalArgumentException("Service package not found")); + response.setServicePackage(servicePackage); + // Set order handler + if (request.getOrderHandler() != null) { + Account orderHandler = accountRepository.findById(request.getOrderHandler().getId()) + .orElseThrow(() -> new IllegalArgumentException("Order handler not found")); + response.setOrderHandler(orderHandler); + } - // Set other fields - response.setPriceRoom(request.getPriceRoom()); - response.setDiscountPercentage(request.getDiscountPercentage()); - response.setStartTime(startTime); - response.setEndTime(endTime); - response.setCreatedAt(LocalDateTime.now()); - response.setUpdatedAt(LocalDateTime.now()); - response.setStatus(status); + // Set other fields + response.setPriceRoom(request.getPriceRoom()); + response.setDiscountPercentage(request.getDiscountPercentage()); + response.setStartTime(startTime); + response.setEndTime(endTime); + response.setCreatedAt(LocalDateTime.now()); + response.setUpdatedAt(LocalDateTime.now()); + response.setStatus(status); - // Save the OrderDetail and return response - return orderDetailMapper.toOrderDetailResponse(orderDetailRepository.save(response)); + // Save the OrderDetail and return response + return orderDetailMapper.toOrderDetailResponse(orderDetailRepository.save(response)); - } catch (IllegalArgumentException e) { - // Handle specific validation errors - log.error("Validation error creating order detail: {}", e.getMessage()); - throw e; - } catch (Exception e) { - // Handle general exceptions - log.error("Unexpected error creating order detail", e); - throw new RuntimeException("Failed to create order detail: " + e.getMessage(), e); - } + } catch (IllegalArgumentException e) { + // Handle specific validation errors + log.error("Validation error creating order detail: {}", e.getMessage()); + throw e; + } catch (Exception e) { + // Handle general exceptions + log.error("Unexpected error creating order detail", e); + throw new RuntimeException("Failed to create order detail: " + e.getMessage(), e); } + } - public List getNextDayBookings(LocalDate dayNow){ - // Calculate the start of the next day (00:00:00) - LocalDateTime startOfDay = dayNow.plusDays(1).atStartOfDay(); + public List getNextDayBookings(LocalDate dayNow) { + // Calculate the start of the next day (00:00:00) + LocalDateTime startOfDay = dayNow.plusDays(1).atStartOfDay(); - // Calculate the end of the next day (23:59:59.999) - LocalDateTime endOfDay = dayNow.plusDays(1).atTime(LocalTime.MAX); + // Calculate the end of the next day (23:59:59.999) + LocalDateTime endOfDay = dayNow.plusDays(1).atTime(LocalTime.MAX); - // Fetch all bookings between start and end of tomorrow - return orderDetailRepository.findAllOrderDetailsByDay(startOfDay, endOfDay); - } + // Fetch all bookings between start and end of tomorrow + return orderDetailRepository.findAllOrderDetailsByDay(startOfDay, endOfDay); + } - @Transactional - public void deleteOrderDetailsByOrderId(String orderId) { - List orderDetails = orderDetailRepository.findByOrderId(orderId); - for (OrderDetail orderDetail : orderDetails) { - orderDetailAmenityService.deleteOrderDetailAmenityByOrderDetailId(orderDetail.getId()); - } - orderDetailRepository.deleteByOrderId(orderId); + @Transactional + public void deleteOrderDetailsByOrderId(String orderId) { + List orderDetails = orderDetailRepository.findByOrderId(orderId); + for (OrderDetail orderDetail : orderDetails) { + orderDetailAmenityService.deleteOrderDetailAmenityByOrderDetailId(orderDetail.getId()); } + orderDetailRepository.deleteByOrderId(orderId); } +}