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 | import javax.validation.Valid; | |
26 | ||
27 | import java.time.LocalDateTime; | |
28 | ||
29 | @Tag(name = "HelpRequest") | |
30 | @RequestMapping("/api/helprequest") | |
31 | @RestController | |
32 | @Slf4j | |
33 | public class HelpRequestController extends ApiController{ | |
34 | @Autowired | |
35 | HelpRequestRepository helpRequestRepository; | |
36 | ||
37 | @Operation(summary= "Get all records in the table and return as a JSON array") | |
38 | @PreAuthorize("hasRole('ROLE_USER')") | |
39 | @GetMapping("/all") | |
40 | public Iterable<HelpRequest> allHelpRequests() { | |
41 | Iterable<HelpRequest> requests = helpRequestRepository.findAll(); | |
42 |
1
1. allHelpRequests : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::allHelpRequests → KILLED |
return requests; |
43 | } | |
44 | ||
45 | @Operation(summary= "Create a new row in the table and return the data as JSON") | |
46 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
47 | @PostMapping("/post") | |
48 | public HelpRequest postHelpRequest( | |
49 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
50 | @Parameter(name="teamId") @RequestParam String teamId, | |
51 | @Parameter(name="tableOrBreakoutRoom") @RequestParam String tableOrBreakoutRoom, | |
52 | @Parameter(name="explanation") @RequestParam String explanation, | |
53 | @Parameter(name="solved") @RequestParam Boolean solved, | |
54 | @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) | |
55 | throws JsonProcessingException { | |
56 | ||
57 | log.info("localDateTime={}", requestTime); | |
58 | HelpRequest helpRequest = new HelpRequest(); | |
59 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
60 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
61 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
62 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
63 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
64 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
65 | ||
66 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
67 | ||
68 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return savedHelpRequest; |
69 | } | |
70 | ||
71 | @Operation(summary= "Get a single help request") | |
72 | @PreAuthorize("hasRole('ROLE_USER')") | |
73 | @GetMapping("") | |
74 | public HelpRequest getById( | |
75 | @Parameter(name="id") @RequestParam Long id) { | |
76 | HelpRequest request = helpRequestRepository.findById(id) | |
77 |
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)); |
78 | ||
79 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED |
return request; |
80 | } | |
81 | ||
82 | @Operation(summary= "Delete a help request") | |
83 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
84 | @DeleteMapping("") | |
85 | public Object deleteUCSBDate( | |
86 | @Parameter(name="id") @RequestParam Long id) { | |
87 | HelpRequest request = helpRequestRepository.findById(id) | |
88 |
1
1. lambda$deleteUCSBDate$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$deleteUCSBDate$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
89 | ||
90 |
1
1. deleteUCSBDate : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(request); |
91 |
1
1. deleteUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::deleteUCSBDate → KILLED |
return genericMessage("HelpRequest with id %s deleted".formatted(id)); |
92 | } | |
93 | ||
94 | @Operation(summary= "Update a single help request") | |
95 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
96 | @PutMapping("") | |
97 | public HelpRequest updateUCSBDate( | |
98 | @Parameter(name="id") @RequestParam Long id, | |
99 | @RequestBody @Valid HelpRequest incoming) { | |
100 | ||
101 | HelpRequest request = helpRequestRepository.findById(id) | |
102 |
1
1. lambda$updateUCSBDate$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::lambda$updateUCSBDate$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(HelpRequest.class, id)); |
103 | ||
104 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
request.setExplanation(incoming.getExplanation()); |
105 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
request.setRequestTime(incoming.getRequestTime()); |
106 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
request.setRequesterEmail(incoming.getRequesterEmail()); |
107 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
request.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
108 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
request.setTeamId(incoming.getTeamId()); |
109 |
1
1. updateUCSBDate : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
request.setSolved(incoming.getSolved()); |
110 | ||
111 | helpRequestRepository.save(request); | |
112 | ||
113 |
1
1. updateUCSBDate : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateUCSBDate → KILLED |
return request; |
114 | } | |
115 | } | |
Mutations | ||
42 |
1.1 |
|
59 |
1.1 |
|
60 |
1.1 |
|
61 |
1.1 |
|
62 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |
|
68 |
1.1 |
|
77 |
1.1 |
|
79 |
1.1 |
|
88 |
1.1 |
|
90 |
1.1 |
|
91 |
1.1 |
|
102 |
1.1 |
|
104 |
1.1 |
|
105 |
1.1 |
|
106 |
1.1 |
|
107 |
1.1 |
|
108 |
1.1 |
|
109 |
1.1 |
|
113 |
1.1 |