Class RestaurantsController

java.lang.Object
edu.ucsb.cs156.example.controllers.ApiController
edu.ucsb.cs156.example.controllers.RestaurantsController

@RequestMapping("/api/restaurants") @RestController public class RestaurantsController extends ApiController
This is a REST controller for Restaurants
  • Constructor Details

    • RestaurantsController

      public RestaurantsController()
  • Method Details

    • allRestaurants

      @PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("/all") public Iterable<Restaurant> allRestaurants()
      This method returns a list of all restaurants.
      Returns:
      a list of all restaurants
    • getById

      @PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("") public Restaurant getById(@RequestParam Long id)
      This method returns a single restaurant.
      Parameters:
      id - id of the restaurant to get
      Returns:
      a single restaurant
    • postRestaurant

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PostMapping("/post") public Restaurant postRestaurant(@RequestParam String name, @RequestParam String description)
      This method creates a new restaurant. Accessible only to users with the role "ROLE_ADMIN".
      Parameters:
      name - name of the restaurant
      description - description of the restaurant
      Returns:
      the save restaurant (with it's id field set by the database)
    • deleteRestaurant

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @DeleteMapping("") public Object deleteRestaurant(@RequestParam Long id)
      Deletes a restaurant. Accessible only to users with the role "ROLE_ADMIN".
      Parameters:
      id - id of the restaurant to delete
      Returns:
      a message indicating that the restaurant was deleted
    • updateRestaurant

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PutMapping("") public Restaurant updateRestaurant(@RequestParam Long id, @RequestBody @Valid @Valid Restaurant incoming)
      Update a single restaurant. Accessible only to users with the role "ROLE_ADMIN".
      Parameters:
      id - id of the restaurant to update
      incoming - the new restaurant contents
      Returns:
      the updated restaurant object