Replaces IAccountService/AccountService with one command/query per operation, following the pattern set in the Auth module. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using MediatR;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Mws.Application.Accounts;
|
|
|
|
namespace Mws.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/accounts")]
|
|
[Authorize]
|
|
public class AccountsController(ISender sender) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
public async Task<ActionResult<List<AccountDto>>> GetAll([FromQuery] string? q, CancellationToken ct)
|
|
{
|
|
return Ok(await sender.Send(new GetAccountsQuery(User.GetUserId(), q), ct));
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<ActionResult<AccountDto>> Create([FromBody] CreateAccountRequest request, CancellationToken ct)
|
|
{
|
|
return Ok(await sender.Send(new CreateAccountCommand(User.GetUserId(), request), ct));
|
|
}
|
|
|
|
[HttpPut("{id:guid}")]
|
|
public async Task<ActionResult<AccountDto>> Update(Guid id, [FromBody] UpdateAccountRequest request, CancellationToken ct)
|
|
{
|
|
return Ok(await sender.Send(new UpdateAccountCommand(User.GetUserId(), id, request), ct));
|
|
}
|
|
|
|
[HttpDelete("{id:guid}")]
|
|
public async Task<IActionResult> Delete(Guid id, CancellationToken ct)
|
|
{
|
|
await sender.Send(new DeleteAccountCommand(User.GetUserId(), id), ct);
|
|
return NoContent();
|
|
}
|
|
|
|
[HttpPost("{id:guid}/reset-password")]
|
|
public async Task<IActionResult> ResetPassword(Guid id, [FromBody] ResetPasswordRequest request, CancellationToken ct)
|
|
{
|
|
await sender.Send(new ResetPasswordCommand(User.GetUserId(), id, request), ct);
|
|
return NoContent();
|
|
}
|
|
}
|