using Microsoft.AspNetCore.Mvc;
using WebClientBase.Shared;
using WebClientBase.Shared.DTOs;
namespace WebClientBase.Server.Controllers;
///
/// EN: Authentication API controller.
/// VI: Auth API controller.
///
[ApiController]
[Route("api/[controller]")]
public class AuthController : ControllerBase
{
///
/// EN: Register a new user.
/// VI: Đăng ký user mới.
///
/// Registration data with validation
[HttpPost("register")]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public ActionResult> Register([FromBody] RegisterDto request)
{
// EN: [ApiController] validates before this code runs
// VI: [ApiController] validate trước khi code này chạy
// EN: Demo - create user profile
// VI: Demo - tạo user profile
var profile = new UserProfileDto
{
Id = Guid.NewGuid(),
Email = request.Email,
DisplayName = request.DisplayName,
CreatedAt = DateTime.UtcNow
};
return CreatedAtAction(nameof(GetProfile), new { id = profile.Id }, ApiResponse.Ok(profile));
}
///
/// EN: Login with email and password.
/// VI: Đăng nhập với email và mật khẩu.
///
[HttpPost("login")]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status401Unauthorized)]
public ActionResult> Login([FromBody] LoginDto request)
{
// EN: Demo - always succeed with mock profile
// VI: Demo - luôn thành công với profile giả
var profile = new UserProfileDto
{
Id = Guid.NewGuid(),
Email = request.Email,
DisplayName = "Demo User",
CreatedAt = DateTime.UtcNow.AddDays(-30)
};
return Ok(ApiResponse.Ok(profile));
}
///
/// EN: Get user profile by ID.
/// VI: Lấy user profile theo ID.
///
[HttpGet("profile/{id:guid}")]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResponse), StatusCodes.Status404NotFound)]
public ActionResult> GetProfile(Guid id)
{
// EN: Demo - return mock profile
// VI: Demo - trả về profile giả
var profile = new UserProfileDto
{
Id = id,
Email = "demo@example.com",
DisplayName = "Demo User",
AvatarUrl = "https://example.com/avatar.jpg",
CreatedAt = DateTime.UtcNow.AddDays(-30)
};
return Ok(ApiResponse.Ok(profile));
}
}