| 1 | package edu.ucsb.cs.scaffold.controller; | |
| 2 | ||
| 3 | import edu.ucsb.cs.scaffold.entity.Course; | |
| 4 | import edu.ucsb.cs.scaffold.entity.CourseStaff; | |
| 5 | import edu.ucsb.cs.scaffold.errors.EntityNotFoundException; | |
| 6 | import edu.ucsb.cs.scaffold.repository.CourseRepository; | |
| 7 | import edu.ucsb.cs.scaffold.repository.CourseStaffRepository; | |
| 8 | import edu.ucsb.cs.scaffold.services.CurrentUserService; | |
| 9 | import edu.ucsb.cs.scaffold.services.UpdateUserService; | |
| 10 | import io.swagger.v3.oas.annotations.Operation; | |
| 11 | import io.swagger.v3.oas.annotations.Parameter; | |
| 12 | import io.swagger.v3.oas.annotations.tags.Tag; | |
| 13 | import lombok.extern.slf4j.Slf4j; | |
| 14 | import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | import org.springframework.http.ResponseEntity; | |
| 16 | import org.springframework.security.access.prepost.PreAuthorize; | |
| 17 | import org.springframework.transaction.annotation.Transactional; | |
| 18 | import org.springframework.web.bind.annotation.DeleteMapping; | |
| 19 | import org.springframework.web.bind.annotation.GetMapping; | |
| 20 | import org.springframework.web.bind.annotation.PostMapping; | |
| 21 | import org.springframework.web.bind.annotation.PutMapping; | |
| 22 | import org.springframework.web.bind.annotation.RequestMapping; | |
| 23 | import org.springframework.web.bind.annotation.RequestParam; | |
| 24 | import org.springframework.web.bind.annotation.RestController; | |
| 25 | ||
| 26 | @Tag(name = "CourseStaff") | |
| 27 | @RequestMapping("/api/coursestaff") | |
| 28 | @RestController | |
| 29 | @Slf4j | |
| 30 | public class CourseStaffController extends ApiController { | |
| 31 | ||
| 32 | @Autowired private CourseStaffRepository courseStaffRepository; | |
| 33 | ||
| 34 | @Autowired private CourseRepository courseRepository; | |
| 35 | ||
| 36 | @Autowired private UpdateUserService updateUserService; | |
| 37 | ||
| 38 | @Autowired private CurrentUserService currentUserService; | |
| 39 | ||
| 40 | /** | |
| 41 | * This method creates a new CourseStaff. | |
| 42 | * | |
| 43 | * @return the created CourseStaff | |
| 44 | */ | |
| 45 | @Operation(summary = "Add a staff member to a course") | |
| 46 | @PreAuthorize("@CourseSecurity.hasInstructorPermissions(#root, #courseId)") | |
| 47 | @PostMapping("/post") | |
| 48 | public CourseStaff postCourseStaff( | |
| 49 | @Parameter(name = "firstName") @RequestParam String firstName, | |
| 50 | @Parameter(name = "lastName") @RequestParam String lastName, | |
| 51 | @Parameter(name = "email") @RequestParam String email, | |
| 52 | @Parameter(name = "courseId") @RequestParam Long courseId) | |
| 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$postCourseStaff$0 : replaced return value with null for edu/ucsb/cs/scaffold/controller/CourseStaffController::lambda$postCourseStaff$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 61 | ||
| 62 | CourseStaff courseStaff = | |
| 63 | CourseStaff.builder() | |
| 64 | .firstName(firstName) | |
| 65 | .lastName(lastName) | |
| 66 | .email(email.strip()) | |
| 67 | .course(course) | |
| 68 | .build(); | |
| 69 | ||
| 70 | CourseStaff savedCourseStaff = courseStaffRepository.save(courseStaff); | |
| 71 | ||
| 72 |
1
1. postCourseStaff : removed call to edu/ucsb/cs/scaffold/services/UpdateUserService::attachUserToCourseStaff → KILLED |
updateUserService.attachUserToCourseStaff(savedCourseStaff); |
| 73 | ||
| 74 |
1
1. postCourseStaff : replaced return value with null for edu/ucsb/cs/scaffold/controller/CourseStaffController::postCourseStaff → KILLED |
return savedCourseStaff; |
| 75 | } | |
| 76 | ||
| 77 | /** | |
| 78 | * This method returns a list of course staff for a given course. | |
| 79 | * | |
| 80 | * @return a list of all courses. | |
| 81 | */ | |
| 82 | @Operation(summary = "List all course staff members for a course") | |
| 83 | @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") | |
| 84 | @GetMapping("/course") | |
| 85 | public Iterable<CourseStaff> courseStaffForCourse( | |
| 86 | @Parameter(name = "courseId") @RequestParam Long courseId) throws EntityNotFoundException { | |
| 87 | courseRepository | |
| 88 | .findById(courseId) | |
| 89 |
1
1. lambda$courseStaffForCourse$1 : replaced return value with null for edu/ucsb/cs/scaffold/controller/CourseStaffController::lambda$courseStaffForCourse$1 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
| 90 | Iterable<CourseStaff> courseStaffs = courseStaffRepository.findByCourseId(courseId); | |
| 91 |
1
1. courseStaffForCourse : replaced return value with Collections.emptyList for edu/ucsb/cs/scaffold/controller/CourseStaffController::courseStaffForCourse → KILLED |
return courseStaffs; |
| 92 | } | |
| 93 | ||
| 94 | @Operation(summary = "Update a staff member") | |
| 95 | @PreAuthorize("@CourseSecurity.hasInstructorPermissions(#root, #courseId)") | |
| 96 | @PutMapping("") | |
| 97 | public CourseStaff updateStaffMember( | |
| 98 | @Parameter(name = "courseId") @RequestParam Long courseId, | |
| 99 | @Parameter(name = "id") @RequestParam Long id, | |
| 100 | @Parameter(name = "firstName") @RequestParam String firstName, | |
| 101 | @Parameter(name = "lastName") @RequestParam String lastName) | |
| 102 | throws EntityNotFoundException { | |
| 103 | ||
| 104 | CourseStaff staffMember = | |
| 105 | courseStaffRepository | |
| 106 | .findById(id) | |
| 107 |
1
1. lambda$updateStaffMember$2 : replaced return value with null for edu/ucsb/cs/scaffold/controller/CourseStaffController::lambda$updateStaffMember$2 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(CourseStaff.class, id)); |
| 108 | ||
| 109 |
1
1. updateStaffMember : removed call to edu/ucsb/cs/scaffold/entity/CourseStaff::setFirstName → KILLED |
staffMember.setFirstName(firstName.trim()); |
| 110 |
1
1. updateStaffMember : removed call to edu/ucsb/cs/scaffold/entity/CourseStaff::setLastName → KILLED |
staffMember.setLastName(lastName.trim()); |
| 111 |
1
1. updateStaffMember : replaced return value with null for edu/ucsb/cs/scaffold/controller/CourseStaffController::updateStaffMember → KILLED |
return courseStaffRepository.save(staffMember); |
| 112 | } | |
| 113 | ||
| 114 | @Operation(summary = "Delete a staff member") | |
| 115 | @PreAuthorize("@CourseSecurity.hasInstructorPermissions(#root, #courseId)") | |
| 116 | @DeleteMapping("/delete") | |
| 117 | @Transactional | |
| 118 | public ResponseEntity<String> deleteStaffMember( | |
| 119 | @Parameter(name = "id") @RequestParam Long id, | |
| 120 | @Parameter(name = "courseId") @RequestParam Long courseId) | |
| 121 | throws EntityNotFoundException { | |
| 122 | CourseStaff staffMember = | |
| 123 | courseStaffRepository | |
| 124 | .findById(id) | |
| 125 |
1
1. lambda$deleteStaffMember$3 : replaced return value with null for edu/ucsb/cs/scaffold/controller/CourseStaffController::lambda$deleteStaffMember$3 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(CourseStaff.class, id)); |
| 126 | Course course = staffMember.getCourse(); | |
| 127 | ||
| 128 | course.getCourseStaff().remove(staffMember); | |
| 129 |
1
1. deleteStaffMember : removed call to edu/ucsb/cs/scaffold/entity/CourseStaff::setCourse → KILLED |
staffMember.setCourse(null); |
| 130 |
1
1. deleteStaffMember : removed call to edu/ucsb/cs/scaffold/repository/CourseStaffRepository::delete → KILLED |
courseStaffRepository.delete(staffMember); |
| 131 | ||
| 132 |
1
1. deleteStaffMember : replaced return value with null for edu/ucsb/cs/scaffold/controller/CourseStaffController::deleteStaffMember → KILLED |
return ResponseEntity.ok("Successfully deleted staff member."); |
| 133 | } | |
| 134 | } | |
Mutations | ||
| 60 |
1.1 |
|
| 72 |
1.1 |
|
| 74 |
1.1 |
|
| 89 |
1.1 |
|
| 91 |
1.1 |
|
| 107 |
1.1 |
|
| 109 |
1.1 |
|
| 110 |
1.1 |
|
| 111 |
1.1 |
|
| 125 |
1.1 |
|
| 129 |
1.1 |
|
| 130 |
1.1 |
|
| 132 |
1.1 |