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 javax.validation.Valid; | |
27 | ||
28 | import java.time.LocalDateTime; | |
29 | ||
30 | @Tag(name = "HelpRequests") | |
31 | @RequestMapping("/api/HelpRequest") | |
32 | @RestController | |
33 | @Slf4j | |
34 | public class HelpRequestController extends ApiController { | |
35 | ||
36 | @Autowired | |
37 | HelpRequestRepository helpRequestRepository; | |
38 | ||
39 | @Operation(summary= "List all help requests") | |
40 | @PreAuthorize("hasRole('ROLE_USER')") | |
41 | @GetMapping("/all") | |
42 | public Iterable<HelpRequest> allHelpRequests() { | |
43 | Iterable<HelpRequest> requests = helpRequestRepository.findAll(); | |
44 |
1
1. allHelpRequests : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return requests; |
45 | } | |
46 | ||
47 | @Operation(summary= "Create a help request") | |
48 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
49 | @PostMapping("/post") | |
50 | public HelpRequest postHelpRequest( | |
51 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
52 | @Parameter(name="teamId") @RequestParam String teamId, | |
53 | @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
54 | @Parameter(name="requestTime") @RequestParam("requestTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime requestTime, | |
55 | @Parameter(name="explanation") @RequestParam String explanation, | |
56 | @Parameter(name="solved") @RequestParam boolean solved | |
57 | ) | |
58 | throws JsonProcessingException { | |
59 | ||
60 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
61 | // See: https://www.baeldung.com/spring-date-parameters | |
62 | ||
63 | log.info("requestTime={}", requestTime); | |
64 | ||
65 | HelpRequest helpRequest = new HelpRequest(); | |
66 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
67 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
68 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
69 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
70 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
71 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
72 | ||
73 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
74 | ||
75 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return savedHelpRequest; |
76 | } | |
77 | | |
78 | @Operation(summary= "Get a single request") | |
79 | @PreAuthorize("hasRole('ROLE_USER')") | |
80 | @GetMapping("") | |
81 | public HelpRequest getById( | |
82 | @Parameter(name="id") @RequestParam Long id) { | |
83 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
84 |
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)); |
85 | ||
86 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED |
return helpRequest; |
87 | } | |
88 | ||
89 | @Operation(summary= "Delete a HelpRequest") | |
90 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
91 | @DeleteMapping("") | |
92 | public Object deleteHelpRequest( | |
93 | @Parameter(name="id") @RequestParam Long id) { | |
94 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
95 |
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)); |
96 | ||
97 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
98 |
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)); |
99 | } | |
100 | ||
101 | @Operation(summary= "Update a single request") | |
102 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
103 | @PutMapping("") | |
104 | public HelpRequest updateHelpRequest( | |
105 | @Parameter(name="id") @RequestParam Long id, | |
106 | @RequestBody @Valid HelpRequest incoming) { | |
107 | ||
108 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
109 |
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)); |
110 | ||
111 | | |
112 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
113 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
114 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
115 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
116 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
117 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
118 | ||
119 | helpRequestRepository.save(helpRequest); | |
120 | ||
121 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED |
return helpRequest; |
122 | } | |
123 | ||
124 | | |
125 | } | |
Mutations | ||
44 |
1.1 |
|
66 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 |
|
69 |
1.1 |
|
70 |
1.1 |
|
71 |
1.1 |
|
75 |
1.1 |
|
84 |
1.1 |
|
86 |
1.1 |
|
95 |
1.1 |
|
97 |
1.1 |
|
98 |
1.1 |
|
109 |
1.1 |
|
112 |
1.1 |
|
113 |
1.1 |
|
114 |
1.1 |
|
115 |
1.1 |
|
116 |
1.1 |
|
117 |
1.1 |
|
121 |
1.1 |