| 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.enums.AssignmentType; | |
| 6 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
| 7 | import edu.ucsb.cs156.frontiers.repositories.AssignmentRepository; | |
| 8 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 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 | import org.springframework.beans.factory.annotation.Autowired; | |
| 14 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 15 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 16 | import org.springframework.web.bind.annotation.PathVariable; | |
| 17 | import org.springframework.web.bind.annotation.PostMapping; | |
| 18 | import org.springframework.web.bind.annotation.PutMapping; | |
| 19 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 20 | import org.springframework.web.bind.annotation.RequestParam; | |
| 21 | import org.springframework.web.bind.annotation.RestController; | |
| 22 | ||
| 23 | @Tag(name = "Assignments") | |
| 24 | @RequestMapping("/api/assignments") | |
| 25 | @RestController | |
| 26 | @Slf4j | |
| 27 | public class AssignmentsController extends ApiController { | |
| 28 | @Autowired private AssignmentRepository assignmentRepository; | |
| 29 | ||
| 30 | @Autowired private CourseRepository courseRepository; | |
| 31 | ||
| 32 | /** | |
| 33 | * This method creates a new Assignment. | |
| 34 | * | |
| 35 | * @param courseId the ID of the course the assignment is associated with | |
| 36 | * @param name the name of the assignment | |
| 37 | * @param asnType the assignment type (individual vs team) | |
| 38 | * @param visibility the visbility of the assignment (public vs private) | |
| 39 | * @param permission the permissions for the assignment (read, write, maintain, admin) | |
| 40 | * @return the created Assignment | |
| 41 | */ | |
| 42 | @Operation(summary = "Create a new assignment") | |
| 43 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 44 | @PostMapping("/post") | |
| 45 | public Assignment postAssignment( | |
| 46 | @Parameter(name = "courseId") @RequestParam Long courseId, | |
| 47 | @Parameter(name = "name") @RequestParam String name, | |
| 48 | @Parameter(name = "asnType") @RequestParam AssignmentType asnType, | |
| 49 | @Parameter(name = "visibility") @RequestParam | |
| 50 | edu.ucsb.cs156.frontiers.enums.Visibility visibility, | |
| 51 | @Parameter(name = "permission") @RequestParam | |
| 52 | edu.ucsb.cs156.frontiers.enums.Permission permission) | |
| 53 | throws EntityNotFoundException { | |
| 54 | ||
| 55 | // Get Course or else throw an error | |
| 56 | ||
| 57 | Course course = | |
| 58 | courseRepository | |
| 59 | .findById(courseId) | |
| 60 |
1
1. lambda$postAssignment$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentsController::lambda$postAssignment$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 61 | ||
| 62 | Assignment assignment = | |
| 63 | Assignment.builder() | |
| 64 | .course(course) | |
| 65 | .name(name) | |
| 66 | .asnType(asnType) | |
| 67 | .visibility(visibility) | |
| 68 | .permission(permission) | |
| 69 | .build(); | |
| 70 | ||
| 71 | Assignment savedAssignment = assignmentRepository.save(assignment); | |
| 72 | ||
| 73 |
1
1. postAssignment : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentsController::postAssignment → KILLED |
return savedAssignment; |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * This method updates an Assignment. | |
| 78 | * | |
| 79 | * @param assignmentId the ID of the course the assignment is associated with | |
| 80 | * @param name the name of the assignment | |
| 81 | * @param asnType the assignment type (individual vs team) | |
| 82 | * @param visibility the visbility of the assignment (public vs private) | |
| 83 | * @param permission the permissions for the assignment (read, write, maintain, admin) | |
| 84 | * @return the created Assignment | |
| 85 | */ | |
| 86 | @Operation(summary = "Update an assignment") | |
| 87 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #assignmentId)") | |
| 88 | @PutMapping("/put") | |
| 89 | public Assignment updateAssignment( | |
| 90 | @Parameter(name = "assignmentId") @RequestParam Long assignmentId, | |
| 91 | @Parameter(name = "name") @RequestParam String name, | |
| 92 | @Parameter(name = "asnType") @RequestParam AssignmentType asnType, | |
| 93 | @Parameter(name = "visibility") @RequestParam | |
| 94 | edu.ucsb.cs156.frontiers.enums.Visibility visibility, | |
| 95 | @Parameter(name = "permission") @RequestParam | |
| 96 | edu.ucsb.cs156.frontiers.enums.Permission permission) | |
| 97 | throws EntityNotFoundException { | |
| 98 | ||
| 99 | Assignment assignment = | |
| 100 | assignmentRepository | |
| 101 | .findById(assignmentId) | |
| 102 |
1
1. lambda$updateAssignment$1 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentsController::lambda$updateAssignment$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Assignment.class, assignmentId)); |
| 103 | ||
| 104 |
1
1. updateAssignment : removed call to edu/ucsb/cs156/frontiers/entities/Assignment::setAsnType → KILLED |
assignment.setAsnType(asnType); |
| 105 |
1
1. updateAssignment : removed call to edu/ucsb/cs156/frontiers/entities/Assignment::setVisibility → KILLED |
assignment.setVisibility(visibility); |
| 106 |
1
1. updateAssignment : removed call to edu/ucsb/cs156/frontiers/entities/Assignment::setPermission → KILLED |
assignment.setPermission(permission); |
| 107 |
1
1. updateAssignment : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentsController::updateAssignment → KILLED |
return assignmentRepository.save(assignment); |
| 108 | } | |
| 109 | ||
| 110 | @Operation(summary = "Delete an assignment") | |
| 111 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 112 | @DeleteMapping("/{id}") | |
| 113 | public Object deleteAssignment( | |
| 114 | @Parameter(name = "id") @PathVariable Long id, | |
| 115 | @Parameter(name = "courseId") @RequestParam Long courseId) { | |
| 116 | ||
| 117 | // check course exists | |
| 118 | courseRepository | |
| 119 | .findById(courseId) | |
| 120 |
1
1. lambda$deleteAssignment$2 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentsController::lambda$deleteAssignment$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 121 | ||
| 122 | // find assignment or throw error | |
| 123 | Assignment assignment = | |
| 124 | assignmentRepository | |
| 125 | .findById(id) | |
| 126 |
1
1. lambda$deleteAssignment$3 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentsController::lambda$deleteAssignment$3 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Assignment.class, id)); |
| 127 | ||
| 128 | // delete the assignment | |
| 129 |
1
1. deleteAssignment : removed call to edu/ucsb/cs156/frontiers/repositories/AssignmentRepository::delete → KILLED |
assignmentRepository.delete(assignment); |
| 130 | ||
| 131 |
1
1. deleteAssignment : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentsController::deleteAssignment → KILLED |
return genericMessage(String.format("Assignment with id %s deleted", id)); |
| 132 | } | |
| 133 | } | |
Mutations | ||
| 60 |
1.1 |
|
| 73 |
1.1 |
|
| 102 |
1.1 |
|
| 104 |
1.1 |
|
| 105 |
1.1 |
|
| 106 |
1.1 |
|
| 107 |
1.1 |
|
| 120 |
1.1 |
|
| 126 |
1.1 |
|
| 129 |
1.1 |
|
| 131 |
1.1 |