Class MenuController

java.lang.Object
com.myfood.controllers.MenuController

@RestController @RequestMapping("api/v1") public class MenuController extends Object
Controller class for handling menu-related operations. This controller provides endpoints for basic CRUD operations on menus.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<?>
    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>
    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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 the isMenuVisible(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> A response entity containing the list of visible menus if they exist, or a 404 Not Found response if no visible menus are available.
    • 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.