瀏覽代碼

Renaming and changing structure of sort and pagination filters

Feature
Safet Purkovic 4 年之前
父節點
當前提交
51b487302d

二進制
.vs/BlackRock/v17/.suo 查看文件


二進制
BlackRock.Reporting.API/BlackRock.db-shm 查看文件


+ 1
- 1
BlackRock.Reporting.API/Controllers/DocumentsController.cs 查看文件

@@ -31,7 +31,7 @@ namespace BlackRock.Reporting.API.Controllers
}
// GET: api/documents
[HttpGet]
public async Task<IActionResult> GetDocuments(PaggingAndFiltering query)
public async Task<IActionResult> GetDocuments(SortFilter query)
{
throw new DomainException("Relay");
var result = await mediator.GetDocuments(query);

+ 1
- 1
BlackRock.Reporting.API/Core/IUsersRepository.cs 查看文件

@@ -6,6 +6,6 @@ namespace BlackRock.Reporting.API.Core
public interface IUsersRepository : IRepository<User>
{
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 查看文件

@@ -1,10 +0,0 @@
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 查看文件

@@ -1,7 +0,0 @@
namespace BlackRock.Reporting.API.Core.Models
{
public interface IUserPaggingAndFiltering : IPaggingAndFiltering
{
string EmailDomain {get;set;}
}
}

+ 12
- 0
BlackRock.Reporting.API/Core/Models/PagedCollection.cs 查看文件

@@ -0,0 +1,12 @@
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 查看文件

@@ -1,18 +0,0 @@
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 查看文件

@@ -1,12 +0,0 @@
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 查看文件

@@ -0,0 +1,8 @@
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 查看文件

@@ -0,0 +1,8 @@
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 查看文件

@@ -0,0 +1,7 @@
namespace BlackRock.Reporting.API.Core.Models
{
public class UsersFilter : SortFilter
{
public string? EmailDomain { get; set; }
}
}

+ 10
- 9
BlackRock.Reporting.API/Extensions/IQueryableExtensions.cs 查看文件

@@ -5,28 +5,29 @@ namespace BlackRock.Reporting.API.Extensions
{
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) ||
!columnsMap.ContainsKey(queryObj.SortBy))
return query;
if (queryObj.IsSortAscending)
if (queryObj.IsSortAscending.GetValueOrDefault())
return query.OrderBy(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;

if (queryObj.PageSize <= 0)
if (queryObj.PageSize is null)
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 查看文件

@@ -6,7 +6,7 @@ namespace BlackRock.Reporting.API.Mediator.DocumentMediator
public interface IDocumentMediator
{
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>> UpdateDocument(UpdateDocumentForm form);
Task<Result<int>> DeleteDocument(int id);

+ 6
- 6
BlackRock.Reporting.API/Mediator/UserMediator/Queries/GetAllUsersQuery.cs 查看文件

@@ -7,11 +7,11 @@ using MediatR;

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 IMapper mapper;
@@ -22,7 +22,7 @@ namespace BlackRock.Reporting.API.Mediator.UserMediator.Queries
this.mapper = mapper;
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)
throw new ArgumentNullException($"Parameter {nameof(command)} must not be null");
@@ -30,13 +30,13 @@ namespace BlackRock.Reporting.API.Mediator.UserMediator.Queries
try
{
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");
return new Result<PaggingCollection<UserDto>> { Data = usersDto };
return new Result<PagedCollection<UserDto>> { Data = usersDto };
}
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 查看文件

@@ -13,9 +13,9 @@ namespace BlackRock.Reporting.API.Persistence.Repositories
{
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 query = queryResult.AsQueryable();

+ 3
- 0
BlackRock.Reporting.API/obj/staticwebassets.pack.sentinel 查看文件

@@ -137,3 +137,6 @@
2.0
2.0
2.0
2.0
2.0
2.0

Loading…
取消
儲存