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.hibernate.mapping.TableOwner; | |
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 | /** | |
32 | * This is a REST controller for HelpRequest | |
33 | */ | |
34 | ||
35 | @Tag(name = "HelpRequest") | |
36 | @RequestMapping("/api/helprequest") | |
37 | @RestController | |
38 | @Slf4j | |
39 | ||
40 | public class HelpRequestController extends ApiController { | |
41 | @Autowired | |
42 | HelpRequestRepository helpRequestRepository; | |
43 | ||
44 | /** | |
45 | * List all help requests | |
46 | * | |
47 | * @return an iterable of HelpRequest | |
48 | */ | |
49 | @Operation(summary= "List all help requests") | |
50 | @PreAuthorize("hasRole('ROLE_USER')") | |
51 | @GetMapping("/all") | |
52 | public Iterable<HelpRequest> allHelpRequests() { | |
53 | Iterable<HelpRequest> requests = helpRequestRepository.findAll(); | |
54 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return requests; |
55 | } | |
56 | ||
57 | /** | |
58 | * Get a single request by id | |
59 | * | |
60 | * @param id the id of the request | |
61 | * @return a HelpRequest | |
62 | */ | |
63 | @Operation(summary= "Get a single request") | |
64 | @PreAuthorize("hasRole('ROLE_USER')") | |
65 | @GetMapping("") | |
66 | public HelpRequest getById( | |
67 | @Parameter(name="id") @RequestParam Long id) { | |
68 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
69 |
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)); |
70 | ||
71 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED |
return helpRequest; |
72 | } | |
73 | ||
74 | /** | |
75 | * Create a new HelpRequest | |
76 | * | |
77 | * @param requesterEmail; email of the requester | |
78 | * @param teamId ID of the requester's team | |
79 | * @param tableOrBreakoutRoom table/breakout room of requester | |
80 | * @param requestTime time of the help request | |
81 | * @param explanation the solution to the help request | |
82 | * @param solved flag to indicate status of the request | |
83 | * @return the saved help request | |
84 | */ | |
85 | @Operation(summary= "Create a new help request") | |
86 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
87 | @PostMapping("/post") | |
88 | public HelpRequest postHelpRequest( | |
89 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
90 | @Parameter(name="teamId") @RequestParam String teamId, | |
91 | @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
92 | @Parameter(name="explanation") @RequestParam String explanation, | |
93 | @Parameter(name="solved") @RequestParam boolean solved, | |
94 | @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) | |
95 | throws JsonProcessingException { | |
96 | ||
97 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
98 | // See: https://www.baeldung.com/spring-date-parameters | |
99 | ||
100 | log.info("requestTime={}", requestTime); | |
101 | ||
102 | HelpRequest helpRequest = new HelpRequest(); | |
103 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
104 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
105 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
106 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
107 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
108 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
109 | ||
110 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
111 | ||
112 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return savedHelpRequest; |
113 | } | |
114 | ||
115 | /** | |
116 | * Delete a HelpRequest | |
117 | * | |
118 | * @param id the id of the request to delete | |
119 | * @return a message indicating the request was deleted | |
120 | */ | |
121 | @Operation(summary= "Delete a HelpRequest") | |
122 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
123 | @DeleteMapping("") | |
124 | public Object deleteHelpRequest( | |
125 | @Parameter(name="id") @RequestParam Long id) { | |
126 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
127 |
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)); |
128 | ||
129 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
130 |
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)); |
131 | } | |
132 | ||
133 | /** | |
134 | * Update a single request | |
135 | * | |
136 | * @param id id of the request to update | |
137 | * @param incoming the new request | |
138 | * @return the updated request object | |
139 | */ | |
140 | @Operation(summary= "Update a single request") | |
141 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
142 | @PutMapping("") | |
143 | public HelpRequest updateHelpRequest( | |
144 | @Parameter(name="id") @RequestParam Long id, | |
145 | @RequestBody @Valid HelpRequest incoming) { | |
146 | ||
147 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
148 |
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)); |
149 | ||
150 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
151 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
152 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
153 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
154 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
155 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
156 | | |
157 | ||
158 | helpRequestRepository.save(helpRequest); | |
159 | ||
160 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED |
return helpRequest; |
161 | } | |
162 | ||
163 | ||
164 | } | |
Mutations | ||
54 |
1.1 |
|
69 |
1.1 |
|
71 |
1.1 |
|
103 |
1.1 |
|
104 |
1.1 |
|
105 |
1.1 |
|
106 |
1.1 |
|
107 |
1.1 |
|
108 |
1.1 |
|
112 |
1.1 |
|
127 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
148 |
1.1 |
|
150 |
1.1 |
|
151 |
1.1 |
|
152 |
1.1 |
|
153 |
1.1 |
|
154 |
1.1 |
|
155 |
1.1 |
|
160 |
1.1 |