-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NguyenHCP] fix: error OrderDetailAmenity Entity
- Loading branch information
1 parent
014cb64
commit f738452
Showing
6 changed files
with
252 additions
and
237 deletions.
There are no files selected for viewing
115 changes: 66 additions & 49 deletions
115
src/main/java/com/swp/PodBookingSystem/controller/OrderDetailController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<List<OrderDetailResponse>> getAllOrders() { | ||
try{ | ||
List<OrderDetailResponse> orders = orderDetailService.getAllOrders(); | ||
logOrders(orders); | ||
return ApiResponse.<List<OrderDetailResponse>>builder() | ||
.data(orders) | ||
.build(); | ||
} | ||
catch (Exception e){ | ||
log.error("Error creating order detail: ", e); | ||
return ApiResponse.<List<OrderDetailResponse>>builder() | ||
.message("Failed to create order detail: " + e.getMessage()) | ||
.code(HttpStatus.INTERNAL_SERVER_ERROR.value()) | ||
.build(); | ||
} | ||
} | ||
|
||
@GetMapping("/{customerId}") | ||
public ApiResponse<List<OrderDetailResponse>> getOrdersByCustomerId(@PathVariable String customerId) { | ||
List<OrderDetailResponse> orders = orderDetailService.getOrdersByCustomerId(customerId); | ||
@GetMapping | ||
public ApiResponse<List<OrderDetailResponse>> getAllOrders() { | ||
try { | ||
List<OrderDetailResponse> orders = orderDetailService.getAllOrders(); | ||
logOrders(orders); | ||
return ApiResponse.<List<OrderDetailResponse>>builder() | ||
.data(orders) | ||
.build(); | ||
} catch (Exception e) { | ||
log.error("Error creating order detail: ", e); | ||
return ApiResponse.<List<OrderDetailResponse>>builder() | ||
.message("Failed to create order detail: " + e.getMessage()) | ||
.code(HttpStatus.INTERNAL_SERVER_ERROR.value()) | ||
.build(); | ||
} | ||
} | ||
|
||
@GetMapping("/{customerId}") | ||
public ApiResponse<List<OrderDetailResponse>> getOrdersByCustomerId(@PathVariable String customerId) { | ||
List<OrderDetailResponse> orders = orderDetailService.getOrdersByCustomerId(customerId); | ||
logOrders(orders); | ||
return ApiResponse.<List<OrderDetailResponse>>builder() | ||
.data(orders) | ||
.build(); | ||
} | ||
|
||
// @GetMapping("/order-amenity/{orderDetailId}") | ||
// public ApiResponse<List<AmenityManagementResponse>> getAmenitiesByOrdersByCustomerId(@PathVariable String orderDetailId) { | ||
// List<AmenityManagementResponse> orders = orderDetailAmenityService.getOrderDetailAmenitiesByOrderDetailId(orderDetailId); | ||
// return ApiResponse.<List<AmenityManagementResponse>>builder() | ||
// .data(orders) | ||
// .build(); | ||
// } | ||
|
||
// @GetMapping("/order-amenitysAll") | ||
// public ApiResponse<List<OrderDetailAmenity>> getAll() { | ||
// List<OrderDetailAmenity> orders = orderDetailAmenityService.getAll(); | ||
// return ApiResponse.<List<OrderDetailAmenity>>builder() | ||
// .data(orders) | ||
// .build(); | ||
// } | ||
|
||
|
||
private void logOrders(List<OrderDetailResponse> 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<OrderDetailResponse> 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())); | ||
} | ||
|
||
} | ||
} |
30 changes: 17 additions & 13 deletions
30
src/main/java/com/swp/PodBookingSystem/dto/respone/OrderDetail/OrderDetailResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,33 @@ | ||
|
||
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 | ||
@AllArgsConstructor | ||
@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<AmenityManagementResponse> amenities; | ||
int servicePackageId; | ||
String orderHandledId; | ||
double priceRoom; | ||
OrderStatus status; | ||
LocalDateTime startTime; | ||
LocalDateTime endTime; | ||
LocalDateTime createdAt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.