| 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.enums.RepositoryPermissions; | |
| 7 | import edu.ucsb.cs156.frontiers.enums.Visibility; | |
| 8 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
| 9 | import edu.ucsb.cs156.frontiers.repositories.AssignmentRepository; | |
| 10 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
| 11 | import io.swagger.v3.oas.annotations.Operation; | |
| 12 | import io.swagger.v3.oas.annotations.Parameter; | |
| 13 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 14 | import lombok.extern.slf4j.Slf4j; | |
| 15 | import org.springframework.beans.factory.annotation.Autowired; | |
| 16 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 17 | import org.springframework.web.bind.annotation.*; | |
| 18 | ||
| 19 | @Tag(name = "Assignments") | |
| 20 | @RequestMapping("/api/assignments") | |
| 21 | @RestController | |
| 22 | @Slf4j | |
| 23 | public class AssignmentsController extends ApiController { | |
| 24 | ||
| 25 | @Autowired private AssignmentRepository assignmentRepository; | |
| 26 | ||
| 27 | @Autowired private CourseRepository courseRepository; | |
| 28 | ||
| 29 | @Operation(summary = "Create a new assignment for a course") | |
| 30 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 31 | @PostMapping("/post") | |
| 32 | public Assignment postAssignment( | |
| 33 | @Parameter(name = "courseId") @RequestParam Long courseId, | |
| 34 | @Parameter(name = "name") @RequestParam String name, | |
| 35 | @Parameter(name = "asn_type") @RequestParam AssignmentType asn_type, | |
| 36 | @Parameter(name = "visibility") @RequestParam Visibility visibility, | |
| 37 | @Parameter(name = "permission") @RequestParam RepositoryPermissions permission) { | |
| 38 | ||
| 39 | Course course = | |
| 40 | courseRepository | |
| 41 | .findById(courseId) | |
| 42 |
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)); |
| 43 | ||
| 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 | Assignment savedAssignment = assignmentRepository.save(assignment); | |
| 54 |
1
1. postAssignment : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/AssignmentsController::postAssignment → KILLED |
return savedAssignment; |
| 55 | } | |
| 56 | } | |
Mutations | ||
| 42 |
1.1 |
|
| 54 |
1.1 |