Package com.myfood.controllers
Class OrderController
java.lang.Object
com.myfood.controllers.OrderController
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<?>
deleteOrder
(Long id) Deletes an existing order based on the provided order ID.org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<com.myfood.dto.OrderUserDTO>>
getAllOrders
(int page, int size) Retrieves a paginated list of user orders.org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<com.myfood.dto.OrderCookDTO>>
getAllOrdersForChef
(int page, int size) Retrieves a paginated list of orders suitable for a cook, including associated dishes.org.springframework.http.ResponseEntity<?>
getAllOrdersForUserPaginate
(int page, int size, Long userId) Retrieves a paginated list of orders for a specific user.org.springframework.http.ResponseEntity<?>
getOneOrder
(Long id) Retrieves details of a specific order identified by its ID.org.springframework.http.ResponseEntity<?>
getOrdersByDatePaginate
(int page, int size, Integer year, Integer month, Integer day) Retrieves a paginated list of orders based on the specified date parameters.org.springframework.http.ResponseEntity<?>
markOrderAsMaked
(Long id) Marks an order as "maked" (fulfilled) based on the provided order ID.org.springframework.http.ResponseEntity<com.myfood.dto.OrderUserDTO>
saveOrder
(com.myfood.dto.Order entity) Creates a new order based on the provided order details.org.springframework.http.ResponseEntity<?>
Creates and saves a new order for the specified user.org.springframework.http.ResponseEntity<?>
updateOrder
(Long id, com.myfood.dto.Order entity) Updates an existing order with the provided order details.org.springframework.http.ResponseEntity<?>
updateOrderSlot
(Long orderId, Long slotId) Updates the slot of an order and confirms it, setting the actual date.
-
Constructor Details
-
OrderController
public OrderController()
-
-
Method Details
-
getAllOrders
@PreAuthorize("hasRole(\'ADMIN\')") @GetMapping("/orders") public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<com.myfood.dto.OrderUserDTO>> getAllOrders(@RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size) Retrieves a paginated list of user orders. It's for the ADMIN- Parameters:
page
- The page number (default is 0).size
- The number of orders per page (default is 10).- Returns:
- ResponseEntity containing a paginated list of
OrderUserDTO
. - See Also:
-
OrderService#getAllOrdersWithPagination(Pageable)
-
getOneOrder
@PreAuthorize("hasRole(\'ADMIN\')") @GetMapping("/order/{id}") public org.springframework.http.ResponseEntity<?> getOneOrder(@PathVariable(name="id") Long id) Retrieves details of a specific order identified by its ID. It's for the ADMIN- Parameters:
id
- The unique identifier of the order.- Returns:
- ResponseEntity containing the details of the order as an
OrderUserDTO
. - Throws:
DataNotFoundException
- If the specified order does not exist.- See Also:
-
OrderService#getOneOrder(Long)
-
saveOrder
@PreAuthorize("hasRole(\'ADMIN\')") @PostMapping("/order") public org.springframework.http.ResponseEntity<com.myfood.dto.OrderUserDTO> saveOrder(@RequestBody com.myfood.dto.Order entity) Creates a new order based on the provided order details. It's for the ADMIN- Parameters:
entity
- The order details provided in the request body.- Returns:
- ResponseEntity containing the details of the created order as an
OrderUserDTO
.OrderUserDTO
and returned in the ResponseEntity with status 200 (OK). - See Also:
-
OrderService#createOrder(Order)
-
updateOrder
@PreAuthorize("hasRole(\'ADMIN\')") @PutMapping("/order/{id}") public org.springframework.http.ResponseEntity<?> updateOrder(@PathVariable(name="id") Long id, @RequestBody com.myfood.dto.Order entity) Updates an existing order with the provided order details. It's for ADMIN- Parameters:
id
- The identifier of the order to be updated.entity
- The updated order details provided in the request body.- Returns:
- ResponseEntity containing a message and the details of the updated
order as an
OrderUserDTO
. - See Also:
-
OrderService#getOneOrder(Long)
OrderService#updateOrder(Long, Order)
-
deleteOrder
@PreAuthorize("hasRole(\'ADMIN\')") @DeleteMapping("/order/{id}") public org.springframework.http.ResponseEntity<?> deleteOrder(@PathVariable(name="id") Long id) Deletes an existing order based on the provided order ID. It's for ADMIN- Parameters:
id
- The identifier of the order to be deleted.- Returns:
- ResponseEntity indicating the success or failure of the delete operation.
- See Also:
-
OrderService#getOneOrder(Long)
OrderService#deleteOrder(Long)
-
getAllOrdersForChef
@PreAuthorize("hasRole(\'CHEF\') or hasRole(\'ADMIN\')") @GetMapping("/orders/chef") public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<com.myfood.dto.OrderCookDTO>> getAllOrdersForChef(@RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="8") int size) Retrieves a paginated list of orders suitable for a cook, including associated dishes. It's for CHEF- Parameters:
page
- The page number for pagination (default is 0).size
- The number of orders per page (default is 8).- Returns:
- ResponseEntity containing a paginated list of OrderCookDTO objects.
- See Also:
-
OrderService#getAllOrdersForCook()
OrderController#mapToOrderCookDTO(Order)
paginate(List, Pageable)
OrderCookDTO
-
getAllOrdersForUserPaginate
@GetMapping("/orders/{userId}") public org.springframework.http.ResponseEntity<?> getAllOrdersForUserPaginate(@RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size, @PathVariable(name="userId") Long userId) Retrieves a paginated list of orders for a specific user. It's for the history for USER- Parameters:
page
- The page number for pagination (default is 0).size
- The number of orders per page (default is 10).userId
- The ID of the user for whom to retrieve orders.- Returns:
- ResponseEntity containing a paginated list of OrderUserDTO objects.
- See Also:
-
UserService#getOneUser(Long)
OrderService#getAllOrdersForUserId(Long)
OrderUserDTO
-
markOrderAsMaked
@PreAuthorize("hasRole(\'CHEF\') or hasRole(\'ADMIN\')") @PutMapping("/order/markAsMaked/{id}") public org.springframework.http.ResponseEntity<?> markOrderAsMaked(@PathVariable(name="id") Long id) Marks an order as "maked" (fulfilled) based on the provided order ID. It's for CHEFF- Parameters:
id
- The ID of the order to be marked as "maked."- Returns:
- ResponseEntity containing the updated OrderUserDTO after marking the order as "maked."
- See Also:
-
OrderService#getOneOrder(Long)
OrderService#updateOrder(Order)
OrderUserDTO
-
updateOrderSlot
@PutMapping("/order/finish/{orderId}/{slotId}") public org.springframework.http.ResponseEntity<?> updateOrderSlot(@PathVariable(name="orderId") Long orderId, @PathVariable(name="slotId") Long slotId) Updates the slot of an order and confirms it, setting the actual date. Also, calculates and sets the total price of the order. It's for USER- Parameters:
orderId
- The ID of the order to be updated.slotId
- The ID of the slot to be associated with the order.- Returns:
- ResponseEntity containing the updated OrderUserDTO after updating the order slot and confirming it.
- See Also:
-
OrderService#getOneOrder(Long)
SlotService#getOneSlot(Long)
OrderService#updateOrder(Order)
SlotService#updateSlot(Slot)
calculateTotalPrice(Order)
OrderUserDTO
-
saveOrder
@PostMapping("/order/{userId}") public org.springframework.http.ResponseEntity<?> saveOrder(@PathVariable(name="userId") Long userId) Creates and saves a new order for the specified user. It's for the USER- Parameters:
userId
- The ID of the user for whom the order is created.- Returns:
- ResponseEntity containing the OrderUserDTO representing the newly created order.
- See Also:
-
UserService#getOneUser(Long)
OrderService#createOrder(Order)
OrderUserDTO
-
getOrdersByDatePaginate
@PreAuthorize("hasRole(\'ADMIN\')") @GetMapping("/orders/date") public org.springframework.http.ResponseEntity<?> getOrdersByDatePaginate(@RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size, @RequestParam(name="year",required=false) Integer year, @RequestParam(name="month",required=false) Integer month, @RequestParam(name="day",required=false) Integer day) Retrieves a paginated list of orders based on the specified date parameters. It's for the ADMIN- Parameters:
page
- Page number (default is 0).size
- Number of items per page (default is 10).year
- The year to filter orders by (optional).month
- The month to filter orders by (optional).day
- The day to filter orders by (optional).- Returns:
- A ResponseEntity containing a paginated list of OrderUserDTO objects or an error message.
-