1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | ||
4 | import edu.ucsb.cs156.example.entities.MenuItemReview; | |
5 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
6 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
7 | import edu.ucsb.cs156.example.repositories.MenuItemReviewRepository; | |
8 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
9 | ||
10 | import io.swagger.v3.oas.annotations.Operation; | |
11 | import io.swagger.v3.oas.annotations.Parameter; | |
12 | import io.swagger.v3.oas.annotations.tags.Tag; | |
13 | import lombok.extern.slf4j.Slf4j; | |
14 | ||
15 | import com.fasterxml.jackson.core.JsonProcessingException; | |
16 | ||
17 | import org.springframework.beans.factory.annotation.Autowired; | |
18 | import org.springframework.format.annotation.DateTimeFormat; | |
19 | import org.springframework.security.access.prepost.PreAuthorize; | |
20 | import org.springframework.web.bind.annotation.DeleteMapping; | |
21 | import org.springframework.web.bind.annotation.GetMapping; | |
22 | import org.springframework.web.bind.annotation.PostMapping; | |
23 | import org.springframework.web.bind.annotation.PutMapping; | |
24 | import org.springframework.web.bind.annotation.RequestBody; | |
25 | import org.springframework.web.bind.annotation.RequestMapping; | |
26 | import org.springframework.web.bind.annotation.RequestParam; | |
27 | import org.springframework.web.bind.annotation.RestController; | |
28 | ||
29 | import jakarta.validation.Valid; | |
30 | ||
31 | import java.time.LocalDateTime; | |
32 | ||
33 | @Tag(name = "MenuItemReview") | |
34 | @RequestMapping("/api/menuitemreview") | |
35 | @RestController | |
36 | @Slf4j | |
37 | public class MenuItemReviewController extends ApiController { | |
38 | @Autowired | |
39 | MenuItemReviewRepository menuItemReviewRepository; | |
40 | ||
41 | /** | |
42 | * List all Menu Item Reviews | |
43 | * | |
44 | * @return an iterable of MenuItemRevire | |
45 | */ | |
46 | @Operation(summary= "List all menu item reviews") | |
47 | @PreAuthorize("hasRole('ROLE_USER')") | |
48 | @GetMapping("/all") | |
49 | public Iterable<MenuItemReview> allMenuItemReviews() { | |
50 | Iterable<MenuItemReview> reviews = menuItemReviewRepository.findAll(); | |
51 |
1
1. allMenuItemReviews : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuItemReviews → KILLED |
return reviews; |
52 | } | |
53 | ||
54 | /** | |
55 | * Create a new review | |
56 | * | |
57 | * @param itemId | |
58 | * @param reviewerEmail | |
59 | * @param stars | |
60 | * @param localDateTime | |
61 | * @param comments | |
62 | * @return the saved review | |
63 | */ | |
64 | ||
65 | @Operation(summary= "Create a new review") | |
66 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
67 | @PostMapping("/post") | |
68 | public MenuItemReview postMenuItemReview( | |
69 | @Parameter(name="itemId") @RequestParam Long itemId, | |
70 | @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail, | |
71 | @Parameter(name="stars") @RequestParam int stars, | |
72 | @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, | |
73 | @Parameter(name="comments") @RequestParam String comments) | |
74 | throws JsonProcessingException { | |
75 | ||
76 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
77 | // See: https://www.baeldung.com/spring-date-parameters | |
78 | ||
79 | log.info("localDateTime={}", localDateTime); | |
80 | ||
81 | MenuItemReview review = new MenuItemReview(); | |
82 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemid → KILLED |
review.setItemid(itemId); |
83 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setRevieweremail → KILLED |
review.setRevieweremail(reviewerEmail); |
84 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED |
review.setStars(stars); |
85 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDatereviewed → KILLED |
review.setDatereviewed(localDateTime); |
86 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
review.setComments(comments); |
87 | MenuItemReview savedReview = menuItemReviewRepository.save(review); | |
88 | ||
89 |
1
1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postMenuItemReview → KILLED |
return savedReview; |
90 | } | |
91 | ||
92 | /** | |
93 | * Get a single review by id | |
94 | * | |
95 | * @param id the id of the review | |
96 | * @return a MenuItemReview | |
97 | */ | |
98 | @Operation(summary= "Get a single review") | |
99 | @PreAuthorize("hasRole('ROLE_USER')") | |
100 | @GetMapping("") | |
101 | public MenuItemReview getById(@Parameter(name="id") @RequestParam Long id) { | |
102 | MenuItemReview review = menuItemReviewRepository.findById(id) | |
103 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id)); |
104 | ||
105 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED |
return review; |
106 | } | |
107 | | |
108 | /** | |
109 | * Delete a UCSBDate | |
110 | * | |
111 | * @param id the id of the date to delete | |
112 | * @return a message indicating the date was deleted | |
113 | */ | |
114 | @Operation(summary= "Delete a MenuReviewItem") | |
115 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
116 | @DeleteMapping("") | |
117 | public Object deleteMenuItemReview( | |
118 | @Parameter(name="id") @RequestParam Long id) { | |
119 | MenuItemReview review = menuItemReviewRepository.findById(id) | |
120 |
1
1. lambda$deleteMenuItemReview$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$deleteMenuItemReview$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id)); |
121 | ||
122 |
1
1. deleteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED |
menuItemReviewRepository.delete(review); |
123 |
1
1. deleteMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::deleteMenuItemReview → KILLED |
return genericMessage("MenuItemReview with id %s deleted".formatted(id)); |
124 | } | |
125 | ||
126 | /** | |
127 | * Update a single review | |
128 | * | |
129 | * @param id id of the review to update | |
130 | * @param incoming the new review | |
131 | * @return the updated review object | |
132 | */ | |
133 | @Operation(summary= "Update a single review") | |
134 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
135 | @PutMapping("") | |
136 | public MenuItemReview updateMenuItemReview( | |
137 | @Parameter(name="id") @RequestParam Long id, | |
138 | @RequestBody @Valid MenuItemReview incoming) { | |
139 | ||
140 | MenuItemReview review = menuItemReviewRepository.findById(id) | |
141 |
1
1. lambda$updateMenuItemReview$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$updateMenuItemReview$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id)); |
142 | ||
143 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemid → KILLED |
review.setItemid(incoming.getItemid()); |
144 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setRevieweremail → KILLED |
review.setRevieweremail(incoming.getRevieweremail()); |
145 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED |
review.setStars(incoming.getStars()); |
146 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDatereviewed → KILLED |
review.setDatereviewed(incoming.getDatereviewed()); |
147 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
review.setComments(incoming.getComments()); |
148 | ||
149 | menuItemReviewRepository.save(review); | |
150 | ||
151 |
1
1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED |
return review; |
152 | } | |
153 | } | |
Mutations | ||
51 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
89 |
1.1 |
|
103 |
1.1 |
|
105 |
1.1 |
|
120 |
1.1 |
|
122 |
1.1 |
|
123 |
1.1 |
|
141 |
1.1 |
|
143 |
1.1 |
|
144 |
1.1 |
|
145 |
1.1 |
|
146 |
1.1 |
|
147 |
1.1 |
|
151 |
1.1 |