Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sorting and paging on QA lists. #253

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public Mapping()
.ForMember(target => target.Notes, options => options.MapFrom(source => source.Notes))
.ForMember(target => target.IsCompleted, options => options.MapFrom(source=> source.IsCompleted))
.ForMember(target => target.IsAccepted, options => options.MapFrom(source=> source.IsAccepted))
#pragma warning disable CS8602 // Dereference of a possibly null reference.
.ForMember(target => target.AssignedTo, options => options.MapFrom(source => source.Owner.DisplayName));
#pragma warning restore CS8602 // Dereference of a possibly null reference.
.ForMember(target => target.AssignedTo, options => options.MapFrom(source => source.Owner!.DisplayName));

CreateMap<EnrolmentQa1QueueEntry, EnrolmentQueueEntryDto>()
.ForMember(target => target.ParticipantId,
Expand All @@ -62,9 +60,7 @@ public Mapping()
source => source.Participant!.Owner!.DisplayName
))
.ForMember(target => target.Notes, options => options.MapFrom(source => source.Notes))
#pragma warning disable CS8602 // Dereference of a possibly null reference.
.ForMember(target => target.AssignedTo, options => options.MapFrom(source => source.Owner.DisplayName));
#pragma warning restore CS8602 // Dereference of a possibly null reference.
.ForMember(target => target.AssignedTo, options => options.MapFrom(source => source.Owner!.DisplayName));

CreateMap<EnrolmentQa2QueueEntry, EnrolmentQueueEntryDto>()
.ForMember(target => target.ParticipantId,
Expand All @@ -82,9 +78,7 @@ public Mapping()
source => source.Participant!.Owner!.DisplayName
))
.ForMember(target => target.Notes, options => options.MapFrom(source => source.Notes))
#pragma warning disable CS8602 // Dereference of a possibly null reference.
.ForMember(target => target.AssignedTo, options => options.MapFrom(source => source.Owner.DisplayName));
#pragma warning restore CS8602 // Dereference of a possibly null reference.;
.ForMember(target => target.AssignedTo, options => options.MapFrom(source => source.Owner!.DisplayName));

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,48 @@ public class Handler(IUnitOfWork unitOfWork, IMapper mapper) : IRequestHandler<Q
{
public async Task<PaginatedData<EnrolmentQueueEntryDto>> Handle(Query request, CancellationToken cancellationToken)
{
var data = await unitOfWork.DbContext.EnrolmentPqaQueue.OrderBy($"{request.OrderBy} {request.SortDirection}")
var query = unitOfWork.DbContext
.EnrolmentPqaQueue
.AsNoTracking();

var sortExpression = GetSortExpression(request);

var ordered = request.SortDirection.Equals("Descending", StringComparison.CurrentCultureIgnoreCase)
? query.OrderByDescending(sortExpression)
: query.OrderBy(sortExpression);

var data = await ordered
.ProjectToPaginatedDataAsync<EnrolmentPqaQueueEntry, EnrolmentQueueEntryDto>(request.Specification, request.PageNumber, request.PageSize, mapper.ConfigurationProvider, cancellationToken);

return data;
}
private Expression<Func<EnrolmentPqaQueueEntry, object?>> GetSortExpression(Query request)
{
Expression<Func<EnrolmentPqaQueueEntry, object?>> sortExpression;
switch (request.OrderBy)
{
case "ParticipantId":
sortExpression = (x => x.Participant!.FirstName + ' ' + x.Participant.LastName);
break;
case "TenantId":
sortExpression = (x => x.TenantId);
break;
case "Created":
sortExpression = (x => x.Created!);
break;
case "SupportWorker":
sortExpression = (x => x.Participant!.Owner!.DisplayName!);
break;
case "AssignedTo":
sortExpression = (x => x.OwnerId == null ? null : x.Owner!.DisplayName);
break;
default:
sortExpression = (x => x.Created!);
break;
}

return sortExpression;
}
}
public class Validator : AbstractValidator<Query>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using Cfo.Cats.Application.Features.QualityAssurance.DTOs;
using Cfo.Cats.Application.SecurityConstants;
using Cfo.Cats.Domain.Entities.Participants;
using FluentValidation;

namespace Cfo.Cats.Application.Features.QualityAssurance.Queries;

public static class Qa1WithPagination
Expand All @@ -24,11 +22,49 @@ public class Handler(IUnitOfWork unitOfWork, IMapper mapper) : IRequestHandler<Q
{
public async Task<PaginatedData<EnrolmentQueueEntryDto>> Handle(Query request, CancellationToken cancellationToken)
{
var data = await unitOfWork.DbContext.EnrolmentQa1Queue.OrderBy($"{request.OrderBy} {request.SortDirection}")
var query = unitOfWork.DbContext
.EnrolmentQa1Queue
.AsNoTracking();

var sortExpression = GetSortExpression(request);

var ordered = request.SortDirection.Equals("Descending", StringComparison.CurrentCultureIgnoreCase)
? query.OrderByDescending(sortExpression)
: query.OrderBy(sortExpression);

var data = await ordered
.ProjectToPaginatedDataAsync<EnrolmentQa1QueueEntry, EnrolmentQueueEntryDto>(request.Specification, request.PageNumber, request.PageSize, mapper.ConfigurationProvider, cancellationToken);

return data;
}

private Expression<Func<EnrolmentQa1QueueEntry, object?>> GetSortExpression(Query request)
{
Expression<Func<EnrolmentQa1QueueEntry, object?>> sortExpression;
switch (request.OrderBy)
{
case "ParticipantId":
sortExpression = (x => x.Participant!.FirstName + ' ' + x.Participant.LastName);
break;
case "TenantId":
sortExpression = (x => x.TenantId);
break;
case "Created":
sortExpression = (x => x.Created!);
break;
case "SupportWorker":
sortExpression = (x => x.Participant!.Owner!.DisplayName!);
break;
case "AssignedTo":
sortExpression = (x => x.OwnerId == null ? null : x.Owner!.DisplayName);
break;
default:
sortExpression = (x => x.Created!);
break;
}

return sortExpression;
}
}
public class Validator : AbstractValidator<Query>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,49 @@ public class Handler(IUnitOfWork unitOfWork, IMapper mapper) : IRequestHandler<Q
{
public async Task<PaginatedData<EnrolmentQueueEntryDto>> Handle(Query request, CancellationToken cancellationToken)
{
var data = await unitOfWork.DbContext.EnrolmentQa2Queue.OrderBy($"{request.OrderBy} {request.SortDirection}")
var query = unitOfWork.DbContext
.EnrolmentQa2Queue
.AsNoTracking();

var sortExpression = GetSortExpression(request);

var ordered = request.SortDirection.Equals("Descending", StringComparison.CurrentCultureIgnoreCase)
? query.OrderByDescending(sortExpression)
: query.OrderBy(sortExpression);

var data = await ordered
.ProjectToPaginatedDataAsync<EnrolmentQa2QueueEntry, EnrolmentQueueEntryDto>(request.Specification, request.PageNumber, request.PageSize, mapper.ConfigurationProvider, cancellationToken);

return data;
}

private Expression<Func<EnrolmentQa2QueueEntry, object?>> GetSortExpression(Query request)
{
Expression<Func<EnrolmentQa2QueueEntry, object?>> sortExpression;
switch (request.OrderBy)
{
case "ParticipantId":
sortExpression = (x => x.Participant!.FirstName + ' ' + x.Participant.LastName);
break;
case "TenantId":
sortExpression = (x => x.TenantId);
break;
case "Created":
sortExpression = (x => x.Created!);
break;
case "SupportWorker":
sortExpression = (x => x.Participant!.Owner!.DisplayName!);
break;
case "AssignedTo":
sortExpression = (x => x.OwnerId == null ? null : x.Owner!.DisplayName);
break;
default:
sortExpression = (x => x.Created!);
break;
}

return sortExpression;
}
}
public class Validator : AbstractValidator<Query>
{
Expand Down
7 changes: 5 additions & 2 deletions src/Server.UI/Pages/QA/Enrolments/Components/QA1List.razor
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@
{
_loading = true;
Query.CurrentUser = UserProfile;
Query.SortDirection = "Desc";
Query.OrderBy = "Created";
Query.OrderBy = state.SortDefinitions.FirstOrDefault()?.SortBy ?? "Created";
Query.SortDirection = state.SortDefinitions.FirstOrDefault()?.Descending ?? true ? SortDirection.Descending.ToString() : SortDirection.Ascending.ToString();
Query.PageNumber = state.Page + 1;
Query.PageSize = state.PageSize;

var result = await GetNewMediator().Send(Query).ConfigureAwait(false);
return new GridData<EnrolmentQueueEntryDto> { TotalItems = result.TotalItems, Items = result.Items };
}
Expand Down
7 changes: 5 additions & 2 deletions src/Server.UI/Pages/QA/Enrolments/Components/QA2List.razor
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,11 @@
{
_loading = true;
Query.CurrentUser = UserProfile;
Query.SortDirection = "Desc";
Query.OrderBy = "Created";
Query.OrderBy = state.SortDefinitions.FirstOrDefault()?.SortBy ?? "Created";
Query.SortDirection = state.SortDefinitions.FirstOrDefault()?.Descending ?? true ? SortDirection.Descending.ToString() : SortDirection.Ascending.ToString();
Query.PageNumber = state.Page + 1;
Query.PageSize = state.PageSize;

var result = await GetNewMediator().Send(Query).ConfigureAwait(false);
return new GridData<EnrolmentQueueEntryDto> { TotalItems = result.TotalItems, Items = result.Items };
}
Expand Down
7 changes: 5 additions & 2 deletions src/Server.UI/Pages/QA/Enrolments/PqaList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@
{
_loading = true;
Query.CurrentUser = UserProfile;
Query.SortDirection = "Desc";
Query.OrderBy = "Created";
Query.OrderBy = state.SortDefinitions.FirstOrDefault()?.SortBy ?? "Created";
Query.SortDirection = state.SortDefinitions.FirstOrDefault()?.Descending ?? true ? SortDirection.Descending.ToString() : SortDirection.Ascending.ToString();
Query.PageNumber = state.Page + 1;
Query.PageSize = state.PageSize;

var result = await GetNewMediator().Send(Query).ConfigureAwait(false);
return new GridData<EnrolmentQueueEntryDto> { TotalItems = result.TotalItems, Items = result.Items };
}
Expand Down
Loading