2026-08-17 21:06:40 +07:00
|
|
|
using AutoMapper;
|
2026-08-19 23:25:08 +07:00
|
|
|
using mws.backend.dotnet.application.Common;
|
|
|
|
|
using mws.backend.dotnet.domain.Tasks;
|
2026-08-17 21:06:40 +07:00
|
|
|
|
2026-08-19 23:25:08 +07:00
|
|
|
namespace mws.backend.dotnet.application.Tasks;
|
2026-08-17 21:06:40 +07:00
|
|
|
|
|
|
|
|
internal static class TaskAccess
|
|
|
|
|
{
|
|
|
|
|
public static async Task<TaskDto> 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<TaskDto>(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<TaskItem> 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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|