Class AuthController

java.lang.Object
com.alpaca.controller.AuthController

@RestController @RequestMapping("/auth") public class AuthController extends Object
REST controller for authentication operations.

Provides endpoints for user login, registration, and retrieving the current authenticated user. Utilizes IAuthService for authentication logic.

See Also:
  • Field Details

  • Constructor Details

    • AuthController

      public AuthController()
  • Method Details

    • login

      @PostMapping("/login") public org.springframework.http.ResponseEntity<AuthResponseDTO> login(@Valid @RequestBody @Valid AuthRequestDTO requestDTO)
      Authenticates a user based on provided credentials.
      Parameters:
      requestDTO - the authentication request containing email and password; must not be null
      Returns:
      ResponseEntity containing the AuthResponseDTO with status HttpStatus.OK
      Throws:
      IllegalArgumentException - if the provided credentials are invalid
    • register

      @PostMapping("/register") public org.springframework.http.ResponseEntity<AuthResponseDTO> register(@Valid @RequestBody @Valid AuthRequestDTO requestDTO)
      Registers a new user with the provided credentials.
      Parameters:
      requestDTO - the registration request containing email and password; must not be null
      Returns:
      ResponseEntity containing the AuthResponseDTO with status HttpStatus.OK
      Throws:
      IllegalArgumentException - if the provided credentials are invalid
    • getCurrentUser

      @GetMapping("/me") public org.springframework.http.ResponseEntity<UserPrincipal> getCurrentUser(@AuthenticationPrincipal UserPrincipal user)
      Retrieves the current authenticated user.
      Parameters:
      user - the authenticated user principal; may be null if not authenticated
      Returns:
      ResponseEntity containing the UserPrincipal with status HttpStatus.OK or HttpStatus.UNAUTHORIZED if the user is not authenticated
    • health

      @GetMapping public org.springframework.http.ResponseEntity<String> health()
      Health check endpoint to verify if the API is online.
      Returns:
      ResponseEntity containing a simple string message with status HttpStatus.OK