1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.Article; | |
4 | import edu.ucsb.cs156.example.entities.MenuItemReview; | |
5 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
6 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
7 | import edu.ucsb.cs156.example.repositories.MenuItemReviewRepository; | |
8 | ||
9 | import io.swagger.v3.oas.annotations.Operation; | |
10 | import io.swagger.v3.oas.annotations.Parameter; | |
11 | import io.swagger.v3.oas.annotations.tags.Tag; | |
12 | import lombok.extern.slf4j.Slf4j; | |
13 | ||
14 | import com.fasterxml.jackson.core.JsonProcessingException; | |
15 | ||
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/menuitemreview") | |
38 | @RestController | |
39 | @Slf4j | |
40 | ||
41 | public class MenuItemReviewController extends ApiController{ | |
42 | | |
43 | @Autowired | |
44 | MenuItemReviewRepository menuItemReviewRepository; | |
45 | /* | |
46 | * List all MenuItemReviews | |
47 | * | |
48 | * @return an iterable of MenuItemReview | |
49 | */ | |
50 | @Operation(summary= "List all menu item reviews") | |
51 | @PreAuthorize("hasRole('ROLE_USER')") | |
52 | @GetMapping("/all") | |
53 | public Iterable<MenuItemReview> allMenuItemReviews() { | |
54 | Iterable<MenuItemReview> reviews = menuItemReviewRepository.findAll(); | |
55 |
1
1. allMenuItemReviews : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuItemReviews → KILLED |
return reviews; |
56 | } | |
57 | ||
58 | /** | |
59 | * Get a single article by id | |
60 | * | |
61 | * @param id the id of the review | |
62 | * @return an MenuItemReview | |
63 | */ | |
64 | @Operation(summary= "Get a single review") | |
65 | @PreAuthorize("hasRole('ROLE_USER')") | |
66 | @GetMapping("") | |
67 | public MenuItemReview getById( | |
68 | @Parameter(name="id") @RequestParam Long id) { | |
69 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
70 |
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)); |
71 | ||
72 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED |
return menuItemReview; |
73 | } | |
74 | ||
75 | ||
76 | /** | |
77 | * Create a new date | |
78 | * | |
79 | * @param itemId id of review | |
80 | * @param reviewerEmail review email | |
81 | * @param stars review stars | |
82 | * @param dateReviewed date of review | |
83 | * @param comments review comments | |
84 | * @return the saved review | |
85 | */ | |
86 | @Operation(summary= "Create a new 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::setDateReviewed → KILLED |
menuItemReview.setDateReviewed(dateReviewed); |
106 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED |
menuItemReview.setStars(stars); |
107 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
menuItemReview.setComments(comments); |
108 | ||
109 | ||
110 | MenuItemReview savedMenuItemReview = menuItemReviewRepository.save(menuItemReview); | |
111 | ||
112 |
1
1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postMenuItemReview → KILLED |
return savedMenuItemReview; |
113 | } | |
114 | /** | |
115 | * update a single review | |
116 | * | |
117 | * @param id id of review | |
118 | * @param incoming review to be updated | |
119 | * @return the saved review | |
120 | */ | |
121 | @Operation(summary= "Update a single review") | |
122 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
123 | @PutMapping("") | |
124 | public MenuItemReview updateMenuItemReview( | |
125 | @Parameter(name="id") @RequestParam Long id, | |
126 | @RequestBody @Valid MenuItemReview incoming) { | |
127 | ||
128 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
129 |
1
1. lambda$updateMenuItemReview$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$updateMenuItemReview$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id)); |
130 | ||
131 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED |
menuItemReview.setItemId(incoming.getItemId()); |
132 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED |
menuItemReview.setReviewerEmail(incoming.getReviewerEmail()); |
133 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED |
menuItemReview.setDateReviewed(incoming.getDateReviewed()); |
134 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED |
menuItemReview.setStars(incoming.getStars()); |
135 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
menuItemReview.setComments(incoming.getComments()); |
136 | ||
137 | menuItemReviewRepository.save(menuItemReview); | |
138 | ||
139 |
1
1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED |
return menuItemReview; |
140 | } | |
141 | ||
142 | /** | |
143 | * Delete a review | |
144 | * | |
145 | * @param id id of review | |
146 | * @return the saved review | |
147 | */ | |
148 | @Operation(summary= "Delete a review") | |
149 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
150 | @DeleteMapping("") | |
151 | public Object deleteMenuItemReview( | |
152 | @Parameter(name="id") @RequestParam Long id) { | |
153 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
154 |
1
1. lambda$deleteMenuItemReview$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$deleteMenuItemReview$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id)); |
155 | ||
156 |
1
1. deleteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED |
menuItemReviewRepository.delete(menuItemReview); |
157 |
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)); |
158 | } | |
159 | } | |
Mutations | ||
55 |
1.1 |
|
70 |
1.1 |
|
72 |
1.1 |
|
103 |
1.1 |
|
104 |
1.1 |
|
105 |
1.1 |
|
106 |
1.1 |
|
107 |
1.1 |
|
112 |
1.1 |
|
129 |
1.1 |
|
131 |
1.1 |
|
132 |
1.1 |
|
133 |
1.1 |
|
134 |
1.1 |
|
135 |
1.1 |
|
139 |
1.1 |
|
154 |
1.1 |
|
156 |
1.1 |
|
157 |
1.1 |