1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.MenuItemReview; | |
4 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
6 | import edu.ucsb.cs156.example.repositories.MenuItemReviewRepository; | |
7 | ||
8 | import io.swagger.v3.oas.annotations.Operation; | |
9 | import io.swagger.v3.oas.annotations.Parameter; | |
10 | import io.swagger.v3.oas.annotations.tags.Tag; | |
11 | import lombok.extern.slf4j.Slf4j; | |
12 | ||
13 | import com.fasterxml.jackson.core.JsonProcessingException; | |
14 | ||
15 | import org.springframework.beans.factory.annotation.Autowired; | |
16 | import org.springframework.format.annotation.DateTimeFormat; | |
17 | import org.springframework.security.access.prepost.PreAuthorize; | |
18 | import org.springframework.web.bind.annotation.DeleteMapping; | |
19 | import org.springframework.web.bind.annotation.GetMapping; | |
20 | import org.springframework.web.bind.annotation.PostMapping; | |
21 | import org.springframework.web.bind.annotation.PutMapping; | |
22 | import org.springframework.web.bind.annotation.RequestBody; | |
23 | import org.springframework.web.bind.annotation.RequestMapping; | |
24 | import org.springframework.web.bind.annotation.RequestParam; | |
25 | import org.springframework.web.bind.annotation.RestController; | |
26 | ||
27 | import jakarta.validation.Valid; | |
28 | ||
29 | import java.time.LocalDateTime; | |
30 | ||
31 | @Tag(name = "MenuItemReview") | |
32 | @RequestMapping("/api/menuitemreview") | |
33 | @RestController | |
34 | @Slf4j | |
35 | public class MenuItemReviewController extends ApiController{ | |
36 | | |
37 | @Autowired | |
38 | MenuItemReviewRepository menuItemReviewRepository; | |
39 | ||
40 | @Operation(summary= "List all menu item reviews") | |
41 | @PreAuthorize("hasRole('ROLE_USER')") | |
42 | @GetMapping("/all") | |
43 | public Iterable<MenuItemReview> allMenuItemReviews() { | |
44 | Iterable<MenuItemReview> reviews = menuItemReviewRepository.findAll(); | |
45 |
1
1. allMenuItemReviews : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewController::allMenuItemReviews → KILLED |
return reviews; |
46 | } | |
47 | ||
48 | @Operation(summary= "Create a new review") | |
49 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
50 | @PostMapping("/post") | |
51 | public MenuItemReview postMenuItemReview( | |
52 | @Parameter(name="itemId") @RequestParam long itemId, | |
53 | @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail, | |
54 | @Parameter(name="stars") @RequestParam int stars, | |
55 | @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, | |
56 | @Parameter(name="comments") @RequestParam String comments) | |
57 | throws JsonProcessingException { | |
58 | ||
59 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
60 | // See: https://www.baeldung.com/spring-date-parameters | |
61 | ||
62 | //log.info("localDateTime={}", dateReviewed); | |
63 | ||
64 | MenuItemReview menuItemReview = new MenuItemReview(); | |
65 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setItemId → KILLED |
menuItemReview.setItemId(itemId); |
66 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setReviewerEmail → KILLED |
menuItemReview.setReviewerEmail(reviewerEmail); |
67 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setStars → KILLED |
menuItemReview.setStars(stars); |
68 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setDateReviewed → KILLED |
menuItemReview.setDateReviewed(dateReviewed); |
69 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReview::setComments → KILLED |
menuItemReview.setComments(comments); |
70 | ||
71 | MenuItemReview savedMenuItemReview = menuItemReviewRepository.save(menuItemReview); | |
72 | ||
73 |
1
1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::postMenuItemReview → KILLED |
return savedMenuItemReview; |
74 | } | |
75 | ||
76 | @Operation(summary= "Get a single review") | |
77 | @PreAuthorize("hasRole('ROLE_USER')") | |
78 | @GetMapping("") | |
79 | public MenuItemReview getById( | |
80 | @Parameter(name="id") @RequestParam Long id) { | |
81 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
82 |
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)); |
83 | ||
84 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::getById → KILLED |
return menuItemReview; |
85 | } | |
86 | ||
87 | @Operation(summary= "Delete a MenuItemReview") | |
88 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
89 | @DeleteMapping("") | |
90 | public Object delteMenuItemReview( | |
91 | @Parameter(name="id") @RequestParam Long id) { | |
92 | MenuItemReview menuItemReview = menuItemReviewRepository.findById(id) | |
93 |
1
1. lambda$delteMenuItemReview$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::lambda$delteMenuItemReview$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReview.class, id)); |
94 | ||
95 |
1
1. delteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemReviewRepository::delete → KILLED |
menuItemReviewRepository.delete(menuItemReview); |
96 |
1
1. delteMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewController::delteMenuItemReview → 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 | ||
45 |
1.1 |
|
65 |
1.1 |
|
66 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 |
|
69 |
1.1 |
|
73 |
1.1 |
|
82 |
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 |