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