1 | package edu.ucsb.cs156.frontiers.controllers; | |
2 | ||
3 | import java.io.BufferedInputStream; | |
4 | import java.io.IOException; | |
5 | import java.io.InputStream; | |
6 | import java.io.InputStreamReader; | |
7 | import java.security.NoSuchAlgorithmException; | |
8 | import java.security.spec.InvalidKeySpecException; | |
9 | import java.util.List; | |
10 | import java.util.Map; | |
11 | import java.util.Optional; | |
12 | ||
13 | import edu.ucsb.cs156.frontiers.entities.Job; | |
14 | import edu.ucsb.cs156.frontiers.entities.User; | |
15 | import edu.ucsb.cs156.frontiers.errors.NoLinkedOrganizationException; | |
16 | import edu.ucsb.cs156.frontiers.jobs.UpdateOrgMembershipJob; | |
17 | import edu.ucsb.cs156.frontiers.repositories.UserRepository; | |
18 | import edu.ucsb.cs156.frontiers.services.*; | |
19 | import edu.ucsb.cs156.frontiers.services.jobs.JobService; | |
20 | import org.apache.coyote.BadRequestException; | |
21 | import org.springframework.beans.factory.annotation.Autowired; | |
22 | import org.springframework.http.ResponseEntity; | |
23 | import org.springframework.security.access.AccessDeniedException; | |
24 | import org.springframework.security.access.prepost.PreAuthorize; | |
25 | import org.springframework.web.bind.annotation.*; | |
26 | import org.springframework.web.multipart.MultipartFile; | |
27 | ||
28 | import com.fasterxml.jackson.core.JsonProcessingException; | |
29 | ||
30 | import edu.ucsb.cs156.frontiers.entities.Course; | |
31 | import edu.ucsb.cs156.frontiers.entities.CourseStaff; | |
32 | import edu.ucsb.cs156.frontiers.enums.OrgStatus; | |
33 | import edu.ucsb.cs156.frontiers.enums.RosterStatus; | |
34 | import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException; | |
35 | import edu.ucsb.cs156.frontiers.repositories.CourseRepository; | |
36 | import edu.ucsb.cs156.frontiers.repositories.CourseStaffRepository; | |
37 | import io.swagger.v3.oas.annotations.Operation; | |
38 | import io.swagger.v3.oas.annotations.Parameter; | |
39 | import io.swagger.v3.oas.annotations.tags.Tag; | |
40 | import lombok.extern.slf4j.Slf4j; | |
41 | ||
42 | import com.opencsv.CSVReader; | |
43 | import com.opencsv.exceptions.CsvException; | |
44 | ||
45 | @Tag(name = "CourseStaff") | |
46 | @RequestMapping("/api/coursestaff") | |
47 | @RestController | |
48 | @Slf4j | |
49 | public class CourseStaffController extends ApiController { | |
50 | ||
51 | @Autowired | |
52 | private JobService jobService; | |
53 | @Autowired | |
54 | private OrganizationMemberService organizationMemberService; | |
55 | ||
56 | @Autowired | |
57 | private CourseStaffRepository courseStaffRepository; | |
58 | ||
59 | @Autowired | |
60 | private CourseRepository courseRepository; | |
61 | ||
62 | @Autowired | |
63 | private UpdateUserService updateUserService; | |
64 | ||
65 | @Autowired | |
66 | private CurrentUserService currentUserService; | |
67 | ||
68 | /** | |
69 | * This method creates a new CourseStaff. | |
70 | * | |
71 | * | |
72 | * @return the created CourseStaff | |
73 | */ | |
74 | ||
75 | @Operation(summary = "Create a new course staff") | |
76 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
77 | @PostMapping("/post") | |
78 | public CourseStaff postCourseStaff( | |
79 | @Parameter(name = "firstName") @RequestParam String firstName, | |
80 | @Parameter(name = "lastName") @RequestParam String lastName, | |
81 | @Parameter(name = "email") @RequestParam String email, | |
82 | @Parameter(name = "courseId") @RequestParam Long courseId) throws EntityNotFoundException { | |
83 | ||
84 | // Get Course or else throw an error | |
85 | ||
86 | Course course = courseRepository.findById(courseId) | |
87 |
1
1. lambda$postCourseStaff$0 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/CourseStaffController::lambda$postCourseStaff$0 → KILLED |
.orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
88 | ||
89 | CourseStaff courseStaff = CourseStaff.builder() | |
90 | .firstName(firstName) | |
91 | .lastName(lastName) | |
92 | .email(email) | |
93 | .course(course) | |
94 | .build(); | |
95 | CourseStaff savedCourseStaff = courseStaffRepository.save(courseStaff); | |
96 | ||
97 |
1
1. postCourseStaff : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/CourseStaffController::postCourseStaff → KILLED |
return savedCourseStaff; |
98 | } | |
99 | ||
100 | /** | |
101 | * This method returns a list of course staff for a given course. | |
102 | * | |
103 | * @return a list of all course staff. | |
104 | */ | |
105 | @Operation(summary = "List all course staff for a course") | |
106 | @PreAuthorize("hasRole('ROLE_ADMIN')") | |
107 | @GetMapping("/course") | |
108 | public Iterable<CourseStaff> courseStaffForCourse( | |
109 | @Parameter(name = "courseId") @RequestParam Long courseId) throws EntityNotFoundException { | |
110 |
1
1. lambda$courseStaffForCourse$1 : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/CourseStaffController::lambda$courseStaffForCourse$1 → KILLED |
courseRepository.findById(courseId).orElseThrow(() -> new EntityNotFoundException(Course.class, courseId)); |
111 | Iterable<CourseStaff> courseStaffs = courseStaffRepository.findByCourseId(courseId); | |
112 |
1
1. courseStaffForCourse : replaced return value with Collections.emptyList for edu/ucsb/cs156/frontiers/controllers/CourseStaffController::courseStaffForCourse → KILLED |
return courseStaffs; |
113 | } | |
114 | } | |
Mutations | ||
87 |
1.1 |
|
97 |
1.1 |
|
110 |
1.1 |
|
112 |
1.1 |