Files
2026-08-19 23:25:08 +07:00

28 lines
804 B
C#

using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using mws.backend.dotnet.application.Auth;
using mws.backend.dotnet.application.Users;
namespace mws.backend.dotnet.api.Controllers;
[ApiController]
[Route("api/auth")]
public class AuthController(ISender sender) : ControllerBase
{
[HttpPost("login")]
[AllowAnonymous]
public async Task<ActionResult<LoginResponse>> Login([FromBody] LoginRequest request, CancellationToken ct)
{
var response = await sender.Send(new LoginCommand(request), ct);
return Ok(response);
}
[HttpGet("me")]
[Authorize]
public async Task<ActionResult<UserDto>> GetProfile(CancellationToken ct)
{
return Ok(await sender.Send(new GetProfileQuery(User.GetUserId()), ct));
}
}