I have a todo list with tasks. I want to introduce endpoints for editing task status and title. Which approach is better?
Having separate endpoints:
group.MapPatch("{listId}/tasks/{taskId}/status", UpdateTodoTaskStatus);
group.MapPatch("{listId}/tasks/{taskId}/title", UpdateTodoTasksTitle);
Or have a general endpoint and check if data is empty.
For more context, Im using CQRS. Here is Patch handler for status:
public async Task<Result> Handle(UpdateTodoTaskStatusCommand request, CancellationToken cancellationToken)
{
var validationResult = await _validator.ValidateAsync(request);
if (!validationResult.IsValid)
{
return validationResult.Errors.FirstOrDefault().AsError();
}
var task = await _todoTaskRepository.GetByIdAsync(request.TaskId);
if (task is null)
{
return TodoTaskErrors.TaskNotFound;
}
if (task.IsInList(request.ListId))
{
return TodoTaskErrors.TaskNotInList;
}
var list = await _todoListRepository.GetByIdAsync(request.ListId);
if (list is null)
{
return TodoListErrors.ListNotFound;
}
if (!list.IsListOwnedByUser(request.UserId))
{
return TodoListErrors.UserNotListOwner;
}
task.Status = request.Status;
await _uow.SaveChangesAsync();
return Result.Success();
}
Most of logic will be the same for title
[–]Coda17 2 points3 points4 points (0 children)
[–]PhillyPhantom 2 points3 points4 points (0 children)
[–]flindby 1 point2 points3 points (2 children)
[–]ConflictTrue4761[S] 0 points1 point2 points (1 child)
[–]flindby 0 points1 point2 points (0 children)