28 lines
804 B
C#
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));
|
|
}
|
|
}
|