Bladeren bron

Renaming and changing structure of sort and pagination filters

Feature
Safet Purkovic 4 jaren geleden
bovenliggende
commit
51b487302d

BIN
.vs/BlackRock/v17/.suo Bestand weergeven


BIN
BlackRock.Reporting.API/BlackRock.db-shm Bestand weergeven


+ 1
- 1
BlackRock.Reporting.API/Controllers/DocumentsController.cs Bestand weergeven

} }
// GET: api/documents // GET: api/documents
[HttpGet] [HttpGet]
public async Task<IActionResult> GetDocuments(PaggingAndFiltering query)
public async Task<IActionResult> GetDocuments(SortFilter query)
{ {
throw new DomainException("Relay"); throw new DomainException("Relay");
var result = await mediator.GetDocuments(query); var result = await mediator.GetDocuments(query);

+ 1
- 1
BlackRock.Reporting.API/Core/IUsersRepository.cs Bestand weergeven

public interface IUsersRepository : IRepository<User> public interface IUsersRepository : IRepository<User>
{ {
void UpdateEmail(User user,string email); void UpdateEmail(User user,string email);
Task<PaggingCollection<User>> GetAllByFilter(UserPaggingAndFiltering queryObj);
Task<PagedCollection<User>> GetAllByFilter(UsersFilter queryObj);
} }
} }

+ 0
- 10
BlackRock.Reporting.API/Core/Models/IPaggingAndFiltering.cs Bestand weergeven

namespace BlackRock.Reporting.API.Core.Models
{
public interface IPaggingAndFiltering
{
string SortBy { get; set; }
bool IsSortAscending { get; set; }
int Page { get; set; }
int PageSize { get; set; }
}
}

+ 0
- 7
BlackRock.Reporting.API/Core/Models/IUserPaggingAndFiltering.cs Bestand weergeven

namespace BlackRock.Reporting.API.Core.Models
{
public interface IUserPaggingAndFiltering : IPaggingAndFiltering
{
string EmailDomain {get;set;}
}
}

+ 12
- 0
BlackRock.Reporting.API/Core/Models/PagedCollection.cs Bestand weergeven

using System.Collections.ObjectModel;

namespace BlackRock.Reporting.API.Core.Models
{
public class PagedCollection<T> : Collection<T>
where T : class
{
public int Page { set; get; }
public int PageSize { set; get; }
public int TotalCount { set; get; }
}
}

+ 0
- 18
BlackRock.Reporting.API/Core/Models/PaggingAndFiltering.cs Bestand weergeven

namespace BlackRock.Reporting.API.Core.Models
{
public class UserPaggingAndFiltering : IUserPaggingAndFiltering
{
public string? EmailDomain { get ; set ; }
public string? SortBy { get ; set ; }
public bool IsSortAscending { get ; set ; }
public int Page { get ; set ; }
public int PageSize { get ; set ; }
}
public class PaggingAndFiltering : IPaggingAndFiltering
{
public string? SortBy {get;set;}
public bool IsSortAscending {get;set;}
public int Page {get;set;}
public int PageSize {get;set;}
}
}

+ 0
- 12
BlackRock.Reporting.API/Core/Models/PaggingCollection.cs Bestand weergeven

using System.Collections.ObjectModel;

namespace BlackRock.Reporting.API.Core.Models
{
public class PaggingCollection<T> : Collection<T>, IPaggingAndFiltering where T : class
{
public string? SortBy {set;get;}
public bool IsSortAscending {set;get;}
public int Page {set;get;}
public int PageSize {set;get;}
}
}

+ 8
- 0
BlackRock.Reporting.API/Core/Models/PaginationFilter.cs Bestand weergeven

namespace BlackRock.Reporting.API.Core.Models
{
public class PaginationFilter
{
public int? Page { get; set; }
public int? PageSize { get; set; }
}
}

+ 8
- 0
BlackRock.Reporting.API/Core/Models/SortFilter.cs Bestand weergeven

namespace BlackRock.Reporting.API.Core.Models
{
public class SortFilter : PaginationFilter
{
public string? SortBy { get; set; }
public bool? IsSortAscending { get; set; }
}
}

+ 7
- 0
BlackRock.Reporting.API/Core/Models/UsersFilter.cs Bestand weergeven

namespace BlackRock.Reporting.API.Core.Models
{
public class UsersFilter : SortFilter
{
public string? EmailDomain { get; set; }
}
}

+ 10
- 9
BlackRock.Reporting.API/Extensions/IQueryableExtensions.cs Bestand weergeven

{ {
public static class IQueryableExtensions public static class IQueryableExtensions
{ {
public static IQueryable<T> ApplyOrdering<T>(this IQueryable<T> query,
IPaggingAndFiltering queryObj, Dictionary<string, Expression<Func<T, object>>> columnsMap)
public static IQueryable<T> ApplyOrdering<T>(
this IQueryable<T> query,
SortFilter queryObj,
Dictionary<string, Expression<Func<T, object>>> columnsMap)
{ {
if (string.IsNullOrWhiteSpace(queryObj.SortBy) || if (string.IsNullOrWhiteSpace(queryObj.SortBy) ||
!columnsMap.ContainsKey(queryObj.SortBy)) !columnsMap.ContainsKey(queryObj.SortBy))
return query; return query;
if (queryObj.IsSortAscending)
if (queryObj.IsSortAscending.GetValueOrDefault())
return query.OrderBy(columnsMap[queryObj.SortBy]); return query.OrderBy(columnsMap[queryObj.SortBy]);


return query.OrderByDescending(columnsMap[queryObj.SortBy]); return query.OrderByDescending(columnsMap[queryObj.SortBy]);
} }
public static IQueryable<T> ApplyPagging<T>(this IQueryable<T> query,
IPaggingAndFiltering queryObj)
public static IQueryable<T> ApplyPagging<T>(this IQueryable<T> query,PaginationFilter queryObj)
{ {
if (queryObj.Page <= 0)
if (queryObj.Page is null)
queryObj.Page = 1; queryObj.Page = 1;


if (queryObj.PageSize <= 0)
if (queryObj.PageSize is null)
queryObj.PageSize = 10; queryObj.PageSize = 10;


return query.Skip((queryObj.Page - 1) * queryObj.PageSize)
.Take(queryObj.PageSize);
return query.Skip((queryObj.Page.GetValueOrDefault() - 1) * queryObj.PageSize.GetValueOrDefault())
.Take(queryObj.PageSize.GetValueOrDefault());
} }
} }
} }

+ 1
- 1
BlackRock.Reporting.API/Mediator/DocumentMediator/IDocumentMediator.cs Bestand weergeven

public interface IDocumentMediator public interface IDocumentMediator
{ {
Task<Result<Document>> GetDocument(int id); Task<Result<Document>> GetDocument(int id);
Task<Result<PaggingCollection<Document>>> GetDocuments(PaggingAndFiltering query);
Task<Result<PagedCollection<Document>>> GetDocuments(SortFilter query);
Task<Result<int>> CreateDocument(CreateDocumentForm form); Task<Result<int>> CreateDocument(CreateDocumentForm form);
Task<Result<int>> UpdateDocument(UpdateDocumentForm form); Task<Result<int>> UpdateDocument(UpdateDocumentForm form);
Task<Result<int>> DeleteDocument(int id); Task<Result<int>> DeleteDocument(int id);

+ 6
- 6
BlackRock.Reporting.API/Mediator/UserMediator/Queries/GetAllUsersQuery.cs Bestand weergeven



namespace BlackRock.Reporting.API.Mediator.UserMediator.Queries namespace BlackRock.Reporting.API.Mediator.UserMediator.Queries
{ {
public class GetAllUsersQuery : UserPaggingAndFiltering, IRequest<Result<PaggingCollection<UserDto>>>
public class GetAllUsersQuery : UsersFilter, IRequest<Result<PagedCollection<UserDto>>>
{ {
} }


public class GetAllUsersQueryHandlers : IRequestHandler<GetAllUsersQuery, Result<PaggingCollection<UserDto>>>
public class GetAllUsersQueryHandlers : IRequestHandler<GetAllUsersQuery, Result<PagedCollection<UserDto>>>
{ {
private readonly ILogger<GetAllUsersQueryHandlers> logger; private readonly ILogger<GetAllUsersQueryHandlers> logger;
private readonly IMapper mapper; private readonly IMapper mapper;
this.mapper = mapper; this.mapper = mapper;
this.logger = logger; this.logger = logger;
} }
public async Task<Result<PaggingCollection<UserDto>>> Handle(GetAllUsersQuery command, CancellationToken cancellationToken)
public async Task<Result<PagedCollection<UserDto>>> Handle(GetAllUsersQuery command, CancellationToken cancellationToken)
{ {
if (command == null) if (command == null)
throw new ArgumentNullException($"Parameter {nameof(command)} must not be null"); throw new ArgumentNullException($"Parameter {nameof(command)} must not be null");
try try
{ {
var users = await unitOfWork.UsersRepository.GetAllByFilter(command); var users = await unitOfWork.UsersRepository.GetAllByFilter(command);
var usersDto = mapper.Map<PaggingCollection<User>, PaggingCollection<UserDto>>(users);
var usersDto = mapper.Map<PagedCollection<User>, PagedCollection<UserDto>>(users);
logger.LogInformation($"The Users has been founded successfully"); logger.LogInformation($"The Users has been founded successfully");
return new Result<PaggingCollection<UserDto>> { Data = usersDto };
return new Result<PagedCollection<UserDto>> { Data = usersDto };
} }
catch (Exception ex) catch (Exception ex)
{ {
return new Result<PaggingCollection<UserDto>> { IsSuccess = false, Error = "Faild to fetch data from DB." };
return new Result<PagedCollection<UserDto>> { IsSuccess = false, Error = "Faild to fetch data from DB." };
} }
} }
} }

+ 2
- 2
BlackRock.Reporting.API/Persistence/Repositories/UsersRepository.cs Bestand weergeven

{ {
this.context = context; this.context = context;
} }
public async Task<PaggingCollection<User>> GetAllByFilter(UserPaggingAndFiltering queryObj)
public async Task<PagedCollection<User>> GetAllByFilter(UsersFilter queryObj)
{ {
var result = new PaggingCollection<User>();
var result = new PagedCollection<User>();


var queryResult = await context.Users.ToListAsync(); var queryResult = await context.Users.ToListAsync();
var query = queryResult.AsQueryable(); var query = queryResult.AsQueryable();

+ 3
- 0
BlackRock.Reporting.API/obj/staticwebassets.pack.sentinel Bestand weergeven

2.0 2.0
2.0 2.0
2.0 2.0
2.0
2.0
2.0

Laden…
Annuleren
Opslaan