Class CoursesController
java.lang.Object
edu.ucsb.cs156.frontiers.controllers.ApiController
edu.ucsb.cs156.frontiers.controllers.CoursesController
@RequestMapping("/api/courses")
@RestController
public class CoursesController
extends ApiController
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Projection of Course entity with fields that are relevant for instructors and adminsstatic final record
static final record
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity
<Void> This method returns a list of courses.This method returns a list of courses.deleteCourse
(Long courseId) getCourseById
(Long id) This method returns single course by its idThis method handles the InvalidInstallationTypeException.org.springframework.http.ResponseEntity
<Void> linkCourse
(Long courseId) This is the outgoing method, redirecting from Frontiers to GitHub to allow a Course to be linked to a GitHub Organization.This method returns a list of courses that the current user is enrolled.postCourse
(String courseName, String term, String school) This method creates a new Course.student see what courses they appear as staff inupdateCourse
(Long courseId, String courseName, String term, String school) This method updates an existing course.updateInstructorEmail
(Long courseId, String instructorEmail) Methods inherited from class edu.ucsb.cs156.frontiers.controllers.ApiController
doesCurrentUserHaveRole, genericMessage, getCurrentUser, handleEntityNotFoundException, handleIllegalArgument, handleNoLinkedOrgException, handleUnsupportedOperation, isCurrentUserAdmin
-
Constructor Details
-
CoursesController
public CoursesController()
-
-
Method Details
-
postCourse
@PreAuthorize("hasRole(\'ROLE_ADMIN\') || hasRole(\'ROLE_INSTRUCTOR\')") @PostMapping("/post") public CoursesController.InstructorCourseView postCourse(@RequestParam String courseName, @RequestParam String term, @RequestParam String school) This method creates a new Course.- Parameters:
courseName
- the name of the courseterm
- the term of the courseschool
- the school of the course- Returns:
- the created course
-
allForInstructors
@PreAuthorize("hasRole(\'ROLE_INSTRUCTOR\')") @GetMapping("/allForInstructors") public Iterable<CoursesController.InstructorCourseView> allForInstructors()This method returns a list of courses.- Returns:
- a list of all courses for an instructor.
-
allForAdmins
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @GetMapping("/allForAdmins") public Iterable<CoursesController.InstructorCourseView> allForAdmins()This method returns a list of courses.- Returns:
- a list of all courses for an admin.
-
getCourseById
@PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #id)") @GetMapping("/{id}") public CoursesController.InstructorCourseView getCourseById(@PathVariable Long id) This method returns single course by its id- Returns:
- a course
-
linkCourse
@PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @GetMapping("/redirect") public org.springframework.http.ResponseEntity<Void> linkCourse(Long courseId) throws com.fasterxml.jackson.core.JsonProcessingException, NoSuchAlgorithmException, InvalidKeySpecException This is the outgoing method, redirecting from Frontiers to GitHub to allow a Course to be linked to a GitHub Organization. It redirects from Frontiers to the GitHub app installation process, and will return with theaddInstallation()
endpoint- Parameters:
courseId
- id of the course to be linked to- Returns:
- dynamically loaded url to install Frontiers to a Github Organization, with the courseId marked as the state parameter, which GitHub will return.
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
NoSuchAlgorithmException
InvalidKeySpecException
-
addInstallation
@PreAuthorize("hasRole(\'ROLE_ADMIN\') || hasRole(\'ROLE_INSTRUCTOR\')") @GetMapping("link") public org.springframework.http.ResponseEntity<Void> addInstallation(@RequestParam Optional<String> installation_id, @RequestParam String setup_action, @RequestParam String code, @RequestParam Long state) throws NoSuchAlgorithmException, InvalidKeySpecException, com.fasterxml.jackson.core.JsonProcessingException - Parameters:
installation_id
- id of the incoming GitHub Organization installationsetup_action
- whether the permissions are installed or updated. Required RequestParam but not used by the method.code
- token to be exchanged with GitHub to ensure the request is legitimate and not spoofed.state
- id of the Course to be linked with the GitHub installation.- Returns:
- ResponseEntity, returning /success if the course was successfully linked or /noperms if the user does not have the permission to install the application on GitHub. Alternately returns 403 Forbidden if the user is not the creator.
- Throws:
NoSuchAlgorithmException
InvalidKeySpecException
com.fasterxml.jackson.core.JsonProcessingException
-
handleInvalidInstallationType
@ExceptionHandler(InvalidInstallationTypeException.class) @ResponseStatus(BAD_REQUEST) public Object handleInvalidInstallationType(Throwable e) This method handles the InvalidInstallationTypeException.- Parameters:
e
- the exception- Returns:
- a map with the type and message of the exception
-
listCoursesForCurrentUser
@PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("/list") public List<CoursesController.RosterStudentCoursesDTO> listCoursesForCurrentUser()This method returns a list of courses that the current user is enrolled.- Returns:
- a list of courses in the DTO form along with the student status in the organization.
-
staffCourses
@PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("/staffCourses") public List<CoursesController.StaffCoursesDTO> staffCourses()student see what courses they appear as staff in- Parameters:
studentId
- the id of the student making request- Returns:
- a list of all courses student is staff in
-
updateInstructorEmail
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PutMapping("/updateInstructor") public CoursesController.InstructorCourseView updateInstructorEmail(@RequestParam Long courseId, @RequestParam String instructorEmail) -
deleteCourse
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @DeleteMapping("") public Object deleteCourse(@RequestParam Long courseId) throws NoSuchAlgorithmException, InvalidKeySpecException -
updateCourse
@PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @PutMapping("") public CoursesController.InstructorCourseView updateCourse(@RequestParam Long courseId, @RequestParam String courseName, @RequestParam String term, @RequestParam String school) This method updates an existing course.- Parameters:
courseId
- the id of the course to updatecourseName
- the new name of the courseterm
- the new term of the courseschool
- the new school of the course- Returns:
- the updated course
-