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 Details

    • ReviewsController

      public ReviewsController()
  • Method Details

    • handleIllegalArgumentException

      @ResponseStatus(BAD_REQUEST) @ExceptionHandler(java.lang.IllegalArgumentException.class) public void handleIllegalArgumentException()
    • allReviews

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @GetMapping("/all") public Iterable<Review> allReviews()
      List all reviews
      Returns:
      an iterable of Review
    • getReviewsByUser

      @PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("") public Iterable<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 table
      dateServed - date item was served
      stars - rating from 0-5 inclusive
      reviewText - 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 update
      incoming - 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 moderate
      incoming - the new review
      Returns:
      the updated review object