Update with more optimistic updates
This commit is contained in:
@@ -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)
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user