| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import com.fasterxml.jackson.core.JsonProcessingException; | |
| 4 | import edu.ucsb.cs156.example.entities.RecommendationRequest; | |
| 5 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs156.example.repositories.RecommendationRequestRepository; | |
| 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 jakarta.validation.Valid; | |
| 11 | import java.time.LocalDateTime; | |
| 12 | import lombok.extern.slf4j.Slf4j; | |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | import org.springframework.format.annotation.DateTimeFormat; | |
| 15 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 16 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 17 | import org.springframework.web.bind.annotation.GetMapping; | |
| 18 | import org.springframework.web.bind.annotation.PostMapping; | |
| 19 | import org.springframework.web.bind.annotation.PutMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestBody; | |
| 21 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestParam; | |
| 23 | import org.springframework.web.bind.annotation.RestController; | |
| 24 | ||
| 25 | /** This is a REST controller for requests */ | |
| 26 | @Tag(name = "RecommendationRequest") | |
| 27 | @RequestMapping("/api/recommendationrequest") | |
| 28 | @RestController | |
| 29 | @Slf4j | |
| 30 | public class RecommendationRequestController extends ApiController { | |
| 31 | ||
| 32 | @Autowired RecommendationRequestRepository recommendationRequest; | |
| 33 | ||
| 34 | /** | |
| 35 | * List all records in table | |
| 36 | * | |
| 37 | * @return an iterable of records | |
| 38 | */ | |
| 39 | @Operation(summary = "List all records") | |
| 40 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 41 | @GetMapping("/all") | |
| 42 | public Iterable<RecommendationRequest> allRecords() { | |
| 43 | Iterable<RecommendationRequest> records = recommendationRequest.findAll(); | |
| 44 |
1
1. allRecords : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestController::allRecords → KILLED |
return records; |
| 45 | } | |
| 46 | ||
| 47 | /** | |
| 48 | * Get a single date by id | |
| 49 | * | |
| 50 | * @param id the id of the date | |
| 51 | * @return a record | |
| 52 | */ | |
| 53 | @Operation(summary = "Get a single record") | |
| 54 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 55 | @GetMapping("") | |
| 56 | public RecommendationRequest getById(@Parameter(name = "id") @RequestParam Long id) { | |
| 57 | RecommendationRequest record = | |
| 58 | recommendationRequest | |
| 59 | .findById(id) | |
| 60 |
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)); |
| 61 | ||
| 62 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::getById → KILLED |
return record; |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * Create a new record | |
| 67 | * | |
| 68 | * @param requesterEmail | |
| 69 | * @param professorEmail | |
| 70 | * @param explanation | |
| 71 | * @param dateRequested | |
| 72 | * @param dateNeeded | |
| 73 | * @param done | |
| 74 | * @return the saved record | |
| 75 | */ | |
| 76 | @Operation(summary = "Create a new record") | |
| 77 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 78 | @PostMapping("/post") | |
| 79 | public RecommendationRequest postRecord( | |
| 80 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
| 81 | @Parameter(name = "professorEmail") @RequestParam String professorEmail, | |
| 82 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 83 | @Parameter(name = "dateNeeded") @RequestParam LocalDateTime dateNeeded, | |
| 84 | @Parameter(name = "done") @RequestParam Boolean done, | |
| 85 | @Parameter( | |
| 86 | name = "dateRequested", | |
| 87 | description = | |
| 88 | "date (in iso format, e.g. YYYY-mm-ddTHH:MM:SS; see https://en.wikipedia.org/wiki/ISO_8601)") | |
| 89 | @RequestParam("dateRequested") | |
| 90 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 91 | LocalDateTime dateRequested) | |
| 92 | throws JsonProcessingException { | |
| 93 | ||
| 94 | // For an explanation of @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) | |
| 95 | // See: https://www.baeldung.com/spring-date-parameters | |
| 96 | ||
| 97 | log.info("localDateTime={}", dateRequested); | |
| 98 | ||
| 99 | RecommendationRequest record = new RecommendationRequest(); | |
| 100 |
1
1. postRecord : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
record.setRequesterEmail(requesterEmail); |
| 101 |
1
1. postRecord : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
record.setProfessorEmail(professorEmail); |
| 102 |
1
1. postRecord : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
record.setExplanation(explanation); |
| 103 |
1
1. postRecord : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
record.setDateRequested(dateRequested); |
| 104 |
1
1. postRecord : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
record.setDateNeeded(dateNeeded); |
| 105 |
1
1. postRecord : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
record.setDone(done); |
| 106 | RecommendationRequest savedRecRequest = recommendationRequest.save(record); | |
| 107 | ||
| 108 |
1
1. postRecord : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::postRecord → KILLED |
return savedRecRequest; |
| 109 | } | |
| 110 | ||
| 111 | /** | |
| 112 | * Update a single date | |
| 113 | * | |
| 114 | * @param id id of the request to update | |
| 115 | * @param incoming the new rerquest | |
| 116 | * @return the updated request object | |
| 117 | */ | |
| 118 | @Operation(summary = "Update a single request") | |
| 119 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 120 | @PutMapping("") | |
| 121 | public RecommendationRequest updateRequest( | |
| 122 | @Parameter(name = "id") @RequestParam Long id, | |
| 123 | @RequestBody @Valid RecommendationRequest incoming) { | |
| 124 | ||
| 125 | RecommendationRequest request1 = | |
| 126 | recommendationRequest | |
| 127 | .findById(id) | |
| 128 |
1
1. lambda$updateRequest$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::lambda$updateRequest$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequest.class, id)); |
| 129 | ||
| 130 |
1
1. updateRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setRequesterEmail → KILLED |
request1.setRequesterEmail(incoming.getRequesterEmail()); |
| 131 |
1
1. updateRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setProfessorEmail → KILLED |
request1.setProfessorEmail(incoming.getProfessorEmail()); |
| 132 |
1
1. updateRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setExplanation → KILLED |
request1.setExplanation(incoming.getExplanation()); |
| 133 |
1
1. updateRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateRequested → KILLED |
request1.setDateRequested(incoming.getDateRequested()); |
| 134 |
1
1. updateRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDateNeeded → KILLED |
request1.setDateNeeded(incoming.getDateNeeded()); |
| 135 |
1
1. updateRequest : removed call to edu/ucsb/cs156/example/entities/RecommendationRequest::setDone → KILLED |
request1.setDone(incoming.getDone()); |
| 136 | ; | |
| 137 | recommendationRequest.save(request1); | |
| 138 | ||
| 139 |
1
1. updateRequest : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestController::updateRequest → KILLED |
return request1; |
| 140 | } | |
| 141 | ||
| 142 | /** | |
| 143 | * Delete a RecommendationRequest | |
| 144 | * | |
| 145 | * @param id the id of the request to delete | |
| 146 | * @return a message indicating the request was deleted | |
| 147 | */ | |
| 148 | @Operation(summary = "Delete a RecommendationRequest") | |
| 149 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 150 | @DeleteMapping("") | |
| 151 | public Object deleteRecommendationRequest(@Parameter(name = "id") @RequestParam Long id) { | |
| 152 | RecommendationRequest record2 = | |
| 153 | recommendationRequest | |
| 154 | .findById(id) | |
| 155 |
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)); |
| 156 | ||
| 157 |
1
1. deleteRecommendationRequest : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestRepository::delete → KILLED |
recommendationRequest.delete(record2); |
| 158 |
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)); |
| 159 | } | |
| 160 | } | |
Mutations | ||
| 44 |
1.1 |
|
| 60 |
1.1 |
|
| 62 |
1.1 |
|
| 100 |
1.1 |
|
| 101 |
1.1 |
|
| 102 |
1.1 |
|
| 103 |
1.1 |
|
| 104 |
1.1 |
|
| 105 |
1.1 |
|
| 108 |
1.1 |
|
| 128 |
1.1 |
|
| 130 |
1.1 |
|
| 131 |
1.1 |
|
| 132 |
1.1 |
|
| 133 |
1.1 |
|
| 134 |
1.1 |
|
| 135 |
1.1 |
|
| 139 |
1.1 |
|
| 155 |
1.1 |
|
| 157 |
1.1 |
|
| 158 |
1.1 |