Replaces ITaskService/TaskService, completing the CQRS/mediator refactor. All 9 old service interfaces are now gone except IPermissionService, ITokenService, and IPasswordHasher, which stay plain injected services by design (see spec). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using AutoMapper;
|
|
using MediatR;
|
|
using Mws.Application.Common;
|
|
|
|
namespace Mws.Application.Tasks;
|
|
|
|
public record UpdateTaskCommand(Guid UserId, Guid TaskId, UpdateTaskRequest Request) : IRequest<TaskDto>;
|
|
|
|
public class UpdateTaskHandler(IUnitOfWork uow, IMapper mapper) : IRequestHandler<UpdateTaskCommand, TaskDto>
|
|
{
|
|
public async Task<TaskDto> Handle(UpdateTaskCommand command, CancellationToken ct)
|
|
{
|
|
var task = await TaskAccess.GetTaskForUserAsync(uow, command.UserId, command.TaskId, ct);
|
|
|
|
var request = command.Request;
|
|
if (string.IsNullOrWhiteSpace(request.Title))
|
|
{
|
|
throw new BadRequestException("Task title is required");
|
|
}
|
|
|
|
if (request.AssigneeId.HasValue && !await uow.Projects.IsMemberAsync(task.ProjectId, request.AssigneeId.Value, ct))
|
|
{
|
|
throw new BadRequestException("Assignee must be a member of the project");
|
|
}
|
|
|
|
task.Title = request.Title.Trim();
|
|
task.Description = request.Description;
|
|
task.Status = request.Status;
|
|
task.Priority = request.Priority;
|
|
task.AssigneeId = request.AssigneeId;
|
|
task.DueDate = request.DueDate;
|
|
task.UpdatedAt = DateTime.UtcNow;
|
|
|
|
await uow.SaveChangesAsync(ct);
|
|
return await TaskAccess.GetDtoAsync(uow, mapper, task.Id, ct);
|
|
}
|
|
}
|