| 1 | package edu.ucsb.cs156.frontiers.controllers; | |
| 2 | ||
| 3 | import edu.ucsb.cs156.frontiers.entities.Assignment; | |
| 4 | import edu.ucsb.cs156.frontiers.entities.Course; | |
| 5 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs156.frontiers.repositories.AssignmentRepository; | |
| 7 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 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 | import org.springframework.beans.factory.annotation.Autowired; | |
| 13 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 14 | import org.springframework.web.bind.annotation.*; | |
| 15 | ||
| 16 | @Tag(name = "Assignments") | |
| 17 | @RequestMapping("/api/assignments") | |
| 18 | @RestController | |
| 19 | @Slf4j | |
| 20 | public class AssignmentController extends ApiController { | |
| 21 | ||
| 22 | @Autowired private AssignmentRepository assignmentRepository; | |
| 23 | ||
| 24 | @Autowired private CourseRepository courseRepository; | |
| 25 | ||
| 26 | /** Create a new assignment */ | |
| 27 | @Operation(summary = "Create a new assignment") | |
| 28 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 29 | @PostMapping("") | |
| 30 | public Assignment postAssignment( | |
| 31 | @Parameter(name = "courseId") @RequestParam Long courseId, | |
| 32 | @Parameter(name = "name") @RequestParam String name, | |
| 33 | @Parameter(name = "asn_type") @RequestParam String asn_type, | |
| 34 | @Parameter(name = "visibility") @RequestParam String visibility, | |
| 35 | @Parameter(name = "permission") @RequestParam String permission) { | |
| 36 | ||
| 37 | // Find the course or throw 404 | |
| 38 | Course course = | |
| 39 | courseRepository | |
| 40 | .findById(courseId) | |
| 41 |
1
1. lambda$postAssignment$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentController::lambda$postAssignment$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 42 | ||
| 43 | // Build the Assignment object | |
| 44 | Assignment assignment = | |
| 45 | Assignment.builder() | |
| 46 | .course(course) | |
| 47 | .name(name) | |
| 48 | .asn_type(asn_type) | |
| 49 | .visibility(visibility) | |
| 50 | .permission(permission) | |
| 51 | .build(); | |
| 52 | ||
| 53 | // Save and return | |
| 54 | Assignment savedAssignment = assignmentRepository.save(assignment); | |
| 55 |
1
1. postAssignment : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentController::postAssignment → KILLED |
return savedAssignment; |
| 56 | } | |
| 57 | ||
| 58 | /** Edit an assignment */ | |
| 59 | @Operation(summary = "Edit an assignment") | |
| 60 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 61 | @PutMapping("/{id}") | |
| 62 | public Assignment putAssignment( | |
| 63 | @Parameter(name = "id") @PathVariable Long id, | |
| 64 | @Parameter(name = "courseId") @RequestParam Long courseId, | |
| 65 | @Parameter(name = "asn_type") @RequestParam String asn_type, | |
| 66 | @Parameter(name = "visibility") @RequestParam String visibility, | |
| 67 | @Parameter(name = "permission") @RequestParam String permission) { | |
| 68 | ||
| 69 | // Validate that the course exists | |
| 70 | courseRepository | |
| 71 | .findById(courseId) | |
| 72 |
1
1. lambda$putAssignment$1 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentController::lambda$putAssignment$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 73 | ||
| 74 | // Find the Assignment object | |
| 75 | Assignment assignment = | |
| 76 | assignmentRepository | |
| 77 | .findById(id) | |
| 78 |
1
1. lambda$putAssignment$2 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentController::lambda$putAssignment$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Assignment.class, id)); |
| 79 | ||
| 80 | // Update Assignment object | |
| 81 |
1
1. putAssignment : removed call to edu/ucsb/cs156/frontiers/entities/Assignment::setAsn_type → KILLED |
assignment.setAsn_type(asn_type); |
| 82 |
1
1. putAssignment : removed call to edu/ucsb/cs156/frontiers/entities/Assignment::setVisibility → KILLED |
assignment.setVisibility(visibility); |
| 83 |
1
1. putAssignment : removed call to edu/ucsb/cs156/frontiers/entities/Assignment::setPermission → KILLED |
assignment.setPermission(permission); |
| 84 | ||
| 85 | // Save and return | |
| 86 | Assignment savedAssignment = assignmentRepository.save(assignment); | |
| 87 |
1
1. putAssignment : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentController::putAssignment → KILLED |
return savedAssignment; |
| 88 | } | |
| 89 | ||
| 90 | /** Delete an an assignment */ | |
| 91 | @Operation(summary = "Delete an assignment") | |
| 92 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 93 | @DeleteMapping("/{id}") | |
| 94 | public Object deleteAssignment( | |
| 95 | @Parameter(name = "id") @PathVariable Long id, | |
| 96 | @Parameter(name = "courseId") @RequestParam Long courseId) { | |
| 97 | ||
| 98 | // Validate that the course exists | |
| 99 | courseRepository | |
| 100 | .findById(courseId) | |
| 101 |
1
1. lambda$deleteAssignment$3 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentController::lambda$deleteAssignment$3 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 102 | ||
| 103 | // Find the Assignment object | |
| 104 | Assignment assignment = | |
| 105 | assignmentRepository | |
| 106 | .findById(id) | |
| 107 |
1
1. lambda$deleteAssignment$4 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentController::lambda$deleteAssignment$4 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Assignment.class, id)); |
| 108 | ||
| 109 | // Delete the assignment | |
| 110 |
1
1. deleteAssignment : removed call to edu/ucsb/cs156/frontiers/repositories/AssignmentRepository::delete → KILLED |
assignmentRepository.delete(assignment); |
| 111 | ||
| 112 |
1
1. deleteAssignment : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentController::deleteAssignment → KILLED |
return genericMessage(String.format("Assignment with id %s deleted", id)); |
| 113 | } | |
| 114 | } | |
Mutations | ||
| 41 |
1.1 |
|
| 55 |
1.1 |
|
| 72 |
1.1 |
|
| 78 |
1.1 |
|
| 81 |
1.1 |
|
| 82 |
1.1 |
|
| 83 |
1.1 |
|
| 87 |
1.1 |
|
| 101 |
1.1 |
|
| 107 |
1.1 |
|
| 110 |
1.1 |
|
| 112 |
1.1 |