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