Package com.alpaca.controller
Class AuthController
java.lang.Object
com.alpaca.controller.AuthController
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity
<UserPrincipal> getCurrentUser
(UserPrincipal user) Retrieves the current authenticated user.org.springframework.http.ResponseEntity
<String> health()
Health check endpoint to verify if the API is online.org.springframework.http.ResponseEntity
<AuthResponseDTO> login
(@Valid AuthRequestDTO requestDTO) Authenticates a user based on provided credentials.org.springframework.http.ResponseEntity
<AuthResponseDTO> register
(@Valid AuthRequestDTO requestDTO) Registers a new user with the provided credentials.
-
Field Details
-
authService
-
-
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 benull
- Returns:
ResponseEntity
containing theAuthResponseDTO
with statusHttpStatus.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 benull
- Returns:
ResponseEntity
containing theAuthResponseDTO
with statusHttpStatus.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 benull
if not authenticated- Returns:
ResponseEntity
containing theUserPrincipal
with statusHttpStatus.OK
orHttpStatus.UNAUTHORIZED
if the user is not authenticated
-
health
Health check endpoint to verify if the API is online.- Returns:
ResponseEntity
containing a simple string message with statusHttpStatus.OK
-