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