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 | import edu.ucsb.cs156.example.repositories.UCSBDateRepository; | |
8 | ||
9 | import io.swagger.v3.oas.annotations.Operation; | |
10 | import io.swagger.v3.oas.annotations.Parameter; | |
11 | import io.swagger.v3.oas.annotations.tags.Tag; | |
12 | import lombok.extern.slf4j.Slf4j; | |
13 | ||
14 | import com.fasterxml.jackson.core.JsonProcessingException; | |
15 | ||
16 | import org.springframework.beans.factory.annotation.Autowired; | |
17 | import org.springframework.format.annotation.DateTimeFormat; | |
18 | import org.springframework.security.access.method.P; | |
19 | import org.springframework.security.access.prepost.PreAuthorize; | |
20 | import org.springframework.web.bind.annotation.DeleteMapping; | |
21 | import org.springframework.web.bind.annotation.GetMapping; | |
22 | import org.springframework.web.bind.annotation.PostMapping; | |
23 | import org.springframework.web.bind.annotation.PutMapping; | |
24 | import org.springframework.web.bind.annotation.RequestBody; | |
25 | import org.springframework.web.bind.annotation.RequestMapping; | |
26 | import org.springframework.web.bind.annotation.RequestParam; | |
27 | import org.springframework.web.bind.annotation.RestController; | |
28 | ||
29 | import jakarta.validation.Valid; | |
30 | ||
31 | import java.time.LocalDateTime; | |
32 | ||
33 | /** | |
34 | * This is a REST controller for RecommendationRequests | |
35 | */ | |
36 | ||
37 | @Tag(name = "RecommendationRequests") | |
38 | @RequestMapping("/api/recommendationrequests") | |
39 | @RestController | |
40 | @Slf4j | |
41 | public class RecommendationRequestController extends ApiController{ | |
42 | @Autowired | |
43 | RecommendationRequestRepository recommendationRequestRepository; | |
44 | ||
45 | /** | |
46 | * List all UCSB dates | |
47 | * | |
48 | * @return an iterable of UCSBDate | |
49 | */ | |
50 | @Operation(summary= "List all recommendation requests") | |
51 | @PreAuthorize("hasRole('ROLE_USER')") | |
52 | @GetMapping("/all") | |
53 | public Iterable<RecommendationRequest> allRecommendationRequests() { | |
54 | Iterable<RecommendationRequest> recommendationRequests = recommendationRequestRepository.findAll(); | |
55 |
1
1. allRecommendationRequests : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecommendationRequests → NO_COVERAGE |
return recommendationRequests; |
56 | } | |
57 | ||
58 | /** | |
59 | * Create a new recommendation request | |
60 | * | |
61 | * @param requesterEmail the email of the requester | |
62 | * @param professorEmail the email of the professor | |
63 | * @param explanation the explanation of the request | |
64 | * @param dateRequested the date the request was made | |
65 | * @param dateNeeded the date the request is needed | |
66 | * @param done whether the request is done | |
67 | * | |
68 | * @return the saved rec request | |
69 | */ | |
70 | @Operation(summary= "Create a new recommendation request") | |
71 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
72 | @PostMapping("/post") | |
73 | public RecommendationRequest postRecommendationRequest( | |
74 | @Parameter(name="requesterEmail") @RequestParam String requesterEmail, | |
75 | @Parameter(name="professorEmail") @RequestParam String professorEmail, | |
76 | @Parameter(name="explanation") @RequestParam String explanation, | |
77 | @Parameter(name="dateRequested (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, | |
78 | @Parameter(name="dateNeeded (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, | |
79 | @Parameter(name="done") @RequestParam boolean done) | |
80 | throws JsonProcessingException { | |
81 | ||
82 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
83 | // See: https://www.baeldung.com/spring-date-parameters | |
84 | ||
85 | log.info("dateRequested={}", dateRequested); | |
86 | log.info("dateNeeded={}", dateNeeded); | |
87 | ||
88 | RecommendationRequest recommendationRequest = new RecommendationRequest(); | |
89 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → NO_COVERAGE |
recommendationRequest.setRequesterEmail(requesterEmail); |
90 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → NO_COVERAGE |
recommendationRequest.setProfessorEmail(professorEmail); |
91 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → NO_COVERAGE |
recommendationRequest.setExplanation(explanation); |
92 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → NO_COVERAGE |
recommendationRequest.setDateRequested(dateRequested); |
93 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → NO_COVERAGE |
recommendationRequest.setDateNeeded(dateNeeded); |
94 |
1
1. postRecommendationRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → NO_COVERAGE |
recommendationRequest.setDone(done); |
95 | ||
96 | RecommendationRequest savedRecommendationRequest = recommendationRequestRepository.save(recommendationRequest); | |
97 | ||
98 |
1
1. postRecommendationRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecommendationRequest → NO_COVERAGE |
return savedRecommendationRequest; |
99 | } | |
100 | } | |
Mutations | ||
55 |
1.1 |
|
89 |
1.1 |
|
90 |
1.1 |
|
91 |
1.1 |
|
92 |
1.1 |
|
93 |
1.1 |
|
94 |
1.1 |
|
98 |
1.1 |