2025-03-04 17:13:02 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace PlanTempus.Components.Users.Create
|
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/users")]
|
|
|
|
|
public class CreateUserController(CreateUserHandler handler, CreateUserValidator validator) : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
[HttpPost]
|
2025-03-04 23:54:55 +01:00
|
|
|
public async Task<ActionResult<CreateUserResult>> Create([FromBody] CreateUserCommand command)
|
2025-03-04 17:13:02 +01:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var validationResult = await validator.ValidateAsync(command);
|
|
|
|
|
if (!validationResult.IsValid)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(validationResult.Errors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = await handler.Handle(command);
|
2025-03-05 16:56:58 +01:00
|
|
|
|
2025-03-04 17:13:02 +01:00
|
|
|
return CreatedAtAction(
|
|
|
|
|
nameof(CreateUserCommand),
|
|
|
|
|
"GetUser",
|
|
|
|
|
new { id = result.Id },
|
|
|
|
|
result);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|