Update with more optimistic updates

This commit is contained in:
2021-11-21 16:52:56 +01:00
parent bb99f99a22
commit 3c5fe488cd
11 changed files with 80 additions and 2874 deletions

View File

@@ -37,11 +37,15 @@ public class TodosController : ApiController
[HttpPost]
public async Task<ActionResult<string>> CreateTodo(
[FromBody] CreateTodoRequest request)
=> Ok(await Mediator.Send(request.To()));
{
return Ok(await Mediator.Send(request.To()));
}
[HttpGet("{todoId}")]
public async Task<ActionResult<TodoViewModel>> GetTodoById([FromRoute] string todoId)
=> await Mediator.Send(new GetTodoByIdQuery(todoId));
{
return await Mediator.Send(new GetTodoByIdQuery(todoId));
}
[HttpGet]
public async Task<ActionResult<IEnumerable<TodoViewModel>>> GetTodos([FromQuery] bool onlyActive = false)

View File

@@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations;
using System.Threading;
using MediatR;
using Todo.Core.Application.Notifications.Todo;
using Todo.Core.Application.Queries.Todos;
using Todo.Core.Interfaces.Persistence;
using Todo.Core.Interfaces.User;
@@ -10,9 +11,9 @@ namespace Todo.Core.Application.Commands.Todo;
public record CreateTodoCommand(
[Required] string TodoTitle,
string? TodoProject,
string? TodoDescription) : IRequest<string>
string? TodoDescription) : IRequest<TodoViewModel>
{
internal class Handler : IRequestHandler<CreateTodoCommand, string>
internal class Handler : IRequestHandler<CreateTodoCommand, TodoViewModel>
{
private readonly ICurrentUserService _currentUserService;
private readonly IMediator _mediator;
@@ -28,7 +29,7 @@ public record CreateTodoCommand(
_mediator = mediator;
}
public async Task<string> Handle(
public async Task<TodoViewModel> Handle(
CreateTodoCommand request,
CancellationToken cancellationToken)
{
@@ -47,7 +48,7 @@ public record CreateTodoCommand(
new TodoCreated(todo.Id),
cancellationToken);
return todo.Id;
return TodoViewModel.From(todo);
}
}
}