backend/src/main/java/com/magamochi/user/controller/AuthenticationController.java

55 lines
1.9 KiB
Java

package com.magamochi.user.controller;
import com.magamochi.model.dto.*;
import com.magamochi.user.model.dto.AuthenticationRequestDTO;
import com.magamochi.user.model.dto.AuthenticationResponseDTO;
import com.magamochi.user.model.dto.RefreshTokenRequestDTO;
import com.magamochi.user.model.dto.RegistrationRequestDTO;
import com.magamochi.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/auth")
@CrossOrigin(origins = "*")
@RequiredArgsConstructor
public class AuthenticationController {
private final UserService userService;
@Operation(
summary = "Authenticate user",
description = "Authenticate user with email and password.",
tags = {"Auth"},
operationId = "authenticateUser")
@PostMapping("/login")
public DefaultResponseDTO<AuthenticationResponseDTO> authenticateUser(
@RequestBody AuthenticationRequestDTO authenticationRequestDTO) {
return DefaultResponseDTO.ok(userService.authenticate(authenticationRequestDTO));
}
@Operation(
summary = "Refresh authentication token",
description = "Refresh the authentication token",
tags = {"Auth"},
operationId = "refreshAuthToken")
@PostMapping("/refresh")
public DefaultResponseDTO<AuthenticationResponseDTO> refreshAuthToken(
@RequestBody RefreshTokenRequestDTO authenticationRequestDTO) {
return DefaultResponseDTO.ok(userService.refreshAuthToken(authenticationRequestDTO));
}
@Operation(
summary = "Register user",
description = "Register a new user.",
tags = {"Auth"},
operationId = "registerUser")
@PostMapping("/register")
public DefaultResponseDTO<Void> registerUser(
@RequestBody RegistrationRequestDTO registrationRequestDTO) {
userService.register(registrationRequestDTO);
return DefaultResponseDTO.ok().build();
}
}