1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.entities.HelpRequest; | |
4 | import edu.ucsb.cs156.example.repositories.HelpRequestRepository; | |
5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
6 | import edu.ucsb.cs156.example.repositories.HelpRequestRepository; | |
7 | import edu.ucsb.cs156.example.entities.UCSBDate; | |
8 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
9 | ||
10 | import io.swagger.v3.oas.annotations.Operation; | |
11 | import io.swagger.v3.oas.annotations.Parameter; | |
12 | import io.swagger.v3.oas.annotations.tags.Tag; | |
13 | import lombok.extern.slf4j.Slf4j; | |
14 | ||
15 | import com.fasterxml.jackson.core.JsonProcessingException; | |
16 | ||
17 | import org.springframework.beans.factory.annotation.Autowired; | |
18 | import org.springframework.format.annotation.DateTimeFormat; | |
19 | import org.springframework.security.access.prepost.PreAuthorize; | |
20 | import org.springframework.web.bind.annotation.DeleteMapping; | |
21 | import org.springframework.web.bind.annotation.GetMapping; | |
22 | import org.springframework.web.bind.annotation.PostMapping; | |
23 | import org.springframework.web.bind.annotation.PutMapping; | |
24 | import org.springframework.web.bind.annotation.RequestBody; | |
25 | import org.springframework.web.bind.annotation.RequestMapping; | |
26 | import org.springframework.web.bind.annotation.RequestParam; | |
27 | import org.springframework.web.bind.annotation.RestController; | |
28 | ||
29 | import jakarta.validation.Valid; | |
30 | ||
31 | import java.time.LocalDateTime; | |
32 | ||
33 | /** | |
34 | * This is a REST controller for HelpRequests | |
35 | */ | |
36 | ||
37 | @Tag(name = "helprequests") | |
38 | @RequestMapping("/api/helprequests") | |
39 | @RestController | |
40 | @Slf4j | |
41 | public class HelpRequestController extends ApiController { | |
42 | ||
43 | @Autowired | |
44 | HelpRequestRepository helpRequestRepository; | |
45 | ||
46 | /** | |
47 | * List all UCSB dates | |
48 | * | |
49 | * @return an iterable of HelpRequest | |
50 | */ | |
51 | @Operation(summary= "List all help requests") | |
52 | @PreAuthorize("hasRole('ROLE_USER')") | |
53 | @GetMapping("/all") | |
54 | public Iterable<HelpRequest> allHelpRequests() { | |
55 | Iterable<HelpRequest> requests = helpRequestRepository.findAll(); | |
56 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return requests; |
57 | } | |
58 | ||
59 | ||
60 | /** | |
61 | * Get a single date by id | |
62 | * | |
63 | * @param id the id of the date | |
64 | * @return a UCSBDate | |
65 | */ | |
66 | @Operation(summary= "Get a single request") | |
67 | @PreAuthorize("hasRole('ROLE_USER')") | |
68 | @GetMapping("") | |
69 | public HelpRequest getById( | |
70 | @Parameter(name="id") @RequestParam Long id) { | |
71 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
72 |
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)); |
73 | ||
74 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED |
return helpRequest; |
75 | } | |
76 | ||
77 | ||
78 | /** | |
79 | * Create a help request | |
80 | * | |
81 | * @param requesterEmail the email of the requester | |
82 | * @param teamId the id of the team | |
83 | * @param tableOrBreakoutRoom whether its at a table or breakout room | |
84 | * @param explanation the details of request | |
85 | * @param solved whether request has been solved or not | |
86 | * @param requestTime the date and time of request in the format YYYY-mm-ddTHH:MM:SS | |
87 | * @return the saved helprequest | |
88 | */ | |
89 | @Operation(summary= "Create a help request") | |
90 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
91 | @PostMapping("/post") | |
92 | public HelpRequest postHelpRequest( | |
93 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
94 | @Parameter(name="teamId") @RequestParam String teamId, | |
95 | @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
96 | @Parameter(name="explanation") @RequestParam String explanation, | |
97 | @Parameter(name="solved") @RequestParam boolean solved, | |
98 | @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) | |
99 | throws JsonProcessingException { | |
100 | ||
101 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
102 | // See: https://www.baeldung.com/spring-date-parameters | |
103 | ||
104 | log.info("requestTime={}", requestTime); | |
105 | ||
106 | HelpRequest helpRequest = new HelpRequest(); | |
107 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
108 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
109 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
110 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
111 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
112 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
113 | ||
114 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
115 | ||
116 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return savedHelpRequest; |
117 | } | |
118 | ||
119 | ||
120 | /** | |
121 | * Delete a HelpRequest | |
122 | * | |
123 | * @param id the id of the request to delete | |
124 | * @return a message indicating the request was deleted | |
125 | */ | |
126 | @Operation(summary= "Delete a HelpRequest") | |
127 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
128 | @DeleteMapping("") | |
129 | public Object deleteHelpRequest( | |
130 | @Parameter(name="id") @RequestParam Long id) { | |
131 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
132 |
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)); |
133 | ||
134 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
135 |
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)); |
136 | } | |
137 | ||
138 | ||
139 | /** | |
140 | * Update a single request | |
141 | * | |
142 | * @param id id of the date to update | |
143 | * @param incoming the new request | |
144 | * @return the updated request object | |
145 | */ | |
146 | @Operation(summary= "Update a single request") | |
147 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
148 | @PutMapping("") | |
149 | public HelpRequest updateHelpRequest( | |
150 | @Parameter(name="id") @RequestParam Long id, | |
151 | @RequestBody @Valid HelpRequest incoming) { | |
152 | ||
153 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
154 |
1
1. lambda$updateHelpRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$updateHelpRequest$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
155 | ||
156 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
157 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
158 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
159 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
160 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
161 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
162 | ||
163 | helpRequestRepository.save(helpRequest); | |
164 | ||
165 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED |
return helpRequest; |
166 | } | |
167 | ||
168 | ||
169 | } | |
Mutations | ||
56 |
1.1 |
|
72 |
1.1 |
|
74 |
1.1 |
|
107 |
1.1 |
|
108 |
1.1 |
|
109 |
1.1 |
|
110 |
1.1 |
|
111 |
1.1 |
|
112 |
1.1 |
|
116 |
1.1 |
|
132 |
1.1 |
|
134 |
1.1 |
|
135 |
1.1 |
|
154 |
1.1 |
|
156 |
1.1 |
|
157 |
1.1 |
|
158 |
1.1 |
|
159 |
1.1 |
|
160 |
1.1 |
|
161 |
1.1 |
|
165 |
1.1 |