Package com.myfood.controllers
Class MenuController
java.lang.Object
com.myfood.controllers.MenuController
Controller class for handling menu-related operations.
This controller provides endpoints for basic CRUD operations on menus.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<?>
deleteMenu
(Long id) Delete a menu.org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<com.myfood.dto.Menu>>
getAllMenus
(int page, int size) Retrieve all menus.org.springframework.http.ResponseEntity<List<com.myfood.dto.Menu>>
Retrieves all visible menus.org.springframework.http.ResponseEntity<com.myfood.dto.Menu>
getOneMenu
(Long id) Retrieve a specific menu by its ID.org.springframework.http.ResponseEntity<com.myfood.dto.Menu>
saveMenu
(com.myfood.dto.Menu entity) Create a new menu.org.springframework.http.ResponseEntity<?>
Change the visibility status of a menu.org.springframework.http.ResponseEntity<com.myfood.dto.Menu>
updateMenu
(Long id, com.myfood.dto.Menu entity) Update an existing menu.
-
Constructor Details
-
MenuController
public MenuController()
-
-
Method Details
-
getAllMenus
@PreAuthorize("hasRole(\'ADMIN\')") @GetMapping("/menus") public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<com.myfood.dto.Menu>> getAllMenus(@RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size) Retrieve all menus.- Returns:
- ResponseEntity containing a list of all menus.
-
getAllVisibleMenus
@GetMapping("/allVisibleMenus") public org.springframework.http.ResponseEntity<List<com.myfood.dto.Menu>> getAllVisibleMenus()Retrieves all visible menus. This endpoint fetches all menus from the menu service and filters them based on visibility. Visible menus are determined by theisMenuVisible(Menu)
method. The filtered list is then returned in a ResponseEntity. If no visible menus are found, a 404 Not Found response is returned; otherwise, a 200 OK response with the list of visible menus is sent.- Returns:
- ResponseEntity<List
-
getOneMenu
@PreAuthorize("hasRole(\'ADMIN\')") @GetMapping("/menu/{id}") public org.springframework.http.ResponseEntity<com.myfood.dto.Menu> getOneMenu(@PathVariable(name="id") Long id) Retrieve a specific menu by its ID.- Parameters:
id
- The ID of the menu to retrieve.- Returns:
- ResponseEntity containing the requested menu or a 404 response if not found.
-
saveMenu
@PreAuthorize("hasRole(\'ADMIN\')") @PostMapping("/menu") public org.springframework.http.ResponseEntity<com.myfood.dto.Menu> saveMenu(@RequestBody com.myfood.dto.Menu entity) Create a new menu.- Parameters:
entity
- The menu to be created.- Returns:
- ResponseEntity containing the created menu.
-
updateMenu
@PreAuthorize("hasRole(\'ADMIN\')") @PutMapping("/menu/{id}") public org.springframework.http.ResponseEntity<com.myfood.dto.Menu> updateMenu(@PathVariable(name="id") Long id, @RequestBody com.myfood.dto.Menu entity) Update an existing menu.- Parameters:
id
- The ID of the menu to update.entity
- The updated menu.- Returns:
- ResponseEntity containing the updated menu or a 404 response if not found.
-
toggleMenuVisibility
@PreAuthorize("hasRole(\'ADMIN\')") @PutMapping("/menu/changeVisibility/{id}") public org.springframework.http.ResponseEntity<?> toggleMenuVisibility(@PathVariable(name="id") Long id) Change the visibility status of a menu.- Parameters:
id
- The ID of the menu to update.- Returns:
- ResponseEntity indicating success or a 404 response if the menu is not found.
-
deleteMenu
@PreAuthorize("hasRole(\'ADMIN\')") @DeleteMapping("/menu/{id}") public org.springframework.http.ResponseEntity<?> deleteMenu(@PathVariable(name="id") Long id) Delete a menu.- Parameters:
id
- The ID of the menu to delete.- Returns:
- ResponseEntity indicating success or a 404 response if the menu is not found.
-