1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.MenuItemReviews; | |
4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
5 | import edu.ucsb.cs156.example.repositories.MenuItemsReviewsRepository; | |
6 | import io.swagger.v3.oas.annotations.Operation; | |
7 | import io.swagger.v3.oas.annotations.Parameter; | |
8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
9 | import lombok.extern.slf4j.Slf4j; | |
10 | ||
11 | import com.fasterxml.jackson.core.JsonProcessingException; | |
12 | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | |
14 | import org.springframework.format.annotation.DateTimeFormat; | |
15 | import org.springframework.security.access.prepost.PreAuthorize; | |
16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
17 | import org.springframework.web.bind.annotation.GetMapping; | |
18 | import org.springframework.web.bind.annotation.PostMapping; | |
19 | import org.springframework.web.bind.annotation.PutMapping; | |
20 | import org.springframework.web.bind.annotation.RequestBody; | |
21 | import org.springframework.web.bind.annotation.RequestMapping; | |
22 | import org.springframework.web.bind.annotation.RequestParam; | |
23 | import org.springframework.web.bind.annotation.RestController; | |
24 | ||
25 | import jakarta.validation.Valid; | |
26 | ||
27 | import java.time.LocalDateTime; | |
28 | ||
29 | ||
30 | @Tag(name = "MenuItemReviews") | |
31 | @RequestMapping("/api/menuitemreviews") | |
32 | @RestController | |
33 | @Slf4j | |
34 | public class MenuItemReviewsController extends ApiController { | |
35 | //please take into account id is the primary key of the entity and then the other fields | |
36 | ||
37 | @Autowired | |
38 | MenuItemsReviewsRepository menuItemsReviewsRepository; | |
39 | ||
40 | /** | |
41 | * List all MenuItemReviews | |
42 | * | |
43 | * @return an iterable of MenuItemReviews | |
44 | */ | |
45 | @Operation(summary= "List all menu item reviews") | |
46 | @PreAuthorize("hasRole('ROLE_USER')") | |
47 | @GetMapping("/all") | |
48 | public Iterable<MenuItemReviews> allMenuItemReviews() { | |
49 | Iterable<MenuItemReviews> reviews = menuItemsReviewsRepository.findAll(); | |
50 |
1
1. allMenuItemReviews : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::allMenuItemReviews → KILLED |
return reviews; |
51 | } | |
52 | ||
53 | @Operation(summary= "Create a new menu item review") | |
54 | @PreAuthorize("hasRole('ROLE_USER')") | |
55 | @PostMapping("/post") | |
56 | ||
57 | //Create a new menu item review | |
58 | public MenuItemReviews postMenuItemReview( | |
59 | @Parameter(name="itemId") @RequestParam long itemId, | |
60 | @Parameter(name="reviewerEmail") @RequestParam String reviewerEmail, | |
61 | @Parameter(name="stars") @RequestParam int stars, | |
62 | @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, | |
63 | @Parameter(name="comments") @RequestParam String comments) | |
64 | throws JsonProcessingException { | |
65 | ||
66 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
67 | // See: https://www.baeldung.com/spring-date-parameters | |
68 | ||
69 | log.info("dateReviewed={}", dateReviewed); | |
70 | ||
71 | MenuItemReviews menuItemReview = new MenuItemReviews(); | |
72 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setItemId → KILLED |
menuItemReview.setItemId(itemId); |
73 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setReviewerEmail → KILLED |
menuItemReview.setReviewerEmail(reviewerEmail); |
74 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setStars → KILLED |
menuItemReview.setStars(stars); |
75 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setDateReviewed → KILLED |
menuItemReview.setDateReviewed(dateReviewed); |
76 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setComments → KILLED |
menuItemReview.setComments(comments); |
77 | ||
78 | MenuItemReviews savedMenuItemReview = menuItemsReviewsRepository.save(menuItemReview); | |
79 | ||
80 |
1
1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::postMenuItemReview → KILLED |
return savedMenuItemReview; |
81 | } | |
82 | ||
83 | @Operation(summary="get a single menu item review") | |
84 | @PreAuthorize("hasRole('ROLE_USER')") | |
85 | @GetMapping("") | |
86 | ||
87 | //Get a single menu item review by id | |
88 | public MenuItemReviews getById( | |
89 | @Parameter(name="id") @RequestParam Long id) { | |
90 | MenuItemReviews menuItemReview = menuItemsReviewsRepository.findById(id) | |
91 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReviews.class, id)); |
92 | ||
93 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::getById → KILLED |
return menuItemReview; |
94 | } | |
95 | ||
96 | @Operation(summary="Delete a menu item review by id") | |
97 | @PreAuthorize("hasRole('ROLE_USER')") | |
98 | @DeleteMapping("") | |
99 | ||
100 | //Delete a menu item review by id(not itemId) | |
101 | ||
102 | public Object deleteMenuItemReview( | |
103 | @Parameter(name="id") @RequestParam Long id) { | |
104 | MenuItemReviews menuItemReview = menuItemsReviewsRepository.findById(id) | |
105 |
1
1. lambda$deleteMenuItemReview$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::lambda$deleteMenuItemReview$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReviews.class, id)); |
106 | ||
107 |
1
1. deleteMenuItemReview : removed call to edu/ucsb/cs156/example/repositories/MenuItemsReviewsRepository::delete → KILLED |
menuItemsReviewsRepository.delete(menuItemReview); |
108 |
1
1. deleteMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::deleteMenuItemReview → KILLED |
return genericMessage("MenuItemReview with id %s deleted".formatted(id)); |
109 | } | |
110 | ||
111 | @Operation(summary="Update a single menu item review") | |
112 | @PreAuthorize("hasRole('ROLE_USER')") | |
113 | @PutMapping("") | |
114 | ||
115 | //Update a single menu item review by id | |
116 | public MenuItemReviews updateMenuItemReview( | |
117 | @Parameter(name="id") @RequestParam Long id, | |
118 | @RequestBody @Valid MenuItemReviews incoming) { | |
119 | ||
120 | MenuItemReviews menuItemReview = menuItemsReviewsRepository.findById(id) | |
121 |
1
1. lambda$updateMenuItemReview$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::lambda$updateMenuItemReview$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(MenuItemReviews.class, id)); |
122 | ||
123 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setItemId → KILLED |
menuItemReview.setItemId(incoming.getItemId()); |
124 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setReviewerEmail → KILLED |
menuItemReview.setReviewerEmail(incoming.getReviewerEmail()); |
125 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setStars → KILLED |
menuItemReview.setStars(incoming.getStars()); |
126 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setDateReviewed → KILLED |
menuItemReview.setDateReviewed(incoming.getDateReviewed()); |
127 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/MenuItemReviews::setComments → KILLED |
menuItemReview.setComments(incoming.getComments()); |
128 | ||
129 | menuItemsReviewsRepository.save(menuItemReview); | |
130 | ||
131 |
1
1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/MenuItemReviewsController::updateMenuItemReview → KILLED |
return menuItemReview; |
132 | } | |
133 | } | |
Mutations | ||
50 |
1.1 |
|
72 |
1.1 |
|
73 |
1.1 |
|
74 |
1.1 |
|
75 |
1.1 |
|
76 |
1.1 |
|
80 |
1.1 |
|
91 |
1.1 |
|
93 |
1.1 |
|
105 |
1.1 |
|
107 |
1.1 |
|
108 |
1.1 |
|
121 |
1.1 |
|
123 |
1.1 |
|
124 |
1.1 |
|
125 |
1.1 |
|
126 |
1.1 |
|
127 |
1.1 |
|
131 |
1.1 |