Implements search functionality and prepares for upcoming paging in v0.3.
This commit is contained in:
parent
852317d3a6
commit
2887fab53f
17 changed files with 174 additions and 15 deletions
|
|
@ -22,6 +22,13 @@ namespace API.Helpers
|
|||
CreateMap<Series, SeriesDto>();
|
||||
|
||||
CreateMap<AppUserPreferences, UserPreferencesDto>();
|
||||
|
||||
CreateMap<Series, SearchResultDto>()
|
||||
.ForMember(dest => dest.SeriesId,
|
||||
opt => opt.MapFrom(src => src.Id))
|
||||
.ForMember(dest => dest.LibraryName,
|
||||
opt => opt.MapFrom(src => src.Library.Name));
|
||||
|
||||
|
||||
CreateMap<Library, LibraryDto>()
|
||||
.ForMember(dest => dest.Folders,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,32 @@
|
|||
namespace API.Helpers
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Helpers
|
||||
{
|
||||
public class PagedList
|
||||
public class PagedList<T> : List<T>
|
||||
{
|
||||
|
||||
public PagedList(IEnumerable<T> items, int count, int pageNumber, int pageSize)
|
||||
{
|
||||
CurrentPage = pageNumber;
|
||||
TotalPages = (int) Math.Ceiling(count / (double) pageSize);
|
||||
PageSize = pageSize;
|
||||
TotalCount = count;
|
||||
AddRange(items);
|
||||
}
|
||||
|
||||
public int CurrentPage { get; set; }
|
||||
public int TotalPages { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
public int TotalCount { get; set; }
|
||||
|
||||
public static async Task<PagedList<T>> CreateAsync(IQueryable<T> source, int pageNumber, int pageSize)
|
||||
{
|
||||
var count = await source.CountAsync();
|
||||
var items = await source.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToListAsync();
|
||||
return new PagedList<T>(items, count, pageNumber, pageSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,17 @@
|
|||
{
|
||||
public class PaginationHeader
|
||||
{
|
||||
|
||||
public PaginationHeader(int currentPage, int itemsPerPage, int totalItems, int totalPages)
|
||||
{
|
||||
CurrentPage = currentPage;
|
||||
ItemsPerPage = itemsPerPage;
|
||||
TotalItems = totalItems;
|
||||
TotalPages = totalPages;
|
||||
}
|
||||
|
||||
public int CurrentPage { get; set; }
|
||||
public int ItemsPerPage { get; set; }
|
||||
public int TotalItems { get; set; }
|
||||
public int TotalPages { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,14 @@
|
|||
{
|
||||
public class UserParams
|
||||
{
|
||||
|
||||
private const int MaxPageSize = 50;
|
||||
public int PageNumber { get; set; } = 1;
|
||||
private int _pageSize = 10;
|
||||
|
||||
public int PageSize
|
||||
{
|
||||
get => _pageSize;
|
||||
set => _pageSize = (value > MaxPageSize) ? MaxPageSize : value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue