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