Class ApiController
java.lang.Object
edu.ucsb.cs156.organic.controllers.ApiController
- Direct Known Subclasses:
CoursesController
,JobsController
,StudentsController
,SystemInfoController
,UserInfoController
,UsersController
Base class for all API controllers. Provides a getCurrentUser() method
and a genericMessage() method.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Object
genericMessage
(String message) Generic message to return in a controller methodprotected CurrentUser
Returns the current user, or null if no user is logged in.com.fasterxml.jackson.databind.ObjectMapper
Special ObjectMapper that ignores Mockito mocksException handler to return HTTP status code 403 Forbidden when an AccessDeniedException is thrownException handler to return HTTP status code 404 Not Found when an EntityNotFoundException is thrownException handler to return HTTP status code 400 Bad Request when an IllegalArgumentException is thrownstatic com.fasterxml.jackson.databind.ObjectMapper
Special ObjectMapper that ignores Mockito mocks
-
Constructor Details
-
ApiController
public ApiController()Constructor that initializes the ObjectMapper
-
-
Method Details
-
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
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
-