2026-08-14 08:37:56 +07:00
|
|
|
using MediatR;
|
2026-08-13 23:10:22 +07:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Mws.Application.Accounts;
|
|
|
|
|
|
|
|
|
|
namespace Mws.Api.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/accounts")]
|
|
|
|
|
[Authorize]
|
2026-08-14 08:37:56 +07:00
|
|
|
public class AccountsController(ISender sender) : ControllerBase
|
2026-08-13 23:10:22 +07:00
|
|
|
{
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult<List<AccountDto>>> GetAll([FromQuery] string? q, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-14 08:37:56 +07:00
|
|
|
return Ok(await sender.Send(new GetAccountsQuery(User.GetUserId(), q), ct));
|
2026-08-13 23:10:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<ActionResult<AccountDto>> Create([FromBody] CreateAccountRequest request, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-14 08:37:56 +07:00
|
|
|
return Ok(await sender.Send(new CreateAccountCommand(User.GetUserId(), request), ct));
|
2026-08-13 23:10:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPut("{id:guid}")]
|
|
|
|
|
public async Task<ActionResult<AccountDto>> Update(Guid id, [FromBody] UpdateAccountRequest request, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-14 08:37:56 +07:00
|
|
|
return Ok(await sender.Send(new UpdateAccountCommand(User.GetUserId(), id, request), ct));
|
2026-08-13 23:10:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpDelete("{id:guid}")]
|
|
|
|
|
public async Task<IActionResult> Delete(Guid id, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-14 08:37:56 +07:00
|
|
|
await sender.Send(new DeleteAccountCommand(User.GetUserId(), id), ct);
|
2026-08-13 23:10:22 +07:00
|
|
|
return NoContent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("{id:guid}/reset-password")]
|
|
|
|
|
public async Task<IActionResult> ResetPassword(Guid id, [FromBody] ResetPasswordRequest request, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-14 08:37:56 +07:00
|
|
|
await sender.Send(new ResetPasswordCommand(User.GetUserId(), id, request), ct);
|
2026-08-13 23:10:22 +07:00
|
|
|
return NoContent();
|
|
|
|
|
}
|
|
|
|
|
}
|