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