Adds Generic CommandHandlerDecorator
This commit is contained in:
parent
49f9b99ee1
commit
64e696dc5a
21 changed files with 131 additions and 110 deletions
|
|
@ -1,34 +1,31 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using PlanTempus.Core.CommandQueries;
|
||||
|
||||
namespace PlanTempus.Components.Users.Create
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/users")]
|
||||
public class CreateUserController(CreateUserHandler handler, CreateUserValidator validator) : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<CreateUserResult>> Create([FromBody] CreateUserCommand command)
|
||||
{
|
||||
try
|
||||
{
|
||||
var validationResult = await validator.ValidateAsync(command);
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
return BadRequest(validationResult.Errors);
|
||||
}
|
||||
[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);
|
||||
}
|
||||
|
||||
var result = await handler.Handle(command);
|
||||
|
||||
return CreatedAtAction(
|
||||
nameof(CreateUserCommand),
|
||||
"GetUser",
|
||||
new { id = result.Id },
|
||||
result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
var result = await handler.Handle(command);
|
||||
|
||||
return Accepted($"/api/requests/{result.RequestId}", result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue