using AutoMapper; using Mws.Application.Common; using Mws.Domain.Tasks; namespace Mws.Application.Tasks; internal static class TaskAccess { public static async Task GetDtoAsync(IUnitOfWork uow, IMapper mapper, Guid id, CancellationToken ct) { var task = await uow.Tasks.GetWithAssigneeAsync(id, ct) ?? throw new NotFoundException("Task not found"); return mapper.Map(task); } public static async Task GetTaskForUserAsync(IUnitOfWork uow, Guid userId, Guid taskId, CancellationToken ct) { var task = await uow.Tasks.GetByIdAsync(taskId, ct) ?? throw new NotFoundException("Task not found"); if (!await uow.Projects.IsMemberAsync(task.ProjectId, userId, ct)) { throw new NotFoundException("Task not found"); } return task; } public static async Task EnsureMemberAccessAsync(IUnitOfWork uow, Guid userId, Guid projectId, CancellationToken ct) { if (!await uow.Projects.IsMemberAsync(projectId, userId, ct)) { throw new NotFoundException("Project not found"); } } }