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 MenuItemReview | |
32 | */ | |
33 | ||
34 | @Tag(name = "MenuItemReview") | |
35 | @RequestMapping("/api/menuitemreview") | |
36 | @RestController | |
37 | @Slf4j | |
38 | public class MenuItemReviewController extends ApiController { | |
39 | ||
40 | @Autowired | |
41 | MenuItemReviewRepository menuItemReviewRepository; | |
42 | ||
43 | @Operation(summary= "List all menu item reviews") | |
44 | @PreAuthorize("hasRole('ROLE_USER')") | |
45 | @GetMapping("/all") | |
46 | public Iterable<MenuItemReview> allMenuItemReviews() { | |
47 | Iterable<MenuItemReview> reviews = menuItemReviewRepository.findAll(); | |
48 |
1
1. allMenuItemReviews : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuItemReviews → KILLED |
return reviews; |
49 | } | |
50 | ||
51 | @Operation(summary= "Get a single review") | |
52 | @PreAuthorize("hasRole('ROLE_USER')") | |
53 | @GetMapping("") | |
54 | public MenuItemReview getById( | |
55 | @Parameter(name="id") @RequestParam Long id) { | |
56 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
57 |
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)); |
58 | ||
59 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED |
return menuItemReview; |
60 | } | |
61 | ||
62 | @Operation(summary= "Create a menu item review") | |
63 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
64 | @PostMapping("/post") | |
65 | public MenuItemReview postMenuItemReview( | |
66 | @Parameter(name="itemId") @RequestParam long itemId, | |
67 | @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail, | |
68 | @Parameter(name="stars") @RequestParam int stars, | |
69 | @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, | |
70 | @Parameter(name = "comments") @RequestParam String comments) | |
71 | throws JsonProcessingException { | |
72 | ||
73 | log.info("localDateTime={}", dateReviewed); | |
74 | ||
75 | MenuItemReview menuItemReview = new MenuItemReview(); | |
76 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED |
menuItemReview.setItemId(itemId); |
77 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED |
menuItemReview.setReviewerEmail(reviewerEmail); |
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 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
menuItemReview.setComments(comments); |
81 | ||
82 | MenuItemReview savedReview = menuItemReviewRepository.save(menuItemReview); | |
83 | ||
84 |
1
1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postMenuItemReview → KILLED |
return savedReview; |
85 | } | |
86 | ||
87 | @Operation(summary= "Delete a MenuItemReview") | |
88 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
89 | @DeleteMapping("") | |
90 | public Object deleteMenuItemReview( | |
91 | @Parameter(name="id") @RequestParam Long id) { | |
92 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
93 |
1
1. lambda$deleteMenuItemReview$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$deleteMenuItemReview$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id)); |
94 | ||
95 |
1
1. deleteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED |
menuItemReviewRepository.delete(menuItemReview); |
96 |
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)); |
97 | } | |
98 | ||
99 | @Operation(summary= "Update a single 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$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$updateMenuItemReview$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id)); |
108 | ||
109 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED |
menuItemReview.setItemId(incoming.getItemId()); |
110 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED |
menuItemReview.setReviewerEmail(incoming.getReviewerEmail()); |
111 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED |
menuItemReview.setStars(incoming.getStars()); |
112 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED |
menuItemReview.setDateReviewed(incoming.getDateReviewed()); |
113 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
menuItemReview.setComments(incoming.getComments()); |
114 | ||
115 | menuItemReviewRepository.save(menuItemReview); | |
116 | ||
117 |
1
1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::updateMenuItemReview → KILLED |
return menuItemReview; |
118 | } | |
119 | ||
120 | } | |
Mutations | ||
48 |
1.1 |
|
57 |
1.1 |
|
59 |
1.1 |
|
76 |
1.1 |
|
77 |
1.1 |
|
78 |
1.1 |
|
79 |
1.1 |
|
80 |
1.1 |
|
84 |
1.1 |
|
93 |
1.1 |
|
95 |
1.1 |
|
96 |
1.1 |
|
107 |
1.1 |
|
109 |
1.1 |
|
110 |
1.1 |
|
111 |
1.1 |
|
112 |
1.1 |
|
113 |
1.1 |
|
117 |
1.1 |