implement two queries

This commit is contained in:
2026-02-12 00:39:05 +01:00
parent a1e80cb748
commit ae5a2be7e4
9 changed files with 119 additions and 46 deletions

View File

@@ -1,5 +1,6 @@
using AipsCore.Application.Abstract;
using AipsCore.Application.Models.User.Command.CreateUser;
using AipsCore.Application.Models.User.Query.GetUser;
using AipsCore.Domain.Common.Validation;
using AipsCore.Domain.Models.User.ValueObjects;
using Microsoft.AspNetCore.Mvc;
@@ -10,10 +11,25 @@ namespace AipsWebApi.Controllers;
[Route("[controller]")]
public class UserController : ControllerBase
{
[HttpPost]
public async Task<ActionResult<int>> CreateUser(CreateUserCommand command, IDispatcher dispatcher, CancellationToken cancellationToken)
private readonly IDispatcher _dispatcher;
public UserController(IDispatcher dispatcher)
{
var userId = await dispatcher.Execute(command, cancellationToken);
_dispatcher = dispatcher;
}
[HttpGet("{userId}")]
public async Task<IActionResult> GetUser([FromRoute] string userId, CancellationToken cancellationToken)
{
var query = new GetUserQuery(userId);
var result = await _dispatcher.Execute(query, cancellationToken);
return Ok(result);
}
[HttpPost]
public async Task<ActionResult<int>> CreateUser(CreateUserCommand command, CancellationToken cancellationToken)
{
var userId = await _dispatcher.Execute(command, cancellationToken);
return Ok(userId.IdValue);
}
}