Class RestaurantsController
java.lang.Object
edu.ucsb.cs156.dining.controllers.ApiController
edu.ucsb.cs156.dining.controllers.RestaurantsController
@RequestMapping("/api/restaurants")
@RestController
public class RestaurantsController
extends ApiController
This is a REST controller for Restaurants
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionThis method returns a list of all restaurants.deleteRestaurant
(Long id) Deletes a restaurant.This method returns a single restaurant.postRestaurant
(String name, String description) This method creates a new restaurant.updateRestaurant
(Long id, @Valid Restaurant incoming) Update a single restaurant.Methods inherited from class edu.ucsb.cs156.dining.controllers.ApiController
genericMessage, getCurrentUser, handleGenericException
-
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 restaurantdescription
- 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 updateincoming
- the new restaurant contents- Returns:
- the updated restaurant object
-