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