Adds User Component
This commit is contained in:
parent
73a1f11e99
commit
69758735de
14 changed files with 222 additions and 65 deletions
33
PlanTempus.Components/Users/Create/CreateUserController.cs
Normal file
33
PlanTempus.Components/Users/Create/CreateUserController.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace PlanTempus.Components.Users.Create
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/users")]
|
||||
public class CreateUserController(CreateUserHandler handler, CreateUserValidator validator) : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<CreateUserResponse>> Create([FromBody] CreateUserCommand command)
|
||||
{
|
||||
try
|
||||
{
|
||||
var validationResult = await validator.ValidateAsync(command);
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
return BadRequest(validationResult.Errors);
|
||||
}
|
||||
|
||||
var result = await handler.Handle(command);
|
||||
return CreatedAtAction(
|
||||
nameof(CreateUserCommand),
|
||||
"GetUser",
|
||||
new { id = result.Id },
|
||||
result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue