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.checkerframework.checker.units.qual.m; | |
16 | import org.springframework.beans.factory.annotation.Autowired; | |
17 | import org.springframework.format.annotation.DateTimeFormat; | |
18 | import org.springframework.security.access.prepost.PreAuthorize; | |
19 | import org.springframework.web.bind.annotation.DeleteMapping; | |
20 | import org.springframework.web.bind.annotation.GetMapping; | |
21 | import org.springframework.web.bind.annotation.PostMapping; | |
22 | import org.springframework.web.bind.annotation.PutMapping; | |
23 | import org.springframework.web.bind.annotation.RequestBody; | |
24 | import org.springframework.web.bind.annotation.RequestMapping; | |
25 | import org.springframework.web.bind.annotation.RequestParam; | |
26 | import org.springframework.web.bind.annotation.RestController; | |
27 | ||
28 | import jakarta.validation.Valid; | |
29 | ||
30 | import java.time.LocalDateTime; | |
31 | ||
32 | /** | |
33 | * This is a REST controller for MenuItemReview | |
34 | */ | |
35 | ||
36 | @Tag(name = "MenuItemReview") | |
37 | @RequestMapping("/api/menu_item_review") | |
38 | @RestController | |
39 | @Slf4j | |
40 | ||
41 | public class MenuItemReviewController extends ApiController { | |
42 | | |
43 | @Autowired | |
44 | MenuItemReviewRepository menuItemReviewRepository; | |
45 | ||
46 | /** | |
47 | * List all MeuItemReviews | |
48 | * | |
49 | * @return an iterable of MenuItemReview | |
50 | */ | |
51 | ||
52 | @Operation(summary= "List all menu item reviews") | |
53 | @PreAuthorize("hasRole('ROLE_USER')") | |
54 | @GetMapping("/all") | |
55 | public Iterable<MenuItemReview> allMenuReviews() { | |
56 | Iterable<MenuItemReview> menuItemReviews = menuItemReviewRepository.findAll(); | |
57 |
1
1. allMenuReviews : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuReviews → KILLED |
return menuItemReviews; |
58 | } | |
59 | ||
60 | /** | |
61 | * Get a single date by id | |
62 | * | |
63 | * @param id the id of the date | |
64 | * @return a MenuItemReview | |
65 | */ | |
66 | ||
67 | ||
68 | @Operation(summary= "Look up by id") | |
69 | @PreAuthorize("hasRole('ROLE_USER')") | |
70 | @GetMapping("") | |
71 | public MenuItemReview getById( | |
72 | @Parameter(name="id") @RequestParam Long id) { | |
73 | MenuItemReview review = menuItemReviewRepository.findById(id) | |
74 |
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)); |
75 | ||
76 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED |
return review; |
77 | } | |
78 | ||
79 | /** | |
80 | * Create a new review | |
81 | * | |
82 | * @param itemId | |
83 | * @param reviewerEmail | |
84 | * @param stars | |
85 | * @param comments | |
86 | * @param dateReviewed date | |
87 | * @return the saved menuItemReview | |
88 | */ | |
89 | @Operation(summary = "Create a new menu item review") | |
90 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
91 | @PostMapping("/post") | |
92 | public MenuItemReview postMenuItemReview( | |
93 | @Parameter(name = "itemId") @RequestParam Long itemId, | |
94 | @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail, | |
95 | @Parameter(name="stars") @RequestParam int stars, | |
96 | @Parameter(name="comments") @RequestParam String comments, | |
97 | @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) | |
98 | throws JsonProcessingException { | |
99 | ||
100 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
101 | // See: https://www.baeldung.com/spring-date-parameters | |
102 | ||
103 | log.info("localDateTime={}", dateReviewed); | |
104 | ||
105 | MenuItemReview menuItemReview = new MenuItemReview(); | |
106 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED |
menuItemReview.setItemId(itemId); |
107 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED |
menuItemReview.setReviewerEmail(reviewerEmail); |
108 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED |
menuItemReview.setStars(stars); |
109 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
menuItemReview.setComments(comments); |
110 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED |
menuItemReview.setDateReviewed(dateReviewed); |
111 | ||
112 | MenuItemReview savedMenuItemReview = menuItemReviewRepository.save(menuItemReview); | |
113 | ||
114 |
1
1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postMenuItemReview → KILLED |
return savedMenuItemReview; |
115 | } | |
116 | ||
117 | ||
118 | /** | |
119 | * Delete a MenuItemReview | |
120 | * | |
121 | * @param id the id of the date to delete | |
122 | * @return a message indicating the date was deleted | |
123 | */ | |
124 | @Operation(summary= "Delete a MenuItemReview") | |
125 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
126 | @DeleteMapping("") | |
127 | public Object deleteMenuItem( | |
128 | @Parameter(name="id") @RequestParam Long id) { | |
129 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
130 |
1
1. lambda$deleteMenuItem$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$deleteMenuItem$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id)); |
131 | ||
132 |
1
1. deleteMenuItem : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED |
menuItemReviewRepository.delete(menuItemReview); |
133 |
1
1. deleteMenuItem : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::deleteMenuItem → KILLED |
return genericMessage("MenuItemReview with id %s deleted".formatted(id)); |
134 | } | |
135 | ||
136 | /** | |
137 | * Update a single date | |
138 | * | |
139 | * @param id id of the date to update | |
140 | * @param incoming the new date | |
141 | * @return the updated date object | |
142 | */ | |
143 | @Operation(summary= "Update a single menu item review") | |
144 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
145 | @PutMapping("") | |
146 | public MenuItemReview updateMenuItemReview( | |
147 | @Parameter(name="id") @RequestParam Long id, | |
148 | @RequestBody @Valid MenuItemReview incoming) { | |
149 | ||
150 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
151 |
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)); |
152 | ||
153 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED |
menuItemReview.setItemId(incoming.getItemId()); |
154 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED |
menuItemReview.setReviewerEmail(incoming.getReviewerEmail()); |
155 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED |
menuItemReview.setStars(incoming.getStars()); |
156 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
menuItemReview.setComments(incoming.getComments()); |
157 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED |
menuItemReview.setDateReviewed(incoming.getDateReviewed()); |
158 | | |
159 | ||
160 | menuItemReviewRepository.save(menuItemReview); | |
161 | ||
162 |
1
1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED |
return menuItemReview; |
163 | } | |
164 | } | |
Mutations | ||
57 |
1.1 |
|
74 |
1.1 |
|
76 |
1.1 |
|
106 |
1.1 |
|
107 |
1.1 |
|
108 |
1.1 |
|
109 |
1.1 |
|
110 |
1.1 |
|
114 |
1.1 |
|
130 |
1.1 |
|
132 |
1.1 |
|
133 |
1.1 |
|
151 |
1.1 |
|
153 |
1.1 |
|
154 |
1.1 |
|
155 |
1.1 |
|
156 |
1.1 |
|
157 |
1.1 |
|
162 |
1.1 |