1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.HelpRequest; | |
4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
5 | import edu.ucsb.cs156.example.repositories.HelpRequestRepository; | |
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 | @Tag(name = "HelpRequest") | |
31 | @RequestMapping("/api/helprequest") | |
32 | @RestController | |
33 | @Slf4j | |
34 | ||
35 | public class HelpRequestController extends ApiController { | |
36 | ||
37 | @Autowired | |
38 | HelpRequestRepository helpRequestRepository; | |
39 | ||
40 | /** | |
41 | * List all HelpRequests | |
42 | * | |
43 | * @return an iterable of HelpRequest | |
44 | */ | |
45 | @Operation(summary= "List all HelpRequests") | |
46 | @PreAuthorize("hasRole('ROLE_USER')") | |
47 | @GetMapping("/all") | |
48 | public Iterable<HelpRequest> allHelpRequests() { | |
49 | Iterable<HelpRequest> requests = helpRequestRepository.findAll(); | |
50 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return requests; |
51 | } | |
52 | ||
53 | /** | |
54 | * Post a new HelpRequest | |
55 | * | |
56 | * @param requesterEmail | |
57 | * @param teamId | |
58 | * @param tableOrBreakoutRoom | |
59 | * @param requestTime | |
60 | * @param explanation | |
61 | * @param solved | |
62 | * @return the new HelpRequest | |
63 | */ | |
64 | @Operation(summary= "Create a new HelpRequest") | |
65 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
66 | @PostMapping("/post") | |
67 | public HelpRequest postMenuItemReview( | |
68 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
69 | @Parameter(name="teamId") @RequestParam String teamId, | |
70 | @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
71 | @Parameter(name="requestTime", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") @RequestParam("requestTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime requestTime, | |
72 | @Parameter(name="explanation") @RequestParam String explanation, | |
73 | @Parameter(name="solved") @RequestParam boolean solved) | |
74 | throws JsonProcessingException { | |
75 | ||
76 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
77 | // See: https://www.baeldung.com/spring-date-parameters | |
78 | | |
79 | log.info("requestTime={}", requestTime); | |
80 | | |
81 | HelpRequest helpRequest = new HelpRequest(); | |
82 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
83 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
84 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
85 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
86 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
87 |
1
1. postMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
88 | HelpRequest savedMenuItemReview = helpRequestRepository.save(helpRequest); | |
89 |
1
1. postMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postMenuItemReview → KILLED |
return savedMenuItemReview; |
90 | } | |
91 | | |
92 | | |
93 | /** Get a single request by id | |
94 | * | |
95 | * @param id the id of the review | |
96 | * @return a HelpRequest object | |
97 | */ | |
98 | @Operation(summary= "Get a single request") | |
99 | @PreAuthorize("hasRole('ROLE_USER')") | |
100 | @GetMapping("") | |
101 | public HelpRequest getById( | |
102 | @Parameter(name="id") @RequestParam Long id) { | |
103 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
104 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
105 | ||
106 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED |
return helpRequest; |
107 | } | |
108 | | |
109 | /** | |
110 | * Delete a HelpRequest | |
111 | * | |
112 | * @param id the id of the review to delete | |
113 | * @return a message indicating the review was deleted | |
114 | */ | |
115 | @Operation(summary= "Delete a HelpRequest") | |
116 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
117 | @DeleteMapping("") | |
118 | public Object deleteHelpRequest( | |
119 | @Parameter(name="id") @RequestParam Long id) { | |
120 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
121 |
1
1. lambda$deleteHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$deleteHelpRequest$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
122 | | |
123 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
124 |
1
1. deleteHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::deleteHelpRequest → KILLED |
return genericMessage("HelpRequest with id %s deleted".formatted(id)); |
125 | } | |
126 | | |
127 | | |
128 | /** | |
129 | * Update a single review | |
130 | * | |
131 | * @param id id of the review to update | |
132 | * @param incoming the new review | |
133 | * @return the updated review object | |
134 | */ | |
135 | @Operation(summary= "Update a single request") | |
136 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
137 | @PutMapping("") | |
138 | public HelpRequest updateMenuItemReview( | |
139 | @Parameter(name="id") @RequestParam Long id, | |
140 | @RequestBody @Valid HelpRequest incoming) { | |
141 | ||
142 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
143 |
1
1. lambda$updateMenuItemReview$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$updateMenuItemReview$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
144 | ||
145 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
146 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
147 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
148 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
149 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
150 |
1
1. updateMenuItemReview : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
151 | ||
152 | helpRequestRepository.save(helpRequest); | |
153 |
1
1. updateMenuItemReview : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateMenuItemReview → KILLED |
return helpRequest; |
154 | } | |
155 | } | |
Mutations | ||
50 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
89 |
1.1 |
|
104 |
1.1 |
|
106 |
1.1 |
|
121 |
1.1 |
|
123 |
1.1 |
|
124 |
1.1 |
|
143 |
1.1 |
|
145 |
1.1 |
|
146 |
1.1 |
|
147 |
1.1 |
|
148 |
1.1 |
|
149 |
1.1 |
|
150 |
1.1 |
|
153 |
1.1 |