Class ApiController

java.lang.Object
edu.ucsb.cs156.frontiers.controllers.ApiController
Direct Known Subclasses:
AdminsController, CoursesController, CourseStaffController, CSVDownloadsController, GithubController, GithubGraphQLController, InstructorsController, JobsController, RepositoryController, RosterStudentsController, RosterStudentsCSVController, SystemInfoController, TeamsController, UserInfoController, UsersController

public abstract class ApiController extends Object
This is an abstract class that provides common functionality for all API controllers.
  • Constructor Details

    • ApiController

      public ApiController()
  • Method Details

    • getCurrentUser

      protected CurrentUser getCurrentUser()
      This method returns the current user.
      Returns:
      the current user
    • doesCurrentUserHaveRole

      protected boolean doesCurrentUserHaveRole(String roleToCheck)
      This method checks if the current user has the given role
      Parameters:
      role - the role to check
      Returns:
      true if the current user has the role, false otherwise
    • isCurrentUserAdmin

      protected boolean isCurrentUserAdmin()
      This method checks if the current user is an admin.
      Returns:
      true if the current user is an admin, false otherwise
    • genericMessage

      protected Object genericMessage(String message)
      This method returns a generic message.
      Parameters:
      message - the message
      Returns:
      a map with the message
    • handleEntityNotFoundException

      @ExceptionHandler(EntityNotFoundException.class) @ResponseStatus(NOT_FOUND) public Object handleEntityNotFoundException(Throwable e)
      This method handles the EntityNotFoundException. This maps to a 404/Not Found.
      Parameters:
      e - the exception
      Returns:
      a map with the type and message of the exception
    • handleNoLinkedOrgException

      @ExceptionHandler(NoLinkedOrganizationException.class) @ResponseStatus(BAD_REQUEST) public Object handleNoLinkedOrgException(Throwable e)
      This method handles the NoLinkedOrganizationException. This maps to a 400/Bad Request.
      Parameters:
      e - the exception
      Returns:
      a map with the type and message of the exception
    • handleUnsupportedOperation

      @ExceptionHandler(java.lang.UnsupportedOperationException.class) public org.springframework.http.ResponseEntity<Map<String,String>> handleUnsupportedOperation(UnsupportedOperationException ex)
      This method handles the UnsupportedOperationException. This maps to a 403/Forbidden.
      Parameters:
      e - the exception
      Returns:
      a map with the type and message of the exception
    • handleIllegalArgument

      @ExceptionHandler(java.lang.IllegalArgumentException.class) @ResponseStatus(BAD_REQUEST) public Object handleIllegalArgument(Throwable e)
      This method handles the IllegalArgumentException. This maps to a 400/Bad Request.
      Parameters:
      e - the exception
      Returns:
      a map with the type and message of the exception