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