Commit 9f943cfa authored by hasan khaddour's avatar hasan khaddour

fix paginaton issues

parent 626a2c9b
......@@ -29,11 +29,12 @@ namespace PSManagement.Application.Employees.UseCases.Queries.GetAvailableEmploy
public async Task<Result<IEnumerable<EmployeeDTO>>> Handle(GetAvailableEmployeesQuery request, CancellationToken cancellationToken)
{
int pageNumber = request.PageNumber.HasValue && request.PageNumber.Value > 0 ? request.PageNumber.Value : 1;
int pageSize = request.PageSize.HasValue && request.PageSize.Value > 0 && request.PageSize.Value <= 30 ? request.PageSize.Value : 30;
_specification.ApplyPaging((pageNumber - 1) * pageSize, pageSize);
_specification.ApplyOptionalPagination(request.PageSize, request.PageNumber);
_specification.AddInclude(e => e.Department);
_specification.AddInclude(e => e.User);
return Result.Success(_mapper.Map<IEnumerable<EmployeeDTO>>(await _employeesRepository.ListAsync(_specification)));
}
}
......
......@@ -30,9 +30,7 @@ namespace PSManagement.Application.Employees.UseCases.Queries.GetEmployeeById
public async Task<Result<IEnumerable<EmployeeParticipateDTO>>> Handle(GetEmployeeParticipationQuery request, CancellationToken cancellationToken)
{
int pageNumber = request.PageNumber.HasValue && request.PageNumber.Value > 0 ? request.PageNumber.Value : 1;
int pageSize = request.PageSize.HasValue && request.PageSize.Value > 0 && request.PageSize.Value <= 30 ? request.PageSize.Value : 30;
_specification.ApplyPaging((pageNumber - 1) * pageSize, pageSize);
_specification.ApplyOptionalPagination(request.PageSize, request.PageNumber);
_specification.AddInclude(e => e.Project);
_specification.AddInclude("Employee.User");
......
......@@ -30,15 +30,13 @@ namespace PSManagement.Application.Employees.UseCases.Queries.GetEmployeeTrackHi
public async Task<Result<IEnumerable<EmployeeTrackDTO>>> Handle(GetEmployeeTrackHistoryQuery request, CancellationToken cancellationToken)
{
int pageNumber = request.PageNumber.HasValue && request.PageNumber.Value > 0 ? request.PageNumber.Value : 1;
int pageSize = request.PageSize.HasValue && request.PageSize.Value > 0 && request.PageSize.Value <= 30 ? request.PageSize.Value : 30;
_specification.ApplyOptionalPagination(request.PageSize, request.PageNumber);
_specification.AddInclude(e => e.Track);
_specification.AddInclude(e => e.Employee);
_specification.AddInclude(e => e.Employee.User);
_specification.Criteria = e => e.EmployeeId == request.EmployeeId && e.Track.ProjectId == request.ProjectId;
_specification.ApplyPaging((pageNumber - 1) * pageSize, pageSize);
IEnumerable<EmployeeTrack> employeeTracks = await _employeeTracksRepository.ListAsync( _specification);
return Result.Success(_mapper.Map<IEnumerable<EmployeeTrackDTO>>(employeeTracks));
......
......@@ -29,9 +29,7 @@ namespace PSManagement.Application.Employees.UseCases.Queries.GetEmployeesByFilt
public async Task<Result<IEnumerable<EmployeeDTO>>> Handle(GetEmployeesByFilterQuery request, CancellationToken cancellationToken)
{
int pageNumber = request.PageNumber.HasValue && request.PageNumber.Value > 0 ? request.PageNumber.Value : 1;
int pageSize = request.PageSize.HasValue && request.PageSize.Value > 0 && request.PageSize.Value <= 30 ? request.PageSize.Value : 30;
_specification.ApplyPaging((pageNumber - 1) * pageSize, pageSize);
_specification.ApplyOptionalPagination(request.PageSize, request.PageNumber);
_specification.AddInclude(e=>e.Department);
_specification.AddInclude(e => e.User);
......
......@@ -31,12 +31,7 @@ namespace PSManagement.Application.FinancialSpends.UseCases.Queries.GetFinancial
public async Task<Result<IEnumerable<FinancialSpendingDTO>>> Handle(GetFinancialSpendItemByProjectQuery request, CancellationToken cancellationToken)
{
_specification.Criteria = p => p.ProjectId == request.ProjectId;
int pageNumber = request.PageNumber.HasValue && request.PageNumber.Value > 0 ? request.PageNumber.Value : 1;
int pageSize = request.PageSize.HasValue && request.PageSize.Value > 0 && request.PageSize.Value <= 30 ? request.PageSize.Value : 30;
_specification.ApplyPaging((pageNumber - 1) * pageSize, pageSize);
_specification.ApplyOptionalPagination(request.PageSize, request.PageNumber);
IEnumerable<FinancialSpending> spending = await _spendRepository.ListAsync(_specification);
if (spending is null)
......
......@@ -32,7 +32,15 @@ namespace PSManagement.Application.Projects.UseCases.Queries.GetProjectAttachmen
var attachments = await _attachmentRepository.ListAsync();
attachments = attachments.Where(e => e.ProjectId == request.ProjectId).Skip((pageNumber - 1) * pageSize).Take(pageSize);
if (request.PageSize.HasValue && request.PageNumber.HasValue)
{
attachments = attachments.Where(e => e.ProjectId == request.ProjectId).Skip((pageNumber - 1) * pageSize).Take(pageSize);
}
else {
attachments = attachments.Where(e => e.ProjectId == request.ProjectId);
}
return Result.Success(_mapper.Map<IEnumerable<AttachmentDTO>>(attachments));
}
......
......@@ -34,11 +34,7 @@ namespace PSManagement.Application.Projects.UseCases.Queries.ListAllProject
_specification.AddInclude(e => e.TeamLeader);
_specification.AddInclude(e => e.Executer);
_specification.AddInclude(e => e.Proposer);
int pageNumber = request.PageNumber.HasValue && request.PageNumber.Value > 0 ? request.PageNumber.Value : 1;
int pageSize = request.PageSize.HasValue && request.PageSize.Value > 0 && request.PageSize.Value <= 30 ? request.PageSize.Value : 30;
_specification.ApplyPaging((pageNumber - 1) * pageSize, pageSize);
_specification.ApplyOptionalPagination(request.PageSize, request.PageNumber);
IEnumerable<Project> projects = await _projectsRepository.ListAsync(_specification);
......
......@@ -29,9 +29,7 @@ namespace PSManagement.Application.Projects.UseCases.Queries.ListAllProject
public async Task<Result<IEnumerable<ProjectDetailsDTO>>> Handle(ListAllProjectsQuery request, CancellationToken cancellationToken)
{
int pageNumber=request.PageNumber.HasValue && request.PageNumber.Value > 0 ? request.PageNumber.Value : 1;
int pageSize = request.PageSize.HasValue && request.PageSize.Value > 0 && request.PageSize.Value <= 30 ? request.PageSize.Value : 30;
_specification.ApplyOptionalPagination(request.PageSize, request.PageNumber);
_specification.AddInclude(e => e.ProjectManager);
_specification.AddInclude(e => e.Proposer);
_specification.AddInclude(e => e.TeamLeader);
......@@ -39,8 +37,7 @@ namespace PSManagement.Application.Projects.UseCases.Queries.ListAllProject
_specification.ApplyPaging((pageNumber - 1) * pageSize, pageSize);
var projects = await _projectsRepository.ListAsync(_specification);
return Result.Success(_mapper.Map<IEnumerable<ProjectDetailsDTO>>(projects));
......
......@@ -34,13 +34,9 @@ namespace PSManagement.Application.Tracks.UseCaes.Queries.GetTracksByProject
public async Task<Result<IEnumerable<TrackDTO>>> Handle(GetTracksByProjectQuery request, CancellationToken cancellationToken)
{
int pageNumber = request.PageNumber.HasValue && request.PageNumber.Value > 0 ? request.PageNumber.Value : 1;
int pageSize = request.PageSize.HasValue && request.PageSize.Value > 0 && request.PageSize.Value <= 30 ? request.PageSize.Value : 30;
_specification.ApplyOptionalPagination(request.PageSize,request.PageNumber);
_specification.AddInclude(e => e.Project);
_specification.ApplyPaging((pageNumber - 1) * pageSize, pageSize);
_specification.Criteria = t => t.ProjectId == request.ProjectId;
var project = await _projectsRepository.GetByIdAsync(request.ProjectId);
......
......@@ -46,5 +46,16 @@ namespace PSManagement.SharedKernel.Specification
OrderByDescending = orderByDescendingExpression;
}
public void ApplyOptionalPagination(int? pageSize , int? pageNumber ) {
int actPageNumber = pageNumber.HasValue && pageNumber.Value > 0 ? pageNumber.Value : 1;
int actPageSize = pageSize.HasValue && pageSize.Value > 0 && pageSize.Value <= 30 ? pageSize.Value : 30;
if (pageNumber.HasValue && pageSize.HasValue) {
ApplyPaging((actPageNumber - 1) * actPageSize, actPageSize);
}
}
}
}
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