| 1 | package edu.ucsb.cs156.example.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.example.entities.RecommendationRequests; | |
| 4 | import edu.ucsb.cs156.example.errors.EntityNotFoundException; | |
| 5 | import edu.ucsb.cs156.example.repositories.RecommendationRequestsRepository; | |
| 6 | import io.swagger.v3.oas.annotations.Operation; | |
| 7 | import io.swagger.v3.oas.annotations.Parameter; | |
| 8 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 9 | import java.time.LocalDateTime; | |
| 10 | import java.util.Map; | |
| 11 | import lombok.extern.slf4j.Slf4j; | |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | import org.springframework.format.annotation.DateTimeFormat; | |
| 14 | import org.springframework.format.annotation.DateTimeFormat.ISO; | |
| 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 | @Tag(name = "RecommendationRequests") | |
| 26 | @RequestMapping("/api/recommendationrequests") | |
| 27 | @RestController | |
| 28 | @Slf4j | |
| 29 | public class RecommendationRequestsController extends ApiController { | |
| 30 | ||
| 31 | @Autowired RecommendationRequestsRepository repository; | |
| 32 | ||
| 33 | @Operation(summary = "List all recommendation requests") | |
| 34 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 35 | @GetMapping("/all") | |
| 36 | public Iterable<RecommendationRequests> all() { | |
| 37 |
1
1. all : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::all → KILLED |
return repository.findAll(); |
| 38 | } | |
| 39 | ||
| 40 | // pls work | |
| 41 | @Operation(summary = "Get a single RecommendationRequest by id") | |
| 42 | @PreAuthorize("hasRole('ROLE_USER')") | |
| 43 | @GetMapping("") | |
| 44 | public RecommendationRequests getById(@Parameter(name = "id") @RequestParam Long id) { | |
| 45 |
1
1. getById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::getById → KILLED |
return repository |
| 46 | .findById(id) | |
| 47 |
1
1. lambda$getById$0 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$getById$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequests.class, id)); |
| 48 | } | |
| 49 | ||
| 50 | @Operation(summary = "Update a RecommendationRequest by id") | |
| 51 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 52 | @PutMapping("") | |
| 53 | public RecommendationRequests updateById( | |
| 54 | @RequestParam Long id, @RequestBody RecommendationRequests incoming) { | |
| 55 | repository | |
| 56 | .findById(id) | |
| 57 |
1
1. lambda$updateById$1 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$updateById$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequests.class, id)); |
| 58 | ||
| 59 | // Use the incoming payload directly | |
| 60 |
1
1. updateById : removed call to edu/ucsb/cs156/example/entities/RecommendationRequests::setId → KILLED |
incoming.setId(id); |
| 61 |
1
1. updateById : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::updateById → KILLED |
return repository.save(incoming); |
| 62 | } | |
| 63 | ||
| 64 | @Operation( | |
| 65 | summary = "Delete a single RecommendationRequests row by id", | |
| 66 | description = | |
| 67 | "Requires ADMIN. If the id exists, delete it and return a confirmation message; otherwise 404.") | |
| 68 | @PreAuthorize("hasRole('ADMIN')") | |
| 69 | @DeleteMapping("") | |
| 70 | public Map<String, String> deleteRecommendationRequestById( | |
| 71 | @Parameter(name = "id", description = "Primary key of the RecommendationRequests row") | |
| 72 | @RequestParam | |
| 73 | Long id) { | |
| 74 | ||
| 75 | RecommendationRequests existing = | |
| 76 | repository | |
| 77 | .findById(id) | |
| 78 |
1
1. lambda$deleteRecommendationRequestById$2 : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::lambda$deleteRecommendationRequestById$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(RecommendationRequests.class, id)); |
| 79 | ||
| 80 |
1
1. deleteRecommendationRequestById : removed call to edu/ucsb/cs156/example/repositories/RecommendationRequestsRepository::delete → KILLED |
repository.delete(existing); |
| 81 | ||
| 82 |
1
1. deleteRecommendationRequestById : replaced return value with Collections.emptyMap for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::deleteRecommendationRequestById → KILLED |
return Map.of("message", String.format("RecommendationRequests with id %d deleted", id)); |
| 83 | } | |
| 84 | ||
| 85 | @Operation(summary = "Create a new recommendation request") | |
| 86 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
| 87 | @PostMapping("/post") | |
| 88 | public RecommendationRequests post( | |
| 89 | @Parameter(name = "requesterEmail") @RequestParam String requesterEmail, | |
| 90 | @Parameter(name = "professorEmail") @RequestParam String professorEmail, | |
| 91 | @Parameter(name = "explanation") @RequestParam String explanation, | |
| 92 | @Parameter(name = "dateRequested", description = "ISO date-time, e.g. 2025-10-28T12:34:56") | |
| 93 | @RequestParam("dateRequested") | |
| 94 | @DateTimeFormat(iso = ISO.DATE_TIME) | |
| 95 | LocalDateTime dateRequested, | |
| 96 | @Parameter(name = "dateNeeded", description = "ISO date-time, e.g. 2025-11-05T17:00:00") | |
| 97 | @RequestParam("dateNeeded") | |
| 98 | @DateTimeFormat(iso = ISO.DATE_TIME) | |
| 99 | LocalDateTime dateNeeded, | |
| 100 | @Parameter(name = "done") @RequestParam boolean done) { | |
| 101 | RecommendationRequests rr = | |
| 102 | RecommendationRequests.builder() | |
| 103 | .requesterEmail(requesterEmail) | |
| 104 | .professorEmail(professorEmail) | |
| 105 | .explanation(explanation) | |
| 106 | .dateRequested(dateRequested) | |
| 107 | .dateNeeded(dateNeeded) | |
| 108 | .done(done) | |
| 109 | .build(); | |
| 110 | ||
| 111 |
1
1. post : replaced return value with null for edu/ucsb/cs156/example/controllers/RecommendationRequestsController::post → KILLED |
return repository.save(rr); |
| 112 | } | |
| 113 | } | |
Mutations | ||
| 37 |
1.1 |
|
| 45 |
1.1 |
|
| 47 |
1.1 |
|
| 57 |
1.1 |
|
| 60 |
1.1 |
|
| 61 |
1.1 |
|
| 78 |
1.1 |
|
| 80 |
1.1 |
|
| 82 |
1.1 |
|
| 111 |
1.1 |