1 | package edu.ucsb.cs156.example.controllers; | |
2 | ||
3 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
4 | import edu.ucsb.cs156.example.repositories.RecommendationRequestRepository; | |
5 | ||
6 | import io.swagger.v3.oas.annotations.Operation; | |
7 | import io.swagger.v3.oas.annotations.Parameter; | |
8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
9 | import lombok.extern.slf4j.Slf4j; | |
10 | ||
11 | import com.fasterxml.jackson.core.JsonProcessingException; | |
12 | ||
13 | import org.springframework.beans.factory.annotation.Autowired; | |
14 | import org.springframework.format.annotation.DateTimeFormat; | |
15 | import org.springframework.security.access.prepost.PreAuthorize; | |
16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
17 | import org.springframework.web.bind.annotation.GetMapping; | |
18 | import org.springframework.web.bind.annotation.PostMapping; | |
19 | import org.springframework.web.bind.annotation.PutMapping; | |
20 | import org.springframework.web.bind.annotation.RequestBody; | |
21 | import org.springframework.web.bind.annotation.RequestMapping; | |
22 | import org.springframework.web.bind.annotation.RequestParam; | |
23 | import org.springframework.web.bind.annotation.RestController; | |
24 | ||
25 | import jakarta.validation.Valid; | |
26 | ||
27 | import edu.ucsb.cs156.example.entities.RecommendationRequest; | |
28 | ||
29 | import java.time.LocalDateTime; | |
30 | @Tag(name = "recommendationRequests") | |
31 | @RequestMapping("/api/recommendationrequests") | |
32 | @RestController | |
33 | @Slf4j | |
34 | public class RecommendationRequestsController extends ApiController { | |
35 | @Autowired | |
36 | RecommendationRequestRepository recommendationRequestRepository; | |
37 | ||
38 | @Operation(summary= "List all recommendation requests") | |
39 | @PreAuthorize("hasRole('ROLE_USER')") | |
40 | @GetMapping("/all") | |
41 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
42 | Iterable<RecommendationRequest> reqs = recommendationRequestRepository.findAll(); | |
43 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::allRecommendationRequests → KILLED |
return reqs; |
44 | } | |
45 | ||
46 | @Operation(summary= "Create a new recommendation request") | |
47 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
48 | @PostMapping("/post") | |
49 | public RecommendationRequest postRecommendationRequest( | |
50 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
51 | @Parameter(name="professorEmail") @RequestParam String professorEmail, | |
52 | @Parameter(name="explanation") @RequestParam String explanation, | |
53 | | |
54 | @Parameter(name="dateRequested", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
55 | @RequestParam("dateRequested") | |
56 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
57 | LocalDateTime dateRequested, | |
58 | | |
59 | @Parameter(name="dateNeeded", description="date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
60 | @RequestParam("dateNeeded") | |
61 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
62 | LocalDateTime dateNeeded, | |
63 | ||
64 | @Parameter(name="doneBool") @RequestParam boolean doneBool | |
65 | ) | |
66 | ||
67 | throws JsonProcessingException { | |
68 | ||
69 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
70 | // See: https://www.baeldung.com/spring-date-parameters | |
71 | ||
72 | log.info("localDateTime1={}", dateRequested); | |
73 | log.info("localDateTime2={}", dateNeeded); | |
74 | ||
75 | RecommendationRequest req = new RecommendationRequest(); | |
76 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
req.setRequesterEmail(requesterEmail); |
77 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
req.setProfessorEmail(professorEmail); |
78 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
req.setExplanation(explanation); |
79 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
req.setDateRequested(dateRequested); |
80 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
req.setDateNeeded(dateNeeded); |
81 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
req.setDone(doneBool); |
82 | RecommendationRequest savedReq = recommendationRequestRepository.save(req); | |
83 | ||
84 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::postRecommendationRequest → KILLED |
return savedReq; |
85 | } | |
86 | ||
87 | /** | |
88 | * Get a single request by id | |
89 | * | |
90 | * @param id the id of the request | |
91 | * @return a RecommendationRequest | |
92 | */ | |
93 | @Operation(summary= "Get a single recommendation request") | |
94 | @PreAuthorize("hasRole('ROLE_USER')") | |
95 | @GetMapping("") | |
96 | public RecommendationRequest getById( | |
97 | @Parameter(name="id") @RequestParam Long id) { | |
98 | RecommendationRequest req = recommendationRequestRepository.findById(id) | |
99 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
100 | ||
101 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::getById → KILLED |
return req; |
102 | } | |
103 | ||
104 | /** | |
105 | * Delete a RecommendationRequest | |
106 | * | |
107 | * @param id the id of the req | |
108 | * @return a message indicating the req was deleted | |
109 | */ | |
110 | @Operation(summary= "Delete a RecommendationRequest") | |
111 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
112 | @DeleteMapping("") | |
113 | public Object deleteRecommendationRequest( | |
114 | @Parameter(name="id") @RequestParam Long id) { | |
115 | RecommendationRequest req = recommendationRequestRepository.findById(id) | |
116 |
1
1. lambda$deleteRecommendationRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$deleteRecommendationRequest$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
117 | ||
118 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(req); |
119 |
1
1. deleteRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::deleteRecommendationRequest → KILLED |
return genericMessage("RecommendationRequest with id %s deleted".formatted(id)); |
120 | } | |
121 | ||
122 | /** | |
123 | * Update a single recommendation request | |
124 | * | |
125 | * @param id id of the req to update | |
126 | * @param incoming the new req | |
127 | * @return the updated req object | |
128 | */ | |
129 | @Operation(summary= "Update a single RecommendationRequest") | |
130 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
131 | @PutMapping("") | |
132 | public RecommendationRequest updateRecommendationRequest( | |
133 | @Parameter(name="id") @RequestParam Long id, | |
134 | @RequestBody @Valid RecommendationRequest incoming) { | |
135 | ||
136 | RecommendationRequest req = recommendationRequestRepository.findById(id) | |
137 |
1
1. lambda$updateRecommendationRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$updateRecommendationRequest$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
138 | ||
139 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
req.setDateNeeded(incoming.getDateNeeded()); |
140 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
req.setDateRequested(incoming.getDateRequested()); |
141 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
req.setDone(incoming.getDone()); |
142 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
req.setProfessorEmail(incoming.getProfessorEmail()); |
143 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
req.setRequesterEmail(incoming.getRequesterEmail()); |
144 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
req.setExplanation(incoming.getExplanation()); |
145 | ||
146 | recommendationRequestRepository.save(req); | |
147 | ||
148 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::updateRecommendationRequest → KILLED |
return req; |
149 | } | |
150 | | |
151 | } | |
Mutations | ||
43 |
1.1 |
|
76 |
1.1 |
|
77 |
1.1 |
|
78 |
1.1 |
|
79 |
1.1 |
|
80 |
1.1 |
|
81 |
1.1 |
|
84 |
1.1 |
|
99 |
1.1 |
|
101 |
1.1 |
|
116 |
1.1 |
|
118 |
1.1 |
|
119 |
1.1 |
|
137 |
1.1 |
|
139 |
1.1 |
|
140 |
1.1 |
|
141 |
1.1 |
|
142 |
1.1 |
|
143 |
1.1 |
|
144 |
1.1 |
|
148 |
1.1 |