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