Class ApiController

java.lang.Object
edu.ucsb.cs156.organic.controllers.ApiController
Direct Known Subclasses:
CoursesController, JobsController, StudentsController, SystemInfoController, UserInfoController, UsersController

public abstract class ApiController extends Object
Base class for all API controllers. Provides a getCurrentUser() method and a genericMessage() method.
  • Constructor Details

    • ApiController

      public ApiController()
      Constructor that initializes the ObjectMapper
  • Method Details

    • getCurrentUser

      protected CurrentUser getCurrentUser()
      Returns the current user, or null if no user is logged in.
      Returns:
      CurrentUser current user or null
    • handleIllegalArgumentException

      @ExceptionHandler(java.lang.IllegalArgumentException.class) @ResponseStatus(BAD_REQUEST) public Object handleIllegalArgumentException(Throwable e)
      Exception handler to return HTTP status code 400 Bad Request when an IllegalArgumentException is thrown
      Parameters:
      e - IllegalArgumentException
      Returns:
      map with type and message
    • handleGenericException

      @ExceptionHandler(EntityNotFoundException.class) @ResponseStatus(NOT_FOUND) public Object handleGenericException(Throwable e)
      Exception handler to return HTTP status code 404 Not Found when an EntityNotFoundException is thrown
      Parameters:
      e - EntityNotFoundException
      Returns:
      map with type and message
    • handleAccessDeniedException

      @ExceptionHandler(org.springframework.security.access.AccessDeniedException.class) @ResponseStatus(FORBIDDEN) public Object handleAccessDeniedException(Throwable e)
      Exception handler to return HTTP status code 403 Forbidden when an AccessDeniedException is thrown
      Parameters:
      e - AccessDeniedException
      Returns:
      map with type and message
    • genericMessage

      protected Object genericMessage(String message)
      Generic message to return in a controller method
      Parameters:
      message -
      Returns:
      map with message
    • getMapper

      public com.fasterxml.jackson.databind.ObjectMapper getMapper()
      Special ObjectMapper that ignores Mockito mocks
      Returns:
      ObjectMapper mapper
    • mapperThatIgnoresMockitoMocks

      public static com.fasterxml.jackson.databind.ObjectMapper mapperThatIgnoresMockitoMocks()
      Special ObjectMapper that ignores Mockito mocks
      Returns:
      ObjectMapper mapper