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