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 | @Tag(name = "RecommendationRequest") | |
32 | @RequestMapping("/api/recommendationrequests") | |
33 | @RestController | |
34 | @Slf4j | |
35 | public class RecommendationRequestController extends ApiController { | |
36 | @Autowired | |
37 | RecommendationRequestRepository recommendationRequestRepository; | |
38 | ||
39 | | |
40 | @Operation(summary= "List all recommendation requests") | |
41 | @PreAuthorize("hasRole('ROLE_USER')") | |
42 | @GetMapping("/all") | |
43 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
44 | Iterable<RecommendationRequest> requests = recommendationRequestRepository.findAll(); | |
45 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → KILLED |
return requests; |
46 | } | |
47 | ||
48 | @Operation(summary= "Get a single date") | |
49 | @PreAuthorize("hasRole('ROLE_USER')") | |
50 | @GetMapping("") | |
51 | public RecommendationRequest getById( | |
52 | @Parameter(name="id") @RequestParam Long id) { | |
53 | RecommendationRequest request = recommendationRequestRepository.findById(id) | |
54 |
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)); |
55 | ||
56 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED |
return request; |
57 | } | |
58 | ||
59 | @Operation(summary= "Delete a RecommendationRequest") | |
60 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
61 | @DeleteMapping("") | |
62 | public Object deleteRecommendationRequest( | |
63 | @Parameter(name="id") @RequestParam Long id) { | |
64 | RecommendationRequest request = recommendationRequestRepository.findById(id) | |
65 |
1
1. lambda$deleteRecommendationRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$deleteRecommendationRequest$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
66 | ||
67 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequestRepository.delete(request); |
68 |
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)); |
69 | } | |
70 | ||
71 | @Operation(summary= "Create a new request") | |
72 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
73 | @PostMapping("/post") | |
74 | public RecommendationRequest postRecommendationRequest( | |
75 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
76 | @Parameter(name="professorEmail") @RequestParam String professorEmail, | |
77 | @Parameter(name="explanation") @RequestParam String explanation, | |
78 | @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, | |
79 | @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, | |
80 | @Parameter(name="done") @RequestParam boolean done | |
81 | ) | |
82 | throws JsonProcessingException { | |
83 | ||
84 | RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
85 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
recommendationRequest.setRequesterEmail(requesterEmail); |
86 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
recommendationRequest.setProfessorEmail(professorEmail); |
87 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
recommendationRequest.setExplanation(explanation); |
88 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
recommendationRequest.setDateRequested(dateRequested); |
89 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
recommendationRequest.setDateNeeded(dateNeeded); |
90 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
recommendationRequest.setDone(done); |
91 | ||
92 | RecommendationRequest savedRecommendationRequest = recommendationRequestRepository.save(recommendationRequest); | |
93 | ||
94 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → KILLED |
return savedRecommendationRequest; |
95 | } | |
96 | ||
97 | @Operation(summary= "Update a single date") | |
98 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
99 | @PutMapping("") | |
100 | public RecommendationRequest updateRecommendationRequest( | |
101 | @Parameter(name="id") @RequestParam Long id, | |
102 | @RequestBody @Valid RecommendationRequest incoming) { | |
103 | ||
104 | RecommendationRequest request = recommendationRequestRepository.findById(id) | |
105 |
1
1. lambda$updateRecommendationRequest$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$updateRecommendationRequest$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
106 | ||
107 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
request.setRequesterEmail(incoming.getRequesterEmail()); |
108 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
request.setProfessorEmail(incoming.getProfessorEmail()); |
109 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
request.setExplanation(incoming.getExplanation()); |
110 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
request.setDateRequested(incoming.getDateRequested()); |
111 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
request.setDateNeeded(incoming.getDateNeeded()); |
112 |
1
1. updateRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
request.setDone(incoming.getDone()); |
113 | ||
114 | recommendationRequestRepository.save(request); | |
115 | ||
116 |
1
1. updateRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRecommendationRequest → KILLED |
return request; |
117 | } | |
118 | } | |
Mutations | ||
45 |
1.1 |
|
54 |
1.1 |
|
56 |
1.1 |
|
65 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
87 |
1.1 |
|
88 |
1.1 |
|
89 |
1.1 |
|
90 |
1.1 |
|
94 |
1.1 |
|
105 |
1.1 |
|
107 |
1.1 |
|
108 |
1.1 |
|
109 |
1.1 |
|
110 |
1.1 |
|
111 |
1.1 |
|
112 |
1.1 |
|
116 |
1.1 |