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