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