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.Users.Create
|
|
|
|
|
{
|
2025-03-12 00:13:53 +01:00
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/users")]
|
|
|
|
|
public class CreateUserController(CreateUserHandler handler, CreateUserValidator validator) : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<ActionResult<CommandResponse>> Create([FromBody] CreateUserCommand command)
|
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-04 17:13:02 +01:00
|
|
|
}
|