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 HelpRequest | |
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> helpRequests = helpRequestRepository.findAll(); | |
53 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return helpRequests; |
54 | } | |
55 | ||
56 | /** | |
57 | * Get a single help request by id | |
58 | * | |
59 | * @param id the id of the help request | |
60 | * @return a HelpRequest | |
61 | */ | |
62 | @Operation(summary = "Get a single help request") | |
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 help request | |
75 | * | |
76 | * @param requesterEmail the email of the requester | |
77 | * @param teamId the team ID | |
78 | * @param tableOrBreakoutRoom the table or breakout room | |
79 | * @param requestTime the request time | |
80 | * @param explanation the explanation for the request | |
81 | * @param solved whether the request is solved | |
82 | * @return the saved help request | |
83 | */ | |
84 | @Operation(summary = "Create a new help request") | |
85 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
86 | @PostMapping("/post") | |
87 | public HelpRequest postHelpRequest( | |
88 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
89 | @Parameter(name = "teamId") @RequestParam String teamId, | |
90 | @Parameter(name = "tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
91 | @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, | |
92 | @Parameter(name = "explanation") @RequestParam String explanation, | |
93 | @Parameter(name = "solved") @RequestParam boolean solved) | |
94 | throws JsonProcessingException { | |
95 | ||
96 | log.info("requestTime={}", requestTime); | |
97 | ||
98 | HelpRequest helpRequest = HelpRequest.builder() | |
99 | .requesterEmail(requesterEmail) | |
100 | .teamId(teamId) | |
101 | .tableOrBreakoutRoom(tableOrBreakoutRoom) | |
102 | .requestTime(requestTime) | |
103 | .explanation(explanation) | |
104 | .solved(solved) | |
105 | .build(); | |
106 | ||
107 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
108 | ||
109 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return savedHelpRequest; |
110 | } | |
111 | ||
112 | /** | |
113 | * Update a single help request | |
114 | * | |
115 | * @param id id of the help request to update | |
116 | * @param incoming the new help request data | |
117 | * @return the updated help request object | |
118 | */ | |
119 | @Operation(summary = "Update a single help request") | |
120 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
121 | @PutMapping("") | |
122 | public HelpRequest updateHelpRequest( | |
123 | @Parameter(name = "id") @RequestParam Long id, | |
124 | @RequestBody @Valid HelpRequest incoming) { | |
125 | ||
126 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
127 |
1
1. lambda$updateHelpRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$updateHelpRequest$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
128 | ||
129 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
130 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
131 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
132 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
133 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
134 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
135 | ||
136 | helpRequestRepository.save(helpRequest); | |
137 | ||
138 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED |
return helpRequest; |
139 | } | |
140 | ||
141 | /** | |
142 | * Delete a HelpRequest | |
143 | * | |
144 | * @param id the id of the help request to delete | |
145 | * @return a message indicating the help request was deleted | |
146 | */ | |
147 | @Operation(summary = "Delete a HelpRequest") | |
148 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
149 | @DeleteMapping("") | |
150 | public Object deleteHelpRequest( | |
151 | @Parameter(name = "id") @RequestParam Long id) { | |
152 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
153 |
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)); |
154 | ||
155 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
156 |
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)); |
157 | } | |
158 | } | |
Mutations | ||
53 |
1.1 |
|
68 |
1.1 |
|
70 |
1.1 |
|
109 |
1.1 |
|
127 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
131 |
1.1 |
|
132 |
1.1 |
|
133 |
1.1 |
|
134 |
1.1 |
|
138 |
1.1 |
|
153 |
1.1 |
|
155 |
1.1 |
|
156 |
1.1 |