1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.MenuItemReview; | |
4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
5 | import edu.ucsb.cs156.example.repositories.MenuItemReviewRepository; | |
6 | ||
7 | import io.swagger.v3.oas.annotations.Operation; | |
8 | import io.swagger.v3.oas.annotations.Parameter; | |
9 | import io.swagger.v3.oas.annotations.tags.Tag; | |
10 | import lombok.extern.slf4j.Slf4j; | |
11 | ||
12 | import com.fasterxml.jackson.core.JsonProcessingException; | |
13 | ||
14 | import org.springframework.beans.factory.annotation.Autowired; | |
15 | import org.springframework.format.annotation.DateTimeFormat; | |
16 | import org.springframework.security.access.prepost.PreAuthorize; | |
17 | import org.springframework.web.bind.annotation.DeleteMapping; | |
18 | import org.springframework.web.bind.annotation.GetMapping; | |
19 | import org.springframework.web.bind.annotation.PostMapping; | |
20 | import org.springframework.web.bind.annotation.PutMapping; | |
21 | import org.springframework.web.bind.annotation.RequestBody; | |
22 | import org.springframework.web.bind.annotation.RequestMapping; | |
23 | import org.springframework.web.bind.annotation.RequestParam; | |
24 | import org.springframework.web.bind.annotation.RestController; | |
25 | ||
26 | import jakarta.validation.Valid; | |
27 | ||
28 | import java.time.LocalDateTime; | |
29 | ||
30 | /** | |
31 | * This is a REST controller for UCSBMenuItemReview | |
32 | */ | |
33 | ||
34 | @Tag(name = "MenuItemReview") | |
35 | @RequestMapping("/api/menuitemreview") | |
36 | @RestController | |
37 | @Slf4j | |
38 | public class MenuItemReviewController extends ApiController { | |
39 | ||
40 | @Autowired | |
41 | MenuItemReviewRepository menuItemReviewRepository; | |
42 | ||
43 | /** | |
44 | * List all menu item reviews | |
45 | * | |
46 | * @return an iterable of MenuItemReview | |
47 | */ | |
48 | @Operation(summary= "List all menu item reviews") | |
49 | @PreAuthorize("hasRole('ROLE_USER')") | |
50 | @GetMapping("/all") | |
51 | public Iterable<MenuItemReview> allMenuItemReviews() { | |
52 | Iterable<MenuItemReview> reviews = menuItemReviewRepository.findAll(); | |
53 |
1
1. allMenuItemReviews : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuItemReviews → KILLED |
return reviews; |
54 | } | |
55 | ||
56 | | |
57 | /** | |
58 | * Get a single review by id | |
59 | * | |
60 | * @param id the id of the review | |
61 | * @return a MenuItemReview | |
62 | */ | |
63 | @Operation(summary= "Get a single review") | |
64 | @PreAuthorize("hasRole('ROLE_USER')") | |
65 | @GetMapping("") | |
66 | public MenuItemReview getById( | |
67 | @Parameter(name="id") @RequestParam Long id) { | |
68 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
69 |
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)); |
70 | ||
71 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED |
return menuItemReview; |
72 | } | |
73 | ||
74 | ||
75 | /** | |
76 | * Create a new review | |
77 | * | |
78 | * @param itemId the item id | |
79 | * @param reviewerEmail the email of the reviewer | |
80 | * @param stars the rating | |
81 | * @param dateReviewed the date reviewed | |
82 | * @param comments the comments | |
83 | * @return the saved review | |
84 | */ | |
85 | @Operation(summary= "Create a new review") | |
86 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
87 | @PostMapping("/post") | |
88 | public MenuItemReview postMenuItemReview( | |
89 | @Parameter(name="itemId") @RequestParam Long itemId, | |
90 | @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail, | |
91 | @Parameter(name="stars") @RequestParam int stars, | |
92 | @Parameter(name="dateReviewed") @RequestParam("dateReviewed") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateReviewed, | |
93 | @Parameter(name="comments") @RequestParam String comments | |
94 | ) | |
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 review to delete | |
118 | * @return a message indicating the date 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 | ||
128 |
1
1. deleteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED |
menuItemReviewRepository.delete(menuItemReview); |
129 |
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)); |
130 | } | |
131 | ||
132 | /** | |
133 | * Update a single review | |
134 | * | |
135 | * @param id id of the review to update | |
136 | * @param incoming the new review | |
137 | * @return the updated review object | |
138 | */ | |
139 | @Operation(summary= "Update a single review") | |
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 | ||
156 | menuItemReviewRepository.save(menuItemReview); | |
157 | ||
158 |
1
1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED |
return menuItemReview; |
159 | } | |
160 | ||
161 | } | |
Mutations | ||
53 |
1.1 |
|
69 |
1.1 |
|
71 |
1.1 |
|
103 |
1.1 |
|
104 |
1.1 |
|
105 |
1.1 |
|
106 |
1.1 |
|
107 |
1.1 |
|
111 |
1.1 |
|
126 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
147 |
1.1 |
|
149 |
1.1 |
|
150 |
1.1 |
|
151 |
1.1 |
|
152 |
1.1 |
|
153 |
1.1 |
|
158 |
1.1 |