Class DishController

java.lang.Object
com.myfood.controllers.DishController

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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<?>
    Change the visibility status of a dish.
    org.springframework.http.ResponseEntity<?>
    Delete a dish.
    org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<com.myfood.dto.Dish>>
    getAllDishes(int page, int size)
    Retrieve all dishes.
    org.springframework.http.ResponseEntity<List<com.myfood.dto.Dish>>
    Retrieve dishes by name, considering case-insensitive matching.
    org.springframework.http.ResponseEntity<List<com.myfood.dto.Dish>>
    Retrieve visible dishes by name, considering case-insensitive matching.
    org.springframework.http.ResponseEntity<?>
    getDishesByCategory(String category, int page, int size)
    Retrieve dishes by category.
    org.springframework.http.ResponseEntity<com.myfood.dto.Dish>
    Retrieve a specific dish by its ID.
    org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<com.myfood.dto.Dish>>
    getVisibleDishes(int page, int size)
     
    org.springframework.http.ResponseEntity<?>
    getVisibleDishesByCategory(String category, int page, int size)
    Retrieve visible dishes by category.
    org.springframework.http.ResponseEntity<?>
    saveDish(com.myfood.dto.Dish entity)
    Create a new dish.
    org.springframework.http.ResponseEntity<?>
    updateDish(Long id, com.myfood.dto.Dish entity)
    Update an existing dish.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DishController

      public DishController()
  • Method Details

    • getAllDishes

      @PreAuthorize("hasRole(\'ADMIN\')") @GetMapping("/dishes") public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<com.myfood.dto.Dish>> getAllDishes(@RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size)
      Retrieve all dishes.
      Returns:
      ResponseEntity containing a list of all dishes.
    • getVisibleDishes

      @GetMapping("/dishes/visible") public org.springframework.http.ResponseEntity<org.springframework.data.domain.Page<com.myfood.dto.Dish>> getVisibleDishes(@RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size)
    • getOneDish

      @PreAuthorize("hasRole(\'ADMIN\')") @GetMapping("/dish/{id}") public org.springframework.http.ResponseEntity<com.myfood.dto.Dish> getOneDish(@PathVariable(name="id") Long id)
      Retrieve a specific dish by its ID.
      Parameters:
      id - The ID of the dish to retrieve.
      Returns:
      ResponseEntity containing the requested dish or a 404 response if not found.
    • getDishByName

      @PreAuthorize("hasRole(\'ADMIN\')") @GetMapping("/dish/byName/{name}") public org.springframework.http.ResponseEntity<List<com.myfood.dto.Dish>> getDishByName(@PathVariable(name="name") String name)
      Retrieve dishes by name, considering case-insensitive matching.
      Parameters:
      name - The name of the dishes to retrieve.
      Returns:
      ResponseEntity containing a list of dishes matching the provided name or a 404 response if none are found.
    • getDishByNameVisible

      @GetMapping("/dish/visibleByName/{name}") public org.springframework.http.ResponseEntity<List<com.myfood.dto.Dish>> getDishByNameVisible(@PathVariable(name="name") String name)
      Retrieve visible dishes by name, considering case-insensitive matching.
      Parameters:
      name - The name of the dishes to retrieve.
      Returns:
      ResponseEntity containing a list of visible dishes matching the provided name or a 404 response if none are found.
    • getDishesByCategory

      @PreAuthorize("hasRole(\'ADMIN\')") @GetMapping("/dishes/byCategory/{category}") public org.springframework.http.ResponseEntity<?> getDishesByCategory(@PathVariable(name="category") String category, @RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size)
      Retrieve dishes by category.
      Parameters:
      category - The category of dishes to retrieve.
      Returns:
      ResponseEntity containing a list of dishes in the specified category or a 404 response if none are found.
    • getVisibleDishesByCategory

      @GetMapping("/dishes/visibleByCategory/{category}") public org.springframework.http.ResponseEntity<?> getVisibleDishesByCategory(@PathVariable(name="category") String category, @RequestParam(defaultValue="0") int page, @RequestParam(defaultValue="10") int size)
      Retrieve visible dishes by category.
      Parameters:
      category - The category of dishes to retrieve.
      Returns:
      ResponseEntity containing a list of visible dishes in the specified category or a 404 response if none are found.
    • saveDish

      @PreAuthorize("hasRole(\'ADMIN\')") @PostMapping("/dish") public org.springframework.http.ResponseEntity<?> saveDish(@RequestBody com.myfood.dto.Dish entity)
      Create a new dish.
      Parameters:
      entity - The dish to be created.
      Returns:
      ResponseEntity containing the created dish or an error response.
    • updateDish

      @PreAuthorize("hasRole(\'ADMIN\')") @PutMapping("/dish/{id}") public org.springframework.http.ResponseEntity<?> updateDish(@PathVariable(name="id") Long id, @RequestBody com.myfood.dto.Dish entity)
      Update an existing dish.
      Parameters:
      id - The ID of the dish to update.
      entity - The updated dish.
      Returns:
      ResponseEntity containing the updated dish or an error response.
    • changeDishVisibility

      @PreAuthorize("hasRole(\'ADMIN\')") @PutMapping("/dish/changeVisibility/{id}") public org.springframework.http.ResponseEntity<?> changeDishVisibility(@PathVariable(name="id") Long id)
      Change the visibility status of a dish.
      Parameters:
      id - The ID of the dish to update.
      Returns:
      ResponseEntity indicating the success of the visibility change or an error response if the dish is not found.
    • deleteOrder

      @PreAuthorize("hasRole(\'ADMIN\')") @DeleteMapping("/dish/{id}") public org.springframework.http.ResponseEntity<?> deleteOrder(@PathVariable(name="id") Long id)
      Delete a dish.
      Parameters:
      id - The ID of the dish to delete.
      Returns:
      ResponseEntity indicating success or a 404 response if the dish is not found.