PlanTempusApp/PlanTempus.Components/Accounts/Create/CreateAccountController.cs

32 lines
967 B
C#
Raw Normal View History

2025-03-04 17:13:02 +01:00
using Microsoft.AspNetCore.Mvc;
2025-03-12 00:13:53 +01:00
using PlanTempus.Core.CommandQueries;
2025-03-04 17:13:02 +01:00
namespace PlanTempus.Components.Accounts.Create
2025-03-04 17:13:02 +01:00
{
2025-03-12 00:13:53 +01:00
[ApiController]
[Route("api/accounts")]
public class CreateAccountController(CreateAccountHandler handler, CreateAccountValidator validator) : ControllerBase
2025-03-12 00:13:53 +01:00
{
[HttpPost]
public async Task<ActionResult<CommandResponse>> Create([FromBody] CreateAccountCommand command)
2025-03-12 00:13:53 +01:00
{
try
{
var validationResult = await validator.ValidateAsync(command);
if (!validationResult.IsValid)
{
return BadRequest(validationResult.Errors);
}
2025-03-04 17:13:02 +01:00
2025-03-12 00:13:53 +01:00
var result = await handler.Handle(command);
return Accepted($"/api/requests/{result.RequestId}", result);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
}
}