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