Class AbstractController

java.lang.Object
net.andresbustamante.yafoot.commons.web.controllers.AbstractController

@Validated public abstract class AbstractController extends Object
Abstract controller for common RESTful controllers operations.
Author:
andresbustamante
  • Field Details

    • DATABASE_BASIC_ERROR

      protected static final String DATABASE_BASIC_ERROR
      Code to use for generic database errors.
      See Also:
    • UNAUTHORISED_USER_ERROR

      protected static final String 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

      protected URI getLocationURI(String location)
      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

      protected String translate(String messageCode, String[] parameters)
      Translates a given code using some parameters into the user's language.
      Parameters:
      messageCode - Code to find for translation
      parameters - Parameters to replace on the translated message
      Returns:
      Translated message
    • getObjectMapper

      public Optional<com.fasterxml.jackson.databind.ObjectMapper> getObjectMapper()
      OpenAPI auto-generated method.
      Returns:
      Optional for object mapper
    • getRequest

      public Optional<jakarta.servlet.http.HttpServletRequest> getRequest()
      OpenAPI auto-generated method.
      Returns:
      Optional for object mapper