Class ReviewsController
java.lang.Object
edu.ucsb.cs156.dining.controllers.ApiController
edu.ucsb.cs156.dining.controllers.ReviewsController
@RequestMapping("/api/reviews")
@RestController
public class ReviewsController
extends ApiController
This is a REST controller for Reviews
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionList all reviewsList all reviews created by a specific userList all reviews needing moderationvoid
moderateReview
(Long id, @Valid Review incoming) Moderate a single reviewpostReview
(long itemId, LocalDateTime dateServed, long stars, String reviewText) Create a new reviewupdateReview
(Long id, @Valid Review incoming) Update a single reviewMethods inherited from class edu.ucsb.cs156.dining.controllers.ApiController
genericMessage, getCurrentUser, handleGenericException
-
Constructor Details
-
ReviewsController
public ReviewsController()
-
-
Method Details
-
handleIllegalArgumentException
@ResponseStatus(BAD_REQUEST) @ExceptionHandler(java.lang.IllegalArgumentException.class) public void handleIllegalArgumentException() -
allReviews
List all reviews- Returns:
- an iterable of Review
-
getReviewsByUser
List all reviews created by a specific user- Returns:
- an iterable of Review
-
getReviewsNeedingModeration
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @GetMapping("/needsmoderation") public Iterable<Review> getReviewsNeedingModeration()List all reviews needing moderation- Returns:
- an iterable of Review
-
postReview
@PreAuthorize("hasRole(\'ROLE_USER\')") @PostMapping("/post") public Review postReview(@RequestParam long itemId, @RequestParam("dateServed") @DateTimeFormat(iso=DATE_TIME) LocalDateTime dateServed, @RequestParam long stars, @RequestParam String reviewText) throws com.fasterxml.jackson.core.JsonProcessingException Create a new review- Parameters:
itemId
- id of item in DiningCommonsMenuItem tabledateServed
- date item was servedstars
- rating from 0-5 inclusivereviewText
- reviewer comments- Returns:
- the saved review
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
updateReview
@PreAuthorize("hasRole(\'ROLE_USER\')") @PutMapping("/reviewer") public Review updateReview(@RequestParam Long id, @RequestBody @Valid @Valid Review incoming) Update a single review- Parameters:
id
- id of the review to updateincoming
- the new review- Returns:
- the updated review object
-
moderateReview
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PutMapping("/moderator") public Review moderateReview(@RequestParam Long id, @RequestBody @Valid @Valid Review incoming) Moderate a single review- Parameters:
id
- id of the review to moderateincoming
- the new review- Returns:
- the updated review object
-