2026-08-14 08:46:06 +07:00
|
|
|
using AutoMapper;
|
|
|
|
|
using MediatR;
|
2026-08-19 23:25:08 +07:00
|
|
|
using mws.backend.dotnet.application.Common;
|
|
|
|
|
using mws.backend.dotnet.domain.Documents;
|
2026-08-14 08:46:06 +07:00
|
|
|
|
2026-08-19 23:25:08 +07:00
|
|
|
namespace mws.backend.dotnet.application.Projects;
|
2026-08-14 08:46:06 +07:00
|
|
|
|
|
|
|
|
public record GetProjectOverviewQuery(Guid UserId, Guid ProjectId) : IRequest<ProjectOverviewDto>;
|
|
|
|
|
|
|
|
|
|
public class GetProjectOverviewHandler(IUnitOfWork uow, IMapper mapper) : IRequestHandler<GetProjectOverviewQuery, ProjectOverviewDto>
|
|
|
|
|
{
|
|
|
|
|
public async Task<ProjectOverviewDto> Handle(GetProjectOverviewQuery query, CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
var project = await ProjectAccess.GetForUserOrThrowAsync(uow, query.UserId, query.ProjectId, ct);
|
|
|
|
|
|
|
|
|
|
var memberCount = await uow.Projects.CountMembersAsync(query.ProjectId, ct);
|
|
|
|
|
var documentCount = await uow.Documents.CountByTypeForProjectAsync(query.ProjectId, DocumentType.Document, ct);
|
|
|
|
|
|
|
|
|
|
var taskCounts = await uow.Tasks.CountByStatusForProjectAsync(query.ProjectId, ct);
|
|
|
|
|
var taskCountsByStatus = taskCounts.ToDictionary(kv => kv.Key.ToString(), kv => kv.Value);
|
|
|
|
|
|
|
|
|
|
var recentTasks = await uow.Tasks.GetRecentForProjectAsync(query.ProjectId, 5, ct);
|
|
|
|
|
var recentDocuments = await uow.Documents.GetRecentForProjectAsync(query.ProjectId, DocumentType.Document, 5, ct);
|
|
|
|
|
|
|
|
|
|
return new ProjectOverviewDto
|
|
|
|
|
{
|
|
|
|
|
Project = mapper.Map<ProjectDto>(project),
|
|
|
|
|
MemberCount = memberCount,
|
|
|
|
|
DocumentCount = documentCount,
|
|
|
|
|
TaskCountsByStatus = taskCountsByStatus,
|
|
|
|
|
RecentTasks = mapper.Map<List<RecentTaskDto>>(recentTasks),
|
|
|
|
|
RecentDocuments = mapper.Map<List<RecentDocumentDto>>(recentDocuments),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|