| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.MenuItemReview; | |
| 4 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
| 5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs156.example.repositories.MenuItemReviewRepository; | |
| 7 | ||
| 8 | import io.swagger.v3.oas.annotations.Operation; | |
| 9 | import io.swagger.v3.oas.annotations.Parameter; | |
| 10 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 11 | import lombok.extern.slf4j.Slf4j; | |
| 12 | ||
| 13 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 14 | ||
| 15 | import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | import org.springframework.format.annotation.DateTimeFormat; | |
| 17 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 18 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 19 | import org.springframework.web.bind.annotation.GetMapping; | |
| 20 | import org.springframework.web.bind.annotation.PostMapping; | |
| 21 | import org.springframework.web.bind.annotation.PutMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestBody; | |
| 23 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 24 | import org.springframework.web.bind.annotation.RequestParam; | |
| 25 | import org.springframework.web.bind.annotation.RestController; | |
| 26 | ||
| 27 | import javax.validation.Valid; | |
| 28 | ||
| 29 | import java.time.LocalDateTime; | |
| 30 | ||
| 31 | @Tag(name = "MenuItemReview") | |
| 32 | @RequestMapping("/api/menuitemreview") | |
| 33 | @RestController | |
| 34 | @Slf4j | |
| 35 | public class MenuItemReviewController extends ApiController{ | |
| 36 | ||
| 37 | @Autowired | |
| 38 | MenuItemReviewRepository menuItemReviewRepository; | |
| 39 | ||
| 40 | @Operation(summary= "List all reviews") | |
| 41 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 42 | @GetMapping("/all") | |
| 43 | public Iterable<MenuItemReview> allReviews() { | |
| 44 | Iterable<MenuItemReview> reviews = menuItemReviewRepository.findAll(); | |
| 45 |
1
1. allReviews : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allReviews → KILLED |
return reviews; |
| 46 | } | |
| 47 | ||
| 48 | @Operation(summary= "Create a new review") | |
| 49 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 50 | @PostMapping("/post") | |
| 51 | public MenuItemReview postMenuItemReview( | |
| 52 | @Parameter(name="itemID") @RequestParam long itemID, | |
| 53 | @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail, | |
| 54 | @Parameter(name="stars") @RequestParam int stars, | |
| 55 | @Parameter(name="localDateTime", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("localDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime localDateTime, @Parameter(name="comments") @RequestParam String comments) | |
| 56 | ||
| 57 | throws JsonProcessingException { | |
| 58 | ||
| 59 | //log.info("localDateTime={}", localDateTime); | |
| 60 | ||
| 61 | MenuItemReview menuItemReview = new MenuItemReview(); | |
| 62 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED |
menuItemReview.setItemId(itemID); |
| 63 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED |
menuItemReview.setReviewerEmail(reviewerEmail); |
| 64 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED |
menuItemReview.setStars(stars); |
| 65 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED |
menuItemReview.setDateReviewed(localDateTime); |
| 66 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
menuItemReview.setComments(comments); |
| 67 | ||
| 68 | MenuItemReview savedReviews = menuItemReviewRepository.save(menuItemReview); | |
| 69 | ||
| 70 |
1
1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postMenuItemReview → KILLED |
return savedReviews; |
| 71 | } | |
| 72 | ||
| 73 | @Operation(summary= "Delete a UCSBDate") | |
| 74 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 75 | @DeleteMapping("") | |
| 76 | public Object deleteUCSBDate( | |
| 77 | @Parameter(name="id") @RequestParam Long id) { | |
| 78 | MenuItemReview review = menuItemReviewRepository.findById(id) | |
| 79 |
1
1. lambda$deleteUCSBDate$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$deleteUCSBDate$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(UCSBDate.class, id)); |
| 80 | ||
| 81 |
1
1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED |
menuItemReviewRepository.delete(review); |
| 82 |
1
1. deleteUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::deleteUCSBDate → KILLED |
return genericMessage("UCSBDate with id %s deleted".formatted(id)); |
| 83 | } | |
| 84 | ||
| 85 | @Operation(summary= "Update a single date") | |
| 86 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 87 | @PutMapping("") | |
| 88 | public MenuItemReview updateUCSBDate( | |
| 89 | @Parameter(name="id") @RequestParam Long id, | |
| 90 | @RequestBody @Valid MenuItemReview incoming) { | |
| 91 | ||
| 92 | MenuItemReview review = menuItemReviewRepository.findById(id) | |
| 93 |
1
1. lambda$updateUCSBDate$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$updateUCSBDate$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id)); |
| 94 | ||
| 95 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED |
review.setItemId(incoming.getItemId()); |
| 96 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED |
review.setReviewerEmail(incoming.getReviewerEmail()); |
| 97 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED |
review.setStars(incoming.getStars()); |
| 98 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED |
review.setDateReviewed(incoming.getDateReviewed()); |
| 99 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
review.setComments(incoming.getComments()); |
| 100 | ||
| 101 | menuItemReviewRepository.save(review); | |
| 102 | ||
| 103 |
1
1. updateUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateUCSBDate → KILLED |
return review; |
| 104 | } | |
| 105 | ||
| 106 | @Operation(summary= "Get a single review") | |
| 107 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 108 | @GetMapping("") | |
| 109 | public MenuItemReview getById( | |
| 110 | @Parameter(name="id") @RequestParam Long id) { | |
| 111 | MenuItemReview review = menuItemReviewRepository.findById(id) | |
| 112 |
1
1. lambda$getById$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$getById$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id)); |
| 113 | ||
| 114 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED |
return review; |
| 115 | } | |
| 116 | } | |
Mutations | ||
| 45 |
1.1 |
|
| 62 |
1.1 |
|
| 63 |
1.1 |
|
| 64 |
1.1 |
|
| 65 |
1.1 |
|
| 66 |
1.1 |
|
| 70 |
1.1 |
|
| 79 |
1.1 |
|
| 81 |
1.1 |
|
| 82 |
1.1 |
|
| 93 |
1.1 |
|
| 95 |
1.1 |
|
| 96 |
1.1 |
|
| 97 |
1.1 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 103 |
1.1 |
|
| 112 |
1.1 |
|
| 114 |
1.1 |