-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from Kareadita/feature/search
Search
- Loading branch information
Showing
19 changed files
with
235 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace API.DTOs | ||
{ | ||
public class SearchQueryDto | ||
{ | ||
public string QueryString { get; init; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace API.DTOs | ||
{ | ||
public class SearchResultDto | ||
{ | ||
public int SeriesId { get; init; } | ||
public string Name { get; init; } | ||
public string OriginalName { get; init; } | ||
public string SortName { get; init; } | ||
public byte[] CoverImage { get; init; } // This should be optional or a thumbImage (much smaller) | ||
|
||
|
||
// Grouping information | ||
public string LibraryName { get; set; } | ||
public int LibraryId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Text.Json; | ||
using API.Helpers; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace API.Extensions | ||
{ | ||
public static class HttpExtensions | ||
{ | ||
public static void AddPaginationHeader(this HttpResponse response, int currentPage, | ||
int itemsPerPage, int totalItems, int totalPages) | ||
{ | ||
var paginationHeader = new PaginationHeader(currentPage, itemsPerPage, totalItems, totalPages); | ||
response.Headers.Add("Pagination", JsonSerializer.Serialize(paginationHeader)); | ||
response.Headers.Add("Access-Control-Expose-Headers", "Pagination"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace API.Helpers | ||
{ | ||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace API.Helpers | ||
{ | ||
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace API.Helpers | ||
{ | ||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.