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> dates = helpRequestRepository.findAll(); | |
53 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return dates; |
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 date") | |
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 = HelpRequest.builder() | |
102 | .requesterEmail(requesterEmail) | |
103 | .teamId(teamId) | |
104 | .tableOrBreakoutRoom(tableOrBreakoutRoom) | |
105 | .requestTime(requestTime) | |
106 | .explanation(explanation) | |
107 | .solved(solved) | |
108 | .build(); | |
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 HelpRequest to delete | |
119 | * @return a message indicating the HelpRequest 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 date | |
135 | * | |
136 | * @param id id of the date to update | |
137 | * @param incoming the new date | |
138 | * @return the updated date object | |
139 | */ | |
140 | @Operation(summary= "Update a single date") | |
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 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
HelpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
150 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
HelpRequest.setTeamId(incoming.getTeamId()); |
151 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
HelpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
152 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
HelpRequest.setRequestTime(incoming.getRequestTime()); |
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 | | |
156 | ||
157 | helpRequestRepository.save(HelpRequest); | |
158 | ||
159 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED |
return HelpRequest; |
160 | } | |
161 | } | |
Mutations | ||
53 |
1.1 |
|
68 |
1.1 |
|
70 |
1.1 |
|
112 |
1.1 |
|
127 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
148 |
1.1 |
|
149 |
1.1 |
|
150 |
1.1 |
|
151 |
1.1 |
|
152 |
1.1 |
|
153 |
1.1 |
|
154 |
1.1 |
|
159 |
1.1 |