Files
mws.backend.dotnet/api/Controllers/AuthController.cs
T

28 lines
804 B
C#
Raw Normal View History

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