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 | ||
8 | import io.swagger.v3.oas.annotations.Operation; | |
9 | import io.swagger.v3.oas.annotations.Parameter; | |
10 | import io.swagger.v3.oas.annotations.tags.Tag; | |
11 | import lombok.extern.slf4j.Slf4j; | |
12 | ||
13 | import com.fasterxml.jackson.core.JsonProcessingException; | |
14 | ||
15 | import org.springframework.beans.factory.annotation.Autowired; | |
16 | import org.springframework.format.annotation.DateTimeFormat; | |
17 | import org.springframework.security.access.prepost.PreAuthorize; | |
18 | import org.springframework.web.bind.annotation.DeleteMapping; | |
19 | import org.springframework.web.bind.annotation.GetMapping; | |
20 | import org.springframework.web.bind.annotation.PostMapping; | |
21 | import org.springframework.web.bind.annotation.PutMapping; | |
22 | import org.springframework.web.bind.annotation.RequestBody; | |
23 | import org.springframework.web.bind.annotation.RequestMapping; | |
24 | import org.springframework.web.bind.annotation.RequestParam; | |
25 | import org.springframework.web.bind.annotation.RestController; | |
26 | ||
27 | import java.time.LocalDateTime; | |
28 | ||
29 | import javax.validation.Valid; | |
30 | ||
31 | @Tag(name = "HelpRequests") | |
32 | @RequestMapping("/api/helprequests") | |
33 | @RestController | |
34 | @Slf4j | |
35 | public class HelpRequestController extends ApiController{ | |
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 new help request") | |
48 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
49 | @PostMapping("/post") | |
50 | public HelpRequest postHelpRequest( | |
51 | @Parameter(name="requesterEmail",description="Email of help requester",example="cgaucho@ucsb.edu") @RequestParam String requesterEmail, | |
52 | @Parameter(name="teamId",description="Team id",example="s22-5pm-3") @RequestParam String teamId, | |
53 | @Parameter(name="tableOrBreakoutRoom",description="Table or breakout room number",example="7") @RequestParam String tableOrBreakoutRoom, | |
54 | @Parameter(name="explanation",description="Description of help request",example="Need help with Swagger-ui") @RequestParam String explanation, | |
55 | @Parameter(name="solved",description="If request has been solved",example="false") @RequestParam boolean solved, | |
56 | @Parameter(name="requestTime", description="Time in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601",example="2022-04-20T17:35") @RequestParam("requestTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime requestTime) | |
57 | throws JsonProcessingException { | |
58 | ||
59 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
60 | // See: https://www.baeldung.com/spring-date-parameters | |
61 | ||
62 | log.info("requestTime={}", requestTime); | |
63 | ||
64 | HelpRequest helpRequest = new HelpRequest(); | |
65 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(requesterEmail); |
66 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(teamId); |
67 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(tableOrBreakoutRoom); |
68 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(explanation); |
69 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(solved); |
70 |
1
1. postHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(requestTime); |
71 | ||
72 | HelpRequest savedHelpRequest = helpRequestRepository.save(helpRequest); | |
73 | ||
74 |
1
1. postHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::postHelpRequest → KILLED |
return savedHelpRequest; |
75 | } | |
76 | ||
77 | @Operation(summary= "Get a single help request") | |
78 | @PreAuthorize("hasRole('ROLE_USER')") | |
79 | @GetMapping("") | |
80 | public HelpRequest getById( | |
81 | @Parameter(name="id") @RequestParam Long id) { | |
82 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
83 |
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)); |
84 | ||
85 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::getById → KILLED |
return helpRequest; |
86 | } | |
87 | | |
88 | @Operation(summary= "Update a single help request") | |
89 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
90 | @PutMapping("") | |
91 | public HelpRequest updateHelpRequest( | |
92 | @Parameter(name="id") @RequestParam Long id, | |
93 | @RequestBody @Valid HelpRequest incoming) { | |
94 | ||
95 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
96 |
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)); |
97 | ||
98 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequesterEmail → KILLED |
helpRequest.setRequesterEmail(incoming.getRequesterEmail()); |
99 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTeamId → KILLED |
helpRequest.setTeamId(incoming.getTeamId()); |
100 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setTableOrBreakoutRoom → KILLED |
helpRequest.setTableOrBreakoutRoom(incoming.getTableOrBreakoutRoom()); |
101 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setRequestTime → KILLED |
helpRequest.setRequestTime(incoming.getRequestTime()); |
102 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setExplanation → KILLED |
helpRequest.setExplanation(incoming.getExplanation()); |
103 |
1
1. updateHelpRequest : removed call to edu/ucsb/cs156/example/entities/HelpRequest::setSolved → KILLED |
helpRequest.setSolved(incoming.getSolved()); |
104 | ||
105 | helpRequestRepository.save(helpRequest); | |
106 | ||
107 |
1
1. updateHelpRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/HelpRequestController::updateHelpRequest → KILLED |
return helpRequest; |
108 | } | |
109 | ||
110 | @Operation(summary= "Delete a HelpRequest") | |
111 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
112 | @DeleteMapping("") | |
113 | public Object deleteHelpRequest( | |
114 | @Parameter(name="id") @RequestParam Long id) { | |
115 | HelpRequest helpRequest = helpRequestRepository.findById(id) | |
116 |
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)); |
117 | ||
118 |
1
1. deleteHelpRequest : removed call to edu/ucsb/cs156/example/repositories/HelpRequestRepository::delete → KILLED |
helpRequestRepository.delete(helpRequest); |
119 |
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)); |
120 | } | |
121 | } | |
Mutations | ||
44 |
1.1 |
|
65 |
1.1 |
|
66 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 |
|
69 |
1.1 |
|
70 |
1.1 |
|
74 |
1.1 |
|
83 |
1.1 |
|
85 |
1.1 |
|
96 |
1.1 |
|
98 |
1.1 |
|
99 |
1.1 |
|
100 |
1.1 |
|
101 |
1.1 |
|
102 |
1.1 |
|
103 |
1.1 |
|
107 |
1.1 |
|
116 |
1.1 |
|
118 |
1.1 |
|
119 |
1.1 |