Convert Tasks module to MediatR commands/queries
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>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using Mws.Application.Common;
|
||||
|
||||
namespace Mws.Application.Tasks;
|
||||
|
||||
public record GetTaskQuery(Guid UserId, Guid TaskId) : IRequest<TaskDto>;
|
||||
|
||||
public class GetTaskHandler(IUnitOfWork uow, IMapper mapper) : IRequestHandler<GetTaskQuery, TaskDto>
|
||||
{
|
||||
public async Task<TaskDto> Handle(GetTaskQuery query, CancellationToken ct)
|
||||
{
|
||||
var task = await TaskAccess.GetTaskForUserAsync(uow, query.UserId, query.TaskId, ct);
|
||||
return await TaskAccess.GetDtoAsync(uow, mapper, task.Id, ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using Mws.Application.Common;
|
||||
using TaskPriority = Mws.Domain.Tasks.TaskPriority;
|
||||
using TaskStatus = Mws.Domain.Tasks.TaskStatus;
|
||||
|
||||
namespace Mws.Application.Tasks;
|
||||
|
||||
public record GetTasksQuery(Guid UserId, Guid ProjectId, TaskStatus? Status, TaskPriority? Priority, Guid? AssigneeId)
|
||||
: IRequest<List<TaskDto>>;
|
||||
|
||||
public class GetTasksHandler(IUnitOfWork uow, IMapper mapper) : IRequestHandler<GetTasksQuery, List<TaskDto>>
|
||||
{
|
||||
public async Task<List<TaskDto>> Handle(GetTasksQuery query, CancellationToken ct)
|
||||
{
|
||||
await TaskAccess.EnsureMemberAccessAsync(uow, query.UserId, query.ProjectId, ct);
|
||||
|
||||
var tasks = await uow.Tasks.GetForProjectAsync(query.ProjectId, query.Status, query.Priority, query.AssigneeId, ct);
|
||||
return mapper.Map<List<TaskDto>>(tasks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using AutoMapper;
|
||||
using MediatR;
|
||||
using Mws.Application.Common;
|
||||
|
||||
namespace Mws.Application.Tasks;
|
||||
|
||||
public record SearchTasksQuery(Guid UserId, string Term) : IRequest<List<TaskDto>>;
|
||||
|
||||
public class SearchTasksHandler(IUnitOfWork uow, IMapper mapper) : IRequestHandler<SearchTasksQuery, List<TaskDto>>
|
||||
{
|
||||
public async Task<List<TaskDto>> Handle(SearchTasksQuery query, CancellationToken ct)
|
||||
{
|
||||
var projectIds = await uow.Projects.GetProjectIdsForUserAsync(query.UserId, ct);
|
||||
var tasks = await uow.Tasks.SearchWithAssigneeAsync(projectIds, query.Term, 20, ct);
|
||||
return mapper.Map<List<TaskDto>>(tasks);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user