implement two queries
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AipsWebApi.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries =
|
||||
[
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
];
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using AipsCore.Application.Abstract;
|
||||
using AipsCore.Application.Models.Whiteboard.Command.AddUserToWhiteboard;
|
||||
using AipsCore.Application.Models.Whiteboard.Command.CreateWhiteboard;
|
||||
using AipsCore.Application.Models.Whiteboard.Query.GetRecentWhiteboards;
|
||||
using AipsCore.Domain.Models.Whiteboard;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AipsWebApi.Controllers;
|
||||
@@ -9,18 +11,33 @@ namespace AipsWebApi.Controllers;
|
||||
[Route("[controller]")]
|
||||
public class WhiteboardController : ControllerBase
|
||||
{
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<int>> CreateWhiteboard(CreateWhiteboardCommand command, IDispatcher dispatcher, CancellationToken cancellationToken)
|
||||
private readonly IDispatcher _dispatcher;
|
||||
|
||||
public WhiteboardController(IDispatcher dispatcher)
|
||||
{
|
||||
var whiteboardId = await dispatcher.Execute(command, cancellationToken);
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<int>> CreateWhiteboard(CreateWhiteboardCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
var whiteboardId = await _dispatcher.Execute(command, cancellationToken);
|
||||
return Ok(whiteboardId.IdValue);
|
||||
}
|
||||
|
||||
[HttpPost("adduser")]
|
||||
public async Task<IActionResult> AddUser(AddUserToWhiteboardCommand command, IDispatcher dispatcher,
|
||||
public async Task<IActionResult> AddUser(AddUserToWhiteboardCommand command,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
await dispatcher.Execute(command, cancellationToken);
|
||||
await _dispatcher.Execute(command, cancellationToken);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("recent")]
|
||||
public async Task<ActionResult<ICollection<Whiteboard>>> Recent(GetRecentWhiteboardsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await _dispatcher.Execute(query, cancellationToken);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user