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