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 | * This is a REST controller for Recommendation Request | |
31 | */ | |
32 | ||
33 | @Tag(name = "RecommendationRequest") | |
34 | @RequestMapping("/api/recommendationrequest") | |
35 | @RestController | |
36 | @Slf4j | |
37 | ||
38 | public class RecommendationRequestController extends ApiController { | |
39 | @Autowired | |
40 | RecommendationRequestRepository recommendationRequestRepository; | |
41 | | |
42 | /** | |
43 | * List all Recommendation Requests | |
44 | * | |
45 | * @return an iterable of RecommendationRequest | |
46 | */ | |
47 | @Operation(summary= "List all recommendation requests") | |
48 | @PreAuthorize("hasRole('ROLE_USER')") | |
49 | @GetMapping("/all") | |
50 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
51 | Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll(); | |
52 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED |
return requests; |
53 | } | |
54 | ||
55 | /** | |
56 | * Create a new Recommendation Request | |
57 | * | |
58 | * @param explanation | |
59 | * @param dateNeeded | |
60 | * @param requesterEmail | |
61 | * @param done | |
62 | * @param dateRequested | |
63 | * @param professorEmail | |
64 | * @return the created RecommendationRequest | |
65 | */ | |
66 | @Operation(summary = "Create a new recommendation request") | |
67 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
68 | @PostMapping("/post") | |
69 | ||
70 | public RecommendationRequest postRecommendationRequest( | |
71 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
72 | @Parameter(name = "explanation") @RequestParam String explanation, | |
73 | @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, | |
74 | @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, | |
75 | @Parameter(name = "done") @RequestParam boolean done, | |
76 | @Parameter(name = "professorEmail") @RequestParam String professorEmail) | |
77 | throws JsonProcessingException { | |
78 | ||
79 | log.info("Creating recommendation request: requester={}, professor={}, requestedDate={}, neededDate={}, doneStatus={}", | |
80 | requesterEmail, professorEmail, dateRequested, dateNeeded, done); | |
81 | ||
82 | RecommendationRequest rRequest = new RecommendationRequest(); | |
83 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
rRequest.setRequesterEmail(requesterEmail); |
84 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
rRequest.setExplanation(explanation); |
85 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
rRequest.setDateRequested(dateRequested); |
86 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
rRequest.setDateNeeded(dateNeeded); |
87 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
rRequest.setDone(done); |
88 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
rRequest.setProfessorEmail(professorEmail); |
89 | ||
90 | RecommendationRequest savedRecommendationRequest = recommendationRequestRepository.save(rRequest); | |
91 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED |
return savedRecommendationRequest; |
92 | } | |
93 | /** | |
94 | * Get a single recommendation request | |
95 | * | |
96 | * @param id the id of the recommendation request | |
97 | * @return a RecommendationRequest | |
98 | */ | |
99 | @Operation(summary= "Get a single recommendation request") | |
100 | @PreAuthorize("hasRole('ROLE_USER')") | |
101 | @GetMapping("") | |
102 | public RecommendationRequest getById( | |
103 | @Parameter(name="id") @RequestParam Long id) { | |
104 | RecommendationRequest recReq = recommendationRequestRepository.findById(id) | |
105 |
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)); |
106 | ||
107 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED |
return recReq; |
108 | } | |
109 | ||
110 | /** | |
111 | * Update a single recommendation request | |
112 | * | |
113 | * @param id id of the recommendation request to update | |
114 | * @param incoming the new recommendation request | |
115 | * @return the updated recommendation request object | |
116 | */ | |
117 | @Operation(summary= "Update a single recommendation request") | |
118 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
119 | @PutMapping("") | |
120 | public RecommendationRequest updateRecommendationRequest( | |
121 | @Parameter(name="id") @RequestParam Long id, | |
122 | @RequestBody @Valid RecommendationRequest incoming) { | |
123 | ||
124 | RecommendationRequest request = recommendationRequestRepository.findById(id) | |
125 |
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)); |
126 | ||
127 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
request.setRequesterEmail(incoming.getRequesterEmail()); |
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 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
request.setProfessorEmail(incoming.getProfessorEmail()); |
133 | ||
134 | recommendationRequestRepository.save(request); | |
135 | | |
136 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED |
return request; |
137 | } | |
138 | ||
139 | /** | |
140 | * Delete a recommendation request | |
141 | * | |
142 | * @param id the id of the recommendation request to delete | |
143 | * @return a message indicating the recommendation request was deleted | |
144 | */ | |
145 | @Operation(summary = "Delete a recommendation request") | |
146 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
147 | @DeleteMapping("") | |
148 | public Object deleteRecommendationRequest(@Parameter(name = "id") @RequestParam Long id) { | |
149 | ||
150 | RecommendationRequest toDelete = recommendationRequestRepository.findById(id) | |
151 |
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)); |
152 | ||
153 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(toDelete); |
154 | ||
155 |
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)); |
156 | } | |
157 | } | |
Mutations | ||
52 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
88 |
1.1 |
|
91 |
1.1 |
|
105 |
1.1 |
|
107 |
1.1 |
|
125 |
1.1 |
|
127 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
131 |
1.1 |
|
132 |
1.1 |
|
136 |
1.1 |
|
151 |
1.1 |
|
153 |
1.1 |
|
155 |
1.1 |