Commit 37f508dc authored by hasan khaddour's avatar hasan khaddour

Add Proejct Completion Endpoint

parent 93a3b9aa
......@@ -46,7 +46,7 @@ namespace PSManagement.Application.Projects.UseCases.Queries.GetCompletionContri
_trackSpecification.AddInclude("EmployeeTracks.Employee");
_trackSpecification.Criteria = e => e.ProjectId == request.ProjectId;
_projectSpecification.AddInclude(e=>e.ProjectCompletion);
Project project = await _projectsRepository.GetByIdAsync(request.ProjectId, _projectSpecification);
if (project is null)
......
using Ardalis.Result;
using PSManagement.Application.Projects.Common;
using PSManagement.SharedKernel.CQRS.Query;
using System.Collections.Generic;
namespace PSManagement.Application.Projects.UseCases.Queries.GetProjectCompletion
{
public record GetProjectCompletionQuery(
int ProjectId) : IQuery<Result<ProjectCompletionDTO>>;
}
using Ardalis.Result;
using AutoMapper;
using PSManagement.Application.Projects.Common;
using PSManagement.Domain.Projects;
using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.Repositories;
using PSManagement.SharedKernel.CQRS.Query;
using PSManagement.SharedKernel.Specification;
using System.Threading;
using System.Threading.Tasks;
namespace PSManagement.Application.Projects.UseCases.Queries.GetProjectCompletion
{
public class GetProjectCompletionQueryHandler : IQueryHandler<GetProjectCompletionQuery, Result<ProjectCompletionDTO>>
{
private readonly IProjectsRepository _projectsRepository;
private readonly BaseSpecification<Project> _projectSpecification;
private readonly IMapper _mapper;
public GetProjectCompletionQueryHandler(
IProjectsRepository projectsRepository,
IMapper mapper)
{
_projectSpecification = new ProjectSpecification();
_projectsRepository = projectsRepository;
_mapper = mapper;
}
public async Task<Result<ProjectCompletionDTO>> Handle(GetProjectCompletionQuery request, CancellationToken cancellationToken)
{
_projectSpecification.AddInclude(e => e.ProjectCompletion);
Project project = await _projectsRepository.GetByIdAsync(request.ProjectId, _projectSpecification);
if (project is null)
{
return Result.Invalid(ProjectsErrors.InvalidEntryError);
}
else
{
if (project.ProjectCompletion is null)
{
return Result.Invalid(ProjectsErrors.UnCompletedError);
}
var result = _mapper.Map<ProjectCompletionDTO>(project.ProjectCompletion);
return Result.Success(result);
}
}
}
}
......@@ -27,6 +27,7 @@ using PSManagement.Presentation.Controllers.ApiBase;
using PSManagement.Application.Projects.UseCases.Queries.GetParticipationChangeHistory;
using PSManagement.Application.Projects.UseCases.Queries.GetCompletionContribution;
using PSManagement.Application.Projects.UseCases.Commands.RemoveAttachment;
using PSManagement.Application.Projects.UseCases.Queries.GetProjectCompletion;
namespace PSManagement.Presentation.Controllers.Projects
{
......@@ -78,6 +79,16 @@ namespace PSManagement.Presentation.Controllers.Projects
}
[HttpGet("Completion{id}")]
public async Task<IActionResult> GetProjectCompletion(int id)
{
var query = new GetProjectCompletionQuery(id);
var result = await _sender.Send(query);
return HandleResult(_mapper.Map<Result<ProjectCompletionResponse>>(result));
}
[HttpGet("ParticipationChangeHistory/{id}")]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment