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