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 | @Tag(name = "HelpRequest") | |
32 | @RequestMapping("/api/helprequest") | |
33 | @RestController | |
34 | @Slf4j | |
35 | public class HelpRequestController extends ApiController { | |
36 | ||
37 | @Autowired | |
38 | HelpRequestRepository helpRequestRepository; | |
39 | ||
40 | @Operation(summary= "List all help requests") | |
41 | @PreAuthorize("hasRole('ROLE_USER')") | |
42 | @GetMapping("/all") | |
43 | public Iterable<HelpRequest> allHelpRequests() { | |
44 | Iterable<HelpRequest> requests = helpRequestRepository.findAll(); | |
45 |
1
1. allHelpRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return requests; |
46 | } | |
47 | ||
48 | /** | |
49 | * Get a single date by id | |
50 | * | |
51 | * @param id the id of the date | |
52 | * @return a UCSBDate | |
53 | */ | |
54 | @Operation(summary= "Get a single help request") | |
55 | @PreAuthorize("hasRole('ROLE_USER')") | |
56 | @GetMapping("") | |
57 | public HelpRequest getById( | |
58 | @Parameter(name="id") @RequestParam Long id) { | |
59 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
60 |
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)); |
61 | ||
62 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED |
return helpRequest; |
63 | } | |
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="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, | |
73 | @Parameter(name="explanation") @RequestParam String explanation, | |
74 | @Parameter(name="solved") @RequestParam Boolean solved) | |
75 | throws JsonProcessingException { | |
76 | ||
77 | log.info("requestTime={}", requestTime); | |
78 | ||
79 | HelpRequest helpRequest = new HelpRequest(); | |
80 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
81 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
82 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
83 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
84 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
85 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
86 | ||
87 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
88 | ||
89 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return savedHelpRequest; |
90 | } | |
91 | ||
92 | ||
93 | @Operation(summary= "Delete a HelpRequest") | |
94 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
95 | @DeleteMapping("") | |
96 | public Object deleteHelpRequest( | |
97 | @Parameter(name="id") @RequestParam Long id) { | |
98 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
99 |
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)); |
100 | ||
101 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
102 |
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)); |
103 | } | |
104 | ||
105 | ||
106 | @Operation(summary= "Update a single help request") | |
107 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
108 | @PutMapping("") | |
109 | public HelpRequest updateHelpRequest( | |
110 | @Parameter(name="id") @RequestParam Long id, | |
111 | @RequestBody @Valid HelpRequest incoming) { | |
112 | ||
113 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
114 |
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)); |
115 | ||
116 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
117 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
118 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
119 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
120 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
121 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
122 | ||
123 | helpRequestRepository.save(helpRequest); | |
124 | ||
125 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED |
return helpRequest; |
126 | } | |
127 | ||
128 | ||
129 | ||
130 | ||
131 | } | |
Mutations | ||
45 |
1.1 |
|
60 |
1.1 |
|
62 |
1.1 |
|
80 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
89 |
1.1 |
|
99 |
1.1 |
|
101 |
1.1 |
|
102 |
1.1 |
|
114 |
1.1 |
|
116 |
1.1 |
|
117 |
1.1 |
|
118 |
1.1 |
|
119 |
1.1 |
|
120 |
1.1 |
|
121 |
1.1 |
|
125 |
1.1 |