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 javax.validation.Valid; | |
27 | ||
28 | import java.time.LocalDateTime; | |
29 | ||
30 | @Tag(name = "RecommendationRequests") | |
31 | @RequestMapping("/api/recommendationrequests") | |
32 | @RestController | |
33 | @Slf4j | |
34 | public class RecommendationRequestsController extends ApiController { | |
35 | ||
36 | @Autowired | |
37 | RecommendationRequestRepository recommendationRequestRepository; | |
38 | ||
39 | @Operation(summary= "List all recommendation requests") | |
40 | @PreAuthorize("hasRole('ROLE_USER')") | |
41 | @GetMapping("/all") | |
42 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
43 | Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll(); | |
44 |
1
1. allRecommendationRequests : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::allRecommendationRequests → KILLED |
return requests; |
45 | } | |
46 | ||
47 | @Operation(summary= "Create a new recommendation request") | |
48 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
49 | @PostMapping("/post") | |
50 | public RecommendationRequest postRecommendationRequest( | |
51 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
52 | @Parameter(name="professorEmail") @RequestParam String professorEmail, | |
53 | @Parameter(name="explanation") @RequestParam String explanation, | |
54 | @Parameter(name="dateNeeded", description="in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601") | |
55 | @RequestParam("dateNeeded") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateNeeded, | |
56 | @Parameter(name="dateRequested", description="in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601") | |
57 | @RequestParam("dateRequested") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateRequested, | |
58 | @Parameter(name="done") @RequestParam boolean done) | |
59 | throws JsonProcessingException { | |
60 | ||
61 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
62 | // See: https://www.baeldung.com/spring-date-parameters | |
63 | ||
64 | // log.info("localDateTime={}", localDateTime); | |
65 | | |
66 | log.info("dateRequested={}", dateRequested); | |
67 | log.info("dateNeeded={}", dateNeeded); | |
68 | ||
69 | RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
70 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(requesterEmail); |
71 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(professorEmail); |
72 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(explanation); |
73 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(dateNeeded); |
74 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(dateRequested); |
75 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(done); |
76 | ||
77 | RecommendationRequest savedrRecommendationRequest = recommendationRequestRepository.save(recommendationRequest); | |
78 | ||
79 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::postRecommendationRequest → KILLED |
return savedrRecommendationRequest; |
80 | } | |
81 | ||
82 | @Operation(summary= "Get a single date") | |
83 | @PreAuthorize("hasRole('ROLE_USER')") | |
84 | @GetMapping("") | |
85 | public RecommendationRequest getById( | |
86 | @Parameter(name="id") @RequestParam Long id) { | |
87 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
88 |
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)); |
89 | ||
90 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::getById → KILLED |
return recommendationRequest; |
91 | } | |
92 | ||
93 | @Operation(summary= "Delete a RecommendationRequest") | |
94 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
95 | @DeleteMapping("") | |
96 | public Object deleteRecommendationRequest( | |
97 | @Parameter(name="id") @RequestParam Long id) { | |
98 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
99 |
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)); |
100 | ||
101 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(recommendationRequest); |
102 |
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)); |
103 | } | |
104 | ||
105 | @Operation(summary= "Update a single date") | |
106 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
107 | @PutMapping("") | |
108 | public RecommendationRequest updateRecommendationRequest( | |
109 | @Parameter(name="id") @RequestParam Long id, | |
110 | @RequestBody @Valid RecommendationRequest incoming) { | |
111 | ||
112 | RecommendationRequest recommendationRequest = recommendationRequestRepository.findById(id) | |
113 |
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)); |
114 | ||
115 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(incoming.getRequesterEmail()); |
116 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(incoming.getProfessorEmail()); |
117 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(incoming.getExplanation()); |
118 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(incoming.getDateNeeded()); |
119 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(incoming.getDateRequested()); |
120 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(incoming.getDone()); |
121 | ||
122 | recommendationRequestRepository.save(recommendationRequest); | |
123 | | |
124 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::updateRecommendationRequest → KILLED |
return recommendationRequest; |
125 | } | |
126 | } | |
Mutations | ||
44 |
1.1 |
|
70 |
1.1 |
|
71 |
1.1 |
|
72 |
1.1 |
|
73 |
1.1 |
|
74 |
1.1 |
|
75 |
1.1 |
|
79 |
1.1 |
|
88 |
1.1 |
|
90 |
1.1 |
|
99 |
1.1 |
|
101 |
1.1 |
|
102 |
1.1 |
|
113 |
1.1 |
|
115 |
1.1 |
|
116 |
1.1 |
|
117 |
1.1 |
|
118 |
1.1 |
|
119 |
1.1 |
|
120 |
1.1 |
|
124 |
1.1 |