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