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
  • 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, @RequestParam(required=false) String canvasApiToken, @RequestParam(required=false) String canvasCourseId)
      This method creates a new Course.
      Parameters:
      courseName - the name of the course
      term - the term of the course
      school - the school of the course
      canvasApiToken - the Canvas API token (optional)
      canvasCourseId - the Canvas course ID (optional)
    • 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
    • getCourseCanvasInfo

      @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @GetMapping("getCanvasInfo") public Map<String,String> getCourseCanvasInfo(@RequestParam Long courseId)
      This method returns the Canvas course ID and partially obscured Canvas token for a course by its id. If the token is less than or equal to 3 characters long, it is returned in full. Otherwise, all but the last three characters are replaced with asterisks. This is okay because such short tokens are not generated by Canvas.
      Parameters:
      courseId - the id of the course
      Returns:
      a map with courseId, canvasCourseId, and obscured canvasApiToken
    • 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 the addInstallation() 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 installation
      setup_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
      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 update
      courseName - the new name of the course
      term - the new term of the course
      school - the new school of the course
      Returns:
      the updated course
    • updateCourseWithCanvasToken

      @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") @PutMapping("/updateCourseCanvasToken") public CoursesController.InstructorCourseView updateCourseWithCanvasToken(@RequestParam Long courseId, @RequestParam(required=false) String canvasApiToken, @RequestParam(required=false) String canvasCourseId)
      This method updates an existing course.
      Parameters:
      courseId - the id of the course to update
      canvasApiToken - the new Canvas API token for the course
      canvasCourseId - the new Canvas course ID
      courseName - the new name of the course
      term - the new term of the course
      school - the new school of the course
      Returns:
      the updated course
    • warnings

      @GetMapping("/warnings/{courseId}") @PreAuthorize("@CourseSecurity.hasManagePermissions(#root, #courseId)") public CourseWarning warnings(@PathVariable Long courseId) throws Exception
      Throws:
      Exception