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