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 javax.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 | ||
36 | @Autowired | |
37 | MenuItemReviewRepository menuItemReviewRepository; | |
38 | ||
39 | @Operation(summary= "List all menu item reviews") | |
40 | @PreAuthorize("hasRole('ROLE_USER')") | |
41 | @GetMapping("/all") | |
42 | public Iterable<MenuItemReview> allMenuItemReviews() { | |
43 | Iterable<MenuItemReview> reviews = menuItemReviewRepository.findAll(); | |
44 |
1
1. allMenuItemReviews : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuItemReviews → KILLED |
return reviews; |
45 | } | |
46 | ||
47 | @Operation(summary= "Create a new menu item review") | |
48 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
49 | @PostMapping("/post") | |
50 | public MenuItemReview postMenuItemReview( | |
51 | @Parameter(name="itemID") @RequestParam long itemID, | |
52 | @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail, | |
53 | @Parameter(name="stars") @RequestParam int stars, | |
54 | @Parameter(name="dateReviewed") @RequestParam("dateReviewed") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateReviewed, | |
55 | @Parameter(name="comments") @RequestParam String comments) | |
56 | throws JsonProcessingException { | |
57 | ||
58 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
59 | // See: https://www.baeldung.com/spring-date-parameters | |
60 | ||
61 | log.info("localDateTime={}", dateReviewed); | |
62 | ||
63 | MenuItemReview menuItemReview = new MenuItemReview(); | |
64 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemID → KILLED |
menuItemReview.setItemID(itemID); |
65 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED |
menuItemReview.setReviewerEmail(reviewerEmail); |
66 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED |
menuItemReview.setStars(stars); |
67 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED |
menuItemReview.setDateReviewed(dateReviewed); |
68 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
menuItemReview.setComments(comments); |
69 | ||
70 | MenuItemReview savedMenuItemReview = menuItemReviewRepository.save(menuItemReview); | |
71 | ||
72 |
1
1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postMenuItemReview → KILLED |
return savedMenuItemReview; |
73 | } | |
74 | ||
75 | @Operation(summary= "Get a single review") | |
76 | @PreAuthorize("hasRole('ROLE_USER')") | |
77 | @GetMapping("") | |
78 | public MenuItemReview getById( | |
79 | @Parameter(name="id") @RequestParam Long id) { | |
80 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
81 |
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)); |
82 | ||
83 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED |
return menuItemReview; |
84 | } | |
85 | ||
86 | @Operation(summary= "Update a single review") | |
87 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
88 | @PutMapping("") | |
89 | public MenuItemReview updateMenuItemReview( | |
90 | @Parameter(name="id") @RequestParam Long id, | |
91 | @RequestBody @Valid MenuItemReview incoming) { | |
92 | ||
93 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
94 |
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)); |
95 | | |
96 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemID → KILLED |
menuItemReview.setItemID(incoming.getItemID()); |
97 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED |
menuItemReview.setReviewerEmail(incoming.getReviewerEmail()); |
98 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED |
menuItemReview.setStars(incoming.getStars()); |
99 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED |
menuItemReview.setDateReviewed(incoming.getDateReviewed()); |
100 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
menuItemReview.setComments(incoming.getComments()); |
101 | ||
102 | menuItemReviewRepository.save(menuItemReview); | |
103 | ||
104 |
1
1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED |
return menuItemReview; |
105 | } | |
106 | ||
107 | @Operation(summary= "Delete a MenuItemReview") | |
108 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
109 | @DeleteMapping("") | |
110 | public Object deleteMenuItemReview( | |
111 | @Parameter(name="id") @RequestParam Long id) { | |
112 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
113 |
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)); |
114 | ||
115 |
1
1. deleteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED |
menuItemReviewRepository.delete(menuItemReview); |
116 |
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)); |
117 | } | |
118 | ||
119 | } | |
Mutations | ||
44 |
1.1 |
|
64 |
1.1 |
|
65 |
1.1 |
|
66 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 |
|
72 |
1.1 |
|
81 |
1.1 |
|
83 |
1.1 |
|
94 |
1.1 |
|
96 |
1.1 |
|
97 |
1.1 |
|
98 |
1.1 |
|
99 |
1.1 |
|
100 |
1.1 |
|
104 |
1.1 |
|
113 |
1.1 |
|
115 |
1.1 |
|
116 |
1.1 |