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