Class ApiController
java.lang.Object
edu.ucsb.cs156.frontiers.controllers.ApiController
- Direct Known Subclasses:
AdminsController,AssignmentsController,CoursesController,CourseStaffController,CSVDownloadsController,GithubController,GithubGraphQLController,InstructorsController,JobsController,RepositoryController,RosterStudentsController,RosterStudentsCSVController,SystemInfoController,TeamsController,UserInfoController,UsersController
This is an abstract class that provides common functionality for all API controllers.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleandoesCurrentUserHaveRole(String roleToCheck) This method checks if the current user has the given roleprotected ObjectgenericMessage(String message) This method returns a generic message.protected CurrentUserThis method returns the current user.This method handles the EntityNotFoundException.This method handles the IllegalArgumentException.This method handles the NoLinkedOrganizationException.This method handles the UnsupportedOperationException.handleValidationException(jakarta.validation.ConstraintViolationException e) This method handles the ConstraintViolationException.protected booleanThis method checks if the current user is an admin.
-
Constructor Details
-
ApiController
public ApiController()
-
-
Method Details
-
getCurrentUser
This method returns the current user.- Returns:
- the current user
-
doesCurrentUserHaveRole
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
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
-
handleValidationException
@ExceptionHandler(jakarta.validation.ConstraintViolationException.class) @ResponseStatus(BAD_REQUEST) public Map<String,String> handleValidationException(jakarta.validation.ConstraintViolationException e) This method handles the ConstraintViolationException. This maps to a 400/Bad Request.- Parameters:
e- the exception- Returns:
- a map with the type and message of the exception
-