Class AbstractController
java.lang.Object
net.andresbustamante.yafoot.commons.web.controllers.AbstractController
Abstract controller for common RESTful controllers operations.
- Author:
- andresbustamante
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected URI
getLocationURI
(String location) Builds a basic URI for a location header.Optional<com.fasterxml.jackson.databind.ObjectMapper>
OpenAPI auto-generated method.Optional<jakarta.servlet.http.HttpServletRequest>
OpenAPI auto-generated method.protected net.andresbustamante.yafoot.commons.model.UserContext
Gets the connected user from a given request.protected org.springframework.http.ResponseEntity<ErrorResponse>
handleConstraintViolationException
(jakarta.validation.ConstraintViolationException e) Transforms a ConstraintViolationException into a 400 error code.protected String
Translates a given code using some parameters into the user's language.
-
Field Details
-
DATABASE_BASIC_ERROR
Code to use for generic database errors.- See Also:
-
UNAUTHORISED_USER_ERROR
Code to use for authorisation errors.- See Also:
-
-
Constructor Details
-
AbstractController
public AbstractController()
-
-
Method Details
-
handleConstraintViolationException
@ExceptionHandler(jakarta.validation.ConstraintViolationException.class) protected org.springframework.http.ResponseEntity<ErrorResponse> handleConstraintViolationException(jakarta.validation.ConstraintViolationException e) Transforms a ConstraintViolationException into a 400 error code.- Parameters:
e
- Exception to check- Returns:
- ResponseEntity with a "Bad request" code and message
-
getLocationURI
Builds a basic URI for a location header.- Parameters:
location
- Relative location- Returns:
- URI with absolute location
-
getUserContext
protected net.andresbustamante.yafoot.commons.model.UserContext getUserContext()Gets the connected user from a given request.- Returns:
- Connected user's context
-
translate
Translates a given code using some parameters into the user's language.- Parameters:
messageCode
- Code to find for translationparameters
- Parameters to replace on the translated message- Returns:
- Translated message
-
getObjectMapper
OpenAPI auto-generated method.- Returns:
- Optional for object mapper
-
getRequest
OpenAPI auto-generated method.- Returns:
- Optional for object mapper
-