mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Merge pull request #152 from BinaryAlley/feature/alpha-picker-filtering
Feature/alpha picker filtering
This commit is contained in:
57 files changed
+1623
-165
No files matched your search
@@ -13,4 +13,17 @@ public record LibraryFilterDto : BaseFilterDto
|
||||
/// The Id of the media library used to filter data.
|
||||
/// </summary>
|
||||
public required Guid LibraryId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The alpha key used to filter the data by the first character of the item title, for the alpha picker.
|
||||
/// Can be <see langword="null"/> to disable alpha filtering, a single ASCII letter (case-insensitive) to filter by that letter,
|
||||
/// <see cref="LibraryItemAlphaKeys.NUMBER"/> to filter by titles whose first character is a digit,
|
||||
/// or <see cref="LibraryItemAlphaKeys.SYMBOL"/> to filter by titles whose first character is neither a letter nor a digit.
|
||||
/// </summary>
|
||||
public string? FilterAlphaKey { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.
|
||||
/// </summary>
|
||||
public bool IgnoreThePrefixForAlphaPicker { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.Filtering;
|
||||
|
||||
/// <summary>
|
||||
/// Collection of the special alpha keys that can be used for alpha filtering, in addition to the single letters.
|
||||
/// </summary>
|
||||
public static class LibraryItemAlphaKeys
|
||||
{
|
||||
/// <summary>
|
||||
/// The alpha key that filters the items by titles whose first character is a digit.
|
||||
/// </summary>
|
||||
public const string NUMBER = "#";
|
||||
|
||||
/// <summary>
|
||||
/// The alpha key that filters the items by titles whose first character is neither a letter nor a digit.
|
||||
/// </summary>
|
||||
public const string SYMBOL = "*";
|
||||
}
|
||||
+3
-1
@@ -30,7 +30,9 @@ public static class GetBooksLiteRequestMapping
|
||||
LibraryFilterDto libraryFilter = new()
|
||||
{
|
||||
LibraryId = request.LibraryId,
|
||||
SearchTerm = request.SearchTerm
|
||||
SearchTerm = request.SearchTerm,
|
||||
FilterAlphaKey = request.FilterAlphaKey,
|
||||
IgnoreThePrefixForAlphaPicker = request.IgnoreThePrefixForAlphaPicker
|
||||
};
|
||||
|
||||
return new GetBooksLiteQuery(paginationData, libraryFilter, request.SortBy, request.SortOrder);
|
||||
|
||||
+10
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
@@ -22,5 +23,14 @@ public class GetBooksLiteQueryValidator : AbstractValidator<GetBooksLiteQuery>
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty)
|
||||
.Must(id => id != Guid.Empty)
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
// the alpha key must be exactly one of the three picker bucket kinds, so that the filter specification can
|
||||
// derive the key of a title unambiguously: no filter, a number bucket, a symbol bucket, or a single ASCII letter
|
||||
RuleFor(query => query.Filter.FilterAlphaKey)
|
||||
.Must(alphaKey => alphaKey is null
|
||||
|| alphaKey == LibraryItemAlphaKeys.NUMBER
|
||||
|| alphaKey == LibraryItemAlphaKeys.SYMBOL
|
||||
|| (alphaKey.Length == 1 && char.IsAsciiLetter(alphaKey[0])))
|
||||
.WithError(Errors.Library.InvalidFilterAlphaKey);
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="10.0.11" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+8
@@ -13,6 +13,12 @@ namespace Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibra
|
||||
/// <param name="CurrentPage">The page of results to retrieve. Optional.</param>
|
||||
/// <param name="PerPage">The maximum number of books to retrieve per page. Optional.</param>
|
||||
/// <param name="SearchTerm">The search term used to filter results. Optional.</param>
|
||||
/// <param name="FilterAlphaKey">
|
||||
/// The alpha key used to filter the results by the first character of their title, for the alpha picker. Optional.
|
||||
/// Can be <see langword="null"/> to disable alpha filtering, a single ASCII letter (case-insensitive) to filter by that letter,
|
||||
/// "#" to filter by titles whose first character is a digit, or "*" to filter by titles whose first character is neither a letter nor a digit.
|
||||
/// </param>
|
||||
/// <param name="IgnoreThePrefixForAlphaPicker">Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
|
||||
/// <param name="SortBy">The name of the field by which to sort the results. Optional.</param>
|
||||
/// <param name="SortOrder">The direction in which to sort the results. Optional.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
@@ -21,6 +27,8 @@ public record GetBooksLiteRequest(
|
||||
int? CurrentPage,
|
||||
int? PerPage,
|
||||
string? SearchTerm,
|
||||
string? FilterAlphaKey,
|
||||
bool IgnoreThePrefixForAlphaPicker,
|
||||
string? SortBy,
|
||||
SortOrder? SortOrder
|
||||
);
|
||||
@@ -15,6 +15,8 @@ using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -26,6 +28,10 @@ namespace Lumina.DataAccess.Core.Repositories.Books;
|
||||
/// </summary>
|
||||
internal sealed class BookRepository : IBookRepository
|
||||
{
|
||||
private static readonly MethodInfo s_toLowerMethod = typeof(string).GetMethod(nameof(string.ToLower), Type.EmptyTypes)!;
|
||||
private static readonly MethodInfo s_startsWithMethod = typeof(string).GetMethod(nameof(string.StartsWith), [typeof(string)])!;
|
||||
private static readonly MethodInfo s_substringMethod = typeof(string).GetMethod(nameof(string.Substring), [typeof(int)])!;
|
||||
|
||||
private readonly LuminaDbContext _luminaDbContext;
|
||||
|
||||
/// <summary>
|
||||
@@ -120,13 +126,13 @@ internal sealed class BookRepository : IBookRepository
|
||||
|
||||
booksQuery = booksQuery.Where(book => book.LibraryId == libraryFilter.LibraryId);
|
||||
|
||||
FilterSpecification<BookEntity>? filterSpecification = BuildFilterSpecification(libraryFilter.SearchTerm);
|
||||
FilterSpecification<BookEntity>? filterSpecification = BuildFilterSpecification(libraryFilter);
|
||||
// apply filtering
|
||||
if (filterSpecification is not null)
|
||||
booksQuery = booksQuery.Where(filterSpecification.ToExpression());
|
||||
|
||||
// apply sorting based on the specified sortBy and sortOrder parameters
|
||||
booksQuery = ApplySorting(booksQuery, sortBy, sortOrder ?? SortOrder.Ascending);
|
||||
booksQuery = ApplySorting(booksQuery, sortBy, sortOrder ?? SortOrder.Ascending, libraryFilter.IgnoreThePrefixForAlphaPicker);
|
||||
|
||||
// if no pagination was requested, return all the books of the library
|
||||
if (paginationData is null)
|
||||
@@ -255,7 +261,8 @@ internal sealed class BookRepository : IBookRepository
|
||||
/// <param name="booksQuery">The query to sort.</param>
|
||||
/// <param name="sortBy">The field to sort by (case-insensitive).</param>
|
||||
/// <param name="sortOrder">The direction of the sorting.</param>
|
||||
private static IOrderedQueryable<BookEntity> ApplySorting(IQueryable<BookEntity> booksQuery, string? sortBy, SortOrder sortOrder)
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Whether a leading "the " prefix of a title is ignored when deriving the title sort key, or not.</param>
|
||||
private static IOrderedQueryable<BookEntity> ApplySorting(IQueryable<BookEntity> booksQuery, string? sortBy, SortOrder sortOrder, bool ignoreThePrefixForAlphaPicker)
|
||||
{
|
||||
return sortBy?.ToLower() switch
|
||||
{
|
||||
@@ -269,23 +276,67 @@ internal sealed class BookRepository : IBookRepository
|
||||
? booksQuery.OrderByDescending(book => book.MetadataProvider)
|
||||
: booksQuery.OrderBy(book => book.MetadataProvider),
|
||||
_ => sortOrder == SortOrder.Descending
|
||||
? booksQuery.OrderByDescending(book => book.Title)
|
||||
: booksQuery.OrderBy(book => book.Title),
|
||||
? booksQuery.OrderByDescending(BuildTitleSortKey(ignoreThePrefixForAlphaPicker))
|
||||
: booksQuery.OrderBy(BuildTitleSortKey(ignoreThePrefixForAlphaPicker)),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the expression that derives the title sort key of a book, matching the effective title used by the alpha filter:
|
||||
/// the title lowercased, falling back to the original title when the title is <see langword="null"/> or empty, and optionally
|
||||
/// stripped of a leading "the " prefix.
|
||||
/// </summary>
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Whether a leading "the " prefix of a title is ignored when deriving the title sort key, or not.</param>
|
||||
/// <returns>An expression that evaluates to the title sort key of a book.</returns>
|
||||
private static Expression<Func<BookEntity, string>> BuildTitleSortKey(bool ignoreThePrefixForAlphaPicker)
|
||||
{
|
||||
ParameterExpression book = Expression.Parameter(typeof(BookEntity), "book");
|
||||
|
||||
Expression titleProperty = Expression.Property(book, nameof(BookEntity.Title));
|
||||
|
||||
// the raw title: the title, unless it is null or empty, in which case the original title (or an empty string) is used
|
||||
BinaryExpression isTitleMissing = Expression.OrElse(
|
||||
Expression.Equal(titleProperty, Expression.Constant(null, typeof(string))),
|
||||
Expression.Equal(titleProperty, Expression.Constant(string.Empty)));
|
||||
Expression rawTitle = Expression.Condition(isTitleMissing,
|
||||
Expression.Coalesce(Expression.Property(book, nameof(BookEntity.OriginalTitle)), Expression.Constant(string.Empty)),
|
||||
titleProperty);
|
||||
|
||||
MethodCallExpression lowerTitle = Expression.Call(rawTitle, s_toLowerMethod);
|
||||
|
||||
// when ignoring the "The " prefix, strip a leading "the " from the lowercased title
|
||||
Expression effectiveTitle = lowerTitle;
|
||||
if (ignoreThePrefixForAlphaPicker)
|
||||
{
|
||||
MethodCallExpression startsWithThe = Expression.Call(lowerTitle, s_startsWithMethod, Expression.Constant("the "));
|
||||
MethodCallExpression strippedTitle = Expression.Call(lowerTitle, s_substringMethod, Expression.Constant(4));
|
||||
effectiveTitle = Expression.Condition(startsWithThe, strippedTitle, lowerTitle);
|
||||
}
|
||||
|
||||
return Expression.Lambda<Func<BookEntity, string>>(effectiveTitle, book);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a filter specification for querying books.
|
||||
/// </summary>
|
||||
/// <param name="searchTerm">The search term used to filter results.</param>
|
||||
/// <param name="libraryFilter">The model containing the parameters used to filter the results.</param>
|
||||
/// <returns>A filter specification that can be used to query books matching the provided criteria.</returns>
|
||||
private static FilterSpecification<BookEntity>? BuildFilterSpecification(string? searchTerm)
|
||||
private static FilterSpecification<BookEntity>? BuildFilterSpecification(LibraryFilterDto libraryFilter)
|
||||
{
|
||||
FilterSpecification<BookEntity>? filterSpecification = null;
|
||||
|
||||
// include the search term filter here, if provided
|
||||
if (!string.IsNullOrWhiteSpace(searchTerm))
|
||||
filterSpecification = new BookSearchSpecification(searchTerm);
|
||||
|
||||
// include the search term filter, if provided
|
||||
if (!string.IsNullOrWhiteSpace(libraryFilter.SearchTerm))
|
||||
filterSpecification = new BookSearchSpecification(libraryFilter.SearchTerm);
|
||||
|
||||
// include the alpha key filter, if provided
|
||||
if (libraryFilter.FilterAlphaKey is not null)
|
||||
{
|
||||
BookAlphaFilterSpecification alphaFilterSpecification = new(libraryFilter.FilterAlphaKey, libraryFilter.IgnoreThePrefixForAlphaPicker);
|
||||
filterSpecification = filterSpecification is null
|
||||
? alphaFilterSpecification
|
||||
: filterSpecification.And(alphaFilterSpecification);
|
||||
}
|
||||
|
||||
return filterSpecification;
|
||||
}
|
||||
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.Specifications;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Core.Repositories.Books.Specifications;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a filter specification for filtering books by the alpha key of their title, for the alpha picker.
|
||||
/// The alpha key is the first character of the title, lowercased, and optionally computed after ignoring a leading "The " prefix.
|
||||
/// </summary>
|
||||
internal sealed class BookAlphaFilterSpecification : FilterSpecification<BookEntity>
|
||||
{
|
||||
private static readonly MethodInfo s_toLowerMethod = typeof(string).GetMethod(nameof(string.ToLower), Type.EmptyTypes)!;
|
||||
private static readonly MethodInfo s_startsWithMethod = typeof(string).GetMethod(nameof(string.StartsWith), [typeof(string)])!;
|
||||
private static readonly MethodInfo s_substringMethod = typeof(string).GetMethod(nameof(string.Substring), [typeof(int)])!;
|
||||
private static readonly MethodInfo s_globMethod = typeof(SqliteDbFunctionsExtensions)
|
||||
.GetMethod(nameof(SqliteDbFunctionsExtensions.Glob), [typeof(DbFunctions), typeof(string), typeof(string)])!;
|
||||
|
||||
private readonly string? _filterAlphaKey;
|
||||
private readonly bool _ignoreThePrefixForAlphaPicker;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookAlphaFilterSpecification"/> class.
|
||||
/// </summary>
|
||||
/// <param name="filterAlphaKey">The alpha key to filter by. A single ASCII letter, <see cref="LibraryItemAlphaKeys.NUMBER"/>, or <see cref="LibraryItemAlphaKeys.SYMBOL"/>.</param>
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
|
||||
public BookAlphaFilterSpecification(string? filterAlphaKey, bool ignoreThePrefixForAlphaPicker)
|
||||
{
|
||||
_filterAlphaKey = filterAlphaKey;
|
||||
_ignoreThePrefixForAlphaPicker = ignoreThePrefixForAlphaPicker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a LINQ expression that represents the predicate defined by the current specification.
|
||||
/// </summary>
|
||||
/// <returns>An expression tree that can be used to evaluate whether a <see cref="BookEntity"/> satisfies the specification criteria.</returns>
|
||||
public override Expression<Func<BookEntity, bool>> ToExpression()
|
||||
{
|
||||
// when no alpha key was requested, every book matches
|
||||
if (_filterAlphaKey is null)
|
||||
return book => true;
|
||||
|
||||
ParameterExpression book = Expression.Parameter(typeof(BookEntity), "book");
|
||||
Expression effectiveTitle = BuildEffectiveTitle(book);
|
||||
|
||||
if (_filterAlphaKey == LibraryItemAlphaKeys.NUMBER)
|
||||
return BuildGlobPredicate(book, effectiveTitle, "[0-9]*");
|
||||
|
||||
if (_filterAlphaKey == LibraryItemAlphaKeys.SYMBOL)
|
||||
return BuildSymbolPredicate(book, effectiveTitle);
|
||||
|
||||
// the alpha key is a single ASCII letter
|
||||
string globPattern = char.ToLowerInvariant(_filterAlphaKey[0]) + "*";
|
||||
return BuildGlobPredicate(book, effectiveTitle, globPattern);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the expression representing the lowercased title used to derive the alpha key, falling back to the original title
|
||||
/// when the title is <see langword="null"/> or empty, and optionally stripped of a leading "the " prefix.
|
||||
/// </summary>
|
||||
/// <param name="book">The parameter representing the book entity.</param>
|
||||
/// <returns>The expression of the effective title.</returns>
|
||||
private Expression BuildEffectiveTitle(ParameterExpression book)
|
||||
{
|
||||
Expression titleProperty = Expression.Property(book, nameof(BookEntity.Title));
|
||||
|
||||
// the raw title: the title, unless it is null or empty, in which case the original title (or an empty string) is used
|
||||
BinaryExpression isTitleMissing = Expression.OrElse(
|
||||
Expression.Equal(titleProperty, Expression.Constant(null, typeof(string))),
|
||||
Expression.Equal(titleProperty, Expression.Constant(string.Empty)));
|
||||
Expression rawTitle = Expression.Condition(isTitleMissing,
|
||||
Expression.Coalesce(Expression.Property(book, nameof(BookEntity.OriginalTitle)), Expression.Constant(string.Empty)),
|
||||
titleProperty);
|
||||
|
||||
MethodCallExpression lowerTitle = Expression.Call(rawTitle, s_toLowerMethod);
|
||||
|
||||
// when ignoring the "The " prefix, strip a leading "the " from the lowercased title
|
||||
Expression effectiveTitle = lowerTitle;
|
||||
if (_ignoreThePrefixForAlphaPicker)
|
||||
{
|
||||
MethodCallExpression startsWithThe = Expression.Call(lowerTitle, s_startsWithMethod, Expression.Constant("the "));
|
||||
MethodCallExpression strippedTitle = Expression.Call(lowerTitle, s_substringMethod, Expression.Constant(4));
|
||||
effectiveTitle = Expression.Condition(startsWithThe, strippedTitle, lowerTitle);
|
||||
}
|
||||
|
||||
return effectiveTitle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a predicate that is satisfied when the effective title starts with a glob pattern.
|
||||
/// </summary>
|
||||
/// <param name="book">The parameter representing the book entity.</param>
|
||||
/// <param name="effectiveTitle">The expression of the effective title.</param>
|
||||
/// <param name="globPattern">The glob pattern the effective title must match.</param>
|
||||
/// <returns>The built predicate.</returns>
|
||||
private static Expression<Func<BookEntity, bool>> BuildGlobPredicate(ParameterExpression book, Expression effectiveTitle, string globPattern)
|
||||
{
|
||||
MethodCallExpression glob = BuildGlobCall(effectiveTitle, globPattern);
|
||||
return Expression.Lambda<Func<BookEntity, bool>>(glob, book);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a predicate that is satisfied when the first character of the effective title is neither a letter nor a digit.
|
||||
/// </summary>
|
||||
/// <param name="book">The parameter representing the book entity.</param>
|
||||
/// <param name="effectiveTitle">The expression of the effective title.</param>
|
||||
/// <returns>The built predicate.</returns>
|
||||
private static Expression<Func<BookEntity, bool>> BuildSymbolPredicate(ParameterExpression book, Expression effectiveTitle)
|
||||
{
|
||||
Expression notLetter = Expression.Not(BuildGlobCall(effectiveTitle, "[a-z]*"));
|
||||
Expression notDigit = Expression.Not(BuildGlobCall(effectiveTitle, "[0-9]*"));
|
||||
return Expression.Lambda<Func<BookEntity, bool>>(Expression.AndAlso(notLetter, notDigit), book);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the call to <see cref="SqliteDbFunctionsExtensions.Glob"/> for the effective title and the provided glob pattern.
|
||||
/// </summary>
|
||||
/// <param name="effectiveTitle">The expression of the effective title.</param>
|
||||
/// <param name="globPattern">The glob pattern the effective title must match.</param>
|
||||
/// <returns>The built method call.</returns>
|
||||
private static MethodCallExpression BuildGlobCall(Expression effectiveTitle, string globPattern)
|
||||
{
|
||||
Expression functions = Expression.Property(null, typeof(EF), nameof(EF.Functions));
|
||||
return Expression.Call(s_globMethod, functions, effectiveTitle, Expression.Constant(globPattern));
|
||||
}
|
||||
}
|
||||
@@ -18,15 +18,15 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapper" Version="2.1.66" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.0">
|
||||
<PackageReference Include="Dapper" Version="2.1.79" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.11">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.0">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.11">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -15,6 +15,7 @@ public static partial class Errors
|
||||
public static Error CannotScanDisabledLibrary => Error.Forbidden(description: nameof(CannotScanDisabledLibrary));
|
||||
public static Error LibraryIdCannotBeEmpty => Error.Validation(description: nameof(LibraryIdCannotBeEmpty));
|
||||
public static Error FilterMustIncludeLibraryId => Error.Validation(description: nameof(FilterMustIncludeLibraryId));
|
||||
public static Error InvalidFilterAlphaKey => Error.Validation(description: nameof(InvalidFilterAlphaKey));
|
||||
public static Error LibraryAlreadyExists => Error.Conflict(description: nameof(LibraryAlreadyExists));
|
||||
public static Error LibraryNotFound => Error.NotFound(description: nameof(LibraryNotFound));
|
||||
public static Error LibraryTypeCannotBeNull => Error.Validation(description: nameof(LibraryTypeCannotBeNull));
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
|
||||
<PackageReference Include="System.IO.Abstractions" Version="21.1.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="4.1.0" />
|
||||
<PackageReference Include="System.IO.Abstractions" Version="22.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -17,18 +17,18 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DebounceThrottle" Version="3.0.1" />
|
||||
<PackageReference Include="Konscious.Security.Cryptography.Argon2" Version="1.3.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="2.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
|
||||
<PackageReference Include="Otp.NET" Version="1.4.0" />
|
||||
<PackageReference Include="QRCoder" Version="1.6.0" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.2.0" />
|
||||
<PackageReference Include="System.IO.Hashing" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.2.12" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.11" />
|
||||
<PackageReference Include="Otp.NET" Version="1.4.1" />
|
||||
<PackageReference Include="QRCoder" Version="1.8.0" />
|
||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.22.0" />
|
||||
<PackageReference Include="System.IO.Hashing" Version="10.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -22,22 +22,22 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FastEndpoints" Version="5.31.0.6-beta" />
|
||||
<PackageReference Include="FastEndpoints.Swagger" Version="5.31.0.6-beta" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.0">
|
||||
<PackageReference Include="FastEndpoints" Version="8.2.0" />
|
||||
<PackageReference Include="FastEndpoints.Swagger" Version="8.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.11">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Scalar.AspNetCore" Version="1.2.36" />
|
||||
<PackageReference Include="Serilog" Version="4.1.1-dev-02318" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
||||
<PackageReference Include="Scalar.AspNetCore" Version="2.16.20" />
|
||||
<PackageReference Include="Serilog" Version="4.4.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
|
||||
<PackageReference Include="Serilog.Enrichers.AspnetcoreHttpcontext" Version="1.1.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="10.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Lumina.Presentation.Web.Common.Enums.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the sort order.
|
||||
/// </summary>
|
||||
public enum SortOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// Ascending order.
|
||||
/// </summary>
|
||||
Ascending,
|
||||
|
||||
/// <summary>
|
||||
/// Descending order.
|
||||
/// </summary>
|
||||
Descending
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Common;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the query parameters used to retrieve the lightweight details of the books of a media library.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
public class BookLibraryItemsQueryModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the media library whose books are retrieved.
|
||||
/// </summary>
|
||||
public Guid LibraryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the page of results to retrieve.
|
||||
/// </summary>
|
||||
public int? CurrentPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum number of books to retrieve per page.
|
||||
/// </summary>
|
||||
public int? PerPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the search term used to filter results.
|
||||
/// </summary>
|
||||
public string? SearchTerm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the alpha key used to filter the results by the first character of their title, for the alpha picker.
|
||||
/// Can be <see langword="null"/> to disable alpha filtering, a single ASCII letter (case-insensitive) to filter by that letter,
|
||||
/// "#" to filter by titles whose first character is a digit, or "*" to filter by titles whose first character is neither a letter nor a digit.
|
||||
/// </summary>
|
||||
public string? FilterAlphaKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the leading "The " prefix of a title is ignored when computing the alpha key, or not.
|
||||
/// </summary>
|
||||
public bool IgnoreThePrefixForAlphaPicker { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the field by which to sort the results.
|
||||
/// </summary>
|
||||
public string? SortBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the direction in which to sort the results.
|
||||
/// </summary>
|
||||
public SortOrder? SortOrder { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a lightweight book element, containing only the properties needed by the client for card-style navigation.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public class BookLiteModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the book.
|
||||
/// </summary>
|
||||
public Guid Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the book.
|
||||
/// </summary>
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the release year of the book (re-release year, if available, or original release year), if known.
|
||||
/// </summary>
|
||||
public int? ReleaseYear { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the image representing the cover of the book, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Models.Libraries;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a paginated collection of lightweight book elements, together with pagination metadata.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("CurrentPage: {CurrentPage}; Count: {Count}")]
|
||||
public class PaginatedBookLiteModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the collection of lightweight book elements associated with this instance.
|
||||
/// </summary>
|
||||
public IReadOnlyList<BookLiteModel> Data { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current page number in a paginated collection.
|
||||
/// </summary>
|
||||
public int CurrentPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of items to include per page in paginated results.
|
||||
/// </summary>
|
||||
public int PerPage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total number of elements available in the paginated result set.
|
||||
/// </summary>
|
||||
public int Count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total number of pages based on elements available in the result set and per page.
|
||||
/// </summary>
|
||||
public int NumberOfPages { get; set; }
|
||||
}
|
||||
+74
-4
@@ -1,22 +1,92 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Models.Libraries;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Controllers.Library.WrittenContentLibrary.BookLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Controller for books related operations.
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("{culture}library/written-content-library/books-library/books")]
|
||||
[Route("{culture}/library/written-content-library/books-library/books")]
|
||||
public class BooksController : Controller
|
||||
{
|
||||
[HttpGet("")]
|
||||
public IActionResult Index()
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BooksController"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public BooksController(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
return View("/Views/Library/WrittenContentLibrary/BookLibrary/Books/Index.cshtml");
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the view for browsing the books of a media library.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose books are browsed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("")]
|
||||
public async Task<IActionResult> Index(Guid? libraryId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (libraryId is null)
|
||||
return RedirectToAction("Index", "Home");
|
||||
|
||||
LibraryModel library = await _apiHttpClient.GetAsync<LibraryModel>($"libraries/{libraryId}", cancellationToken).ConfigureAwait(false);
|
||||
return View("/Views/Library/WrittenContentLibrary/BookLibrary/Books/Index.cshtml", library);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lightweight details of the books of a media library.
|
||||
/// </summary>
|
||||
/// <param name="query">The model containing the parameters used to retrieve the books.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
[HttpGet("api-get-library-items")]
|
||||
public async Task<IActionResult> GetLibraryItems([FromQuery] BookLibraryItemsQueryModel query, CancellationToken cancellationToken = default)
|
||||
{
|
||||
PaginatedBookLiteModel response = await _apiHttpClient.GetAsync<PaginatedBookLiteModel>(BuildItemsEndpoint(query), cancellationToken).ConfigureAwait(false);
|
||||
return Json(new { success = true, data = response });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Displays the view for a single book.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the book to display.</param>
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult EditBook(Guid id)
|
||||
{
|
||||
return View("/Views/Library/WrittenContentLibrary/BookLibrary/Books/Item.cshtml");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the API endpoint used to retrieve the lightweight details of the books of a media library, from the provided <paramref name="query"/>.
|
||||
/// </summary>
|
||||
/// <param name="query">The model containing the parameters used to retrieve the books.</param>
|
||||
/// <returns>The API endpoint to which the retrieval request is sent.</returns>
|
||||
private static string BuildItemsEndpoint(BookLibraryItemsQueryModel query)
|
||||
{
|
||||
StringBuilder endpoint = new($"books/lite?libraryId={query.LibraryId}");
|
||||
if (query.CurrentPage is not null)
|
||||
endpoint.Append($"¤tPage={query.CurrentPage}");
|
||||
if (query.PerPage is not null)
|
||||
endpoint.Append($"&perPage={query.PerPage}");
|
||||
if (!string.IsNullOrWhiteSpace(query.SearchTerm))
|
||||
endpoint.Append($"&searchTerm={Uri.EscapeDataString(query.SearchTerm)}");
|
||||
if (!string.IsNullOrWhiteSpace(query.FilterAlphaKey))
|
||||
endpoint.Append($"&filterAlphaKey={Uri.EscapeDataString(query.FilterAlphaKey)}");
|
||||
endpoint.Append($"&ignoreThePrefixForAlphaPicker={query.IgnoreThePrefixForAlphaPicker}");
|
||||
if (!string.IsNullOrWhiteSpace(query.SortBy))
|
||||
endpoint.Append($"&sortBy={Uri.EscapeDataString(query.SortBy)}");
|
||||
if (query.SortOrder is not null)
|
||||
endpoint.Append($"&sortOrder={query.SortOrder}");
|
||||
return endpoint.ToString();
|
||||
}
|
||||
}
|
||||
@@ -19,17 +19,17 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentValidation" Version="11.10.0" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.10.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Hybrid" Version="9.0.0-preview.9.24556.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
||||
<PackageReference Include="Polly" Version="8.5.0" />
|
||||
<PackageReference Include="Serilog" Version="4.1.1-dev-02318" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="FluentValidation" Version="12.1.1" />
|
||||
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Hybrid" Version="10.9.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
||||
<PackageReference Include="Polly" Version="8.7.0" />
|
||||
<PackageReference Include="Serilog" Version="4.4.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="10.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Suchen</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Sortieren: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Sortieren: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>Einträge</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>von</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Seite</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Zurück</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Weiter</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Alle</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Diese Bibliothek hat keine Einträge</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Keine Einträge entsprechen den aktuellen Filtern</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Search</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Sort: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Sort: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>items</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>of</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Page</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Previous</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Next</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>All</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>This library has no items</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>No items match the current filters</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Buscar</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Ordenar: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Ordenar: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>elementos</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>de</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Página</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Anterior</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Siguiente</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Todos</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Esta biblioteca no tiene elementos</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Ningún elemento coincide con los filtros actuales</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Rechercher</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Trier : A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Trier : Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>éléments</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>sur</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Page</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Précédent</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Suivant</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Tous</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Cette bibliothèque ne contient aucun élément</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Aucun élément ne correspond aux filtres actuels</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Cerca</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Ordina: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Ordina: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>elementi</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>di</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Pagina</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Precedente</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Successivo</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Tutti</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Questa biblioteca non contiene elementi</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Nessun elemento corrisponde ai filtri correnti</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>検索</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>並べ替え: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>並べ替え: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>件</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>/</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>ページ</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>前へ</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>次へ</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>すべて</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>このライブラリには項目がありません</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>現在のフィルターに一致する項目はありません</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Search</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Sort: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Sort: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>items</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>of</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Page</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Previous</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Next</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>All</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>This library has no items</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>No items match the current filters</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Caută</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Sortare: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Sortare: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>elemente</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>din</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Pagina</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Înapoi</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Înainte</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Toate</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>Această bibliotecă nu are elemente</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Niciun element nu corespunde filtrelor curente</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>Поиск</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>Сортировка: А-Я</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>Сортировка: Я-А</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>элементов</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>из</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>Страница</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>Назад</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>Вперёд</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>Все</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>В этой библиотеке нет элементов</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>Ни один элемент не соответствует текущим фильтрам</value>
|
||||
</data>
|
||||
</root>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Search" xml:space="preserve">
|
||||
<value>搜索</value>
|
||||
</data>
|
||||
<data name="SortAscending" xml:space="preserve">
|
||||
<value>排序: A-Z</value>
|
||||
</data>
|
||||
<data name="SortDescending" xml:space="preserve">
|
||||
<value>排序: Z-A</value>
|
||||
</data>
|
||||
<data name="Items" xml:space="preserve">
|
||||
<value>项</value>
|
||||
</data>
|
||||
<data name="Of" xml:space="preserve">
|
||||
<value>/</value>
|
||||
</data>
|
||||
<data name="Page" xml:space="preserve">
|
||||
<value>页</value>
|
||||
</data>
|
||||
<data name="Previous" xml:space="preserve">
|
||||
<value>上一页</value>
|
||||
</data>
|
||||
<data name="Next" xml:space="preserve">
|
||||
<value>下一页</value>
|
||||
</data>
|
||||
<data name="All" xml:space="preserve">
|
||||
<value>全部</value>
|
||||
</data>
|
||||
<data name="NoItems" xml:space="preserve">
|
||||
<value>此库中没有项目</value>
|
||||
</data>
|
||||
<data name="NoItemsMatchFilters" xml:space="preserve">
|
||||
<value>没有项目符合当前筛选条件</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -27,11 +27,15 @@
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
let isInitialized = false;
|
||||
|
||||
const librariesContainer = document.getElementById('libraries-container');
|
||||
const noLibrariesMessage = document.getElementById('no-libraries');
|
||||
|
||||
const documentLoaded = async function () {
|
||||
async function InitializeAsync() {
|
||||
if (isInitialized)
|
||||
return;
|
||||
isInitialized = true;
|
||||
// get the media libraries
|
||||
// TODO: add setting check whether the user desires this feature or not
|
||||
const data = await callApiGetAsync('@_urlService.GetAbsoluteUrl("GetEnabledLibraries", "LibraryManagement")');
|
||||
@@ -40,33 +44,43 @@
|
||||
librariesContainer.classList.replace('justify-center', 'justify-start');
|
||||
// populate media library items
|
||||
data.forEach((library) => {
|
||||
const libraryDiv = document.createElement('div');
|
||||
libraryDiv.className = 'media-panel';
|
||||
// book libraries are browsable, so their panel is rendered as a link to their browse page
|
||||
const isBrowsable = library.libraryType === 'Book';
|
||||
const browseUrl = isBrowsable
|
||||
? '@_urlService.GetAbsoluteUrl("Index", "Books")' + '?libraryId=' + library.id
|
||||
: null;
|
||||
|
||||
const libraryElement = isBrowsable ? document.createElement('a') : document.createElement('div');
|
||||
libraryElement.className = isBrowsable ? 'media-panel nav-link no-underline' : 'media-panel';
|
||||
if (browseUrl)
|
||||
libraryElement.href = browseUrl;
|
||||
|
||||
// the cover image is optional, so it is only rendered when the library has one
|
||||
const coverImageHtml = library.coverImage
|
||||
? `<img src="${globalConfiguration.serverBasePath}/media/libraries/${library.id}/${library.coverImage.substring(library.coverImage.lastIndexOf('cover.'))}" />`
|
||||
: '';
|
||||
|
||||
libraryDiv.innerHTML = `
|
||||
libraryElement.innerHTML = `
|
||||
${coverImageHtml}
|
||||
<span class="text-light-two"><strong>${library.title}</strong></span>
|
||||
`;
|
||||
|
||||
librariesContainer.appendChild(libraryDiv);
|
||||
librariesContainer.appendChild(libraryElement);
|
||||
});
|
||||
// bind the AJAX navigation behavior to the library links, which were created after the initial navigation binding
|
||||
bindNavigationLinks();
|
||||
} else {
|
||||
noLibrariesMessage.classList.replace('hidden', 'block');
|
||||
librariesContainer.classList.replace('justify-start', 'justify-center');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// add listeners
|
||||
document.addEventListener('DOMContentLoaded', documentLoaded);
|
||||
document.addEventListener('DOMContentLoaded', InitializeAsync);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
document.removeEventListener('click', documentLoaded);
|
||||
document.removeEventListener('DOMContentLoaded', InitializeAsync);
|
||||
});
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
|
||||
+316
-1
@@ -1,2 +1,317 @@
|
||||
@*
|
||||
/library/written-content-library/books-library/books?libraryId=...
|
||||
*@
|
||||
|
||||
<p>All books</p><a href="books/E6B599D6-3819-4FAB-B988-8F027072CF7B" class="nav-link">one</a>
|
||||
@using Lumina.Presentation.Web.Common.Models.Libraries
|
||||
@using Lumina.Presentation.Web.Common.Services
|
||||
@using Microsoft.AspNetCore.Mvc.Localization
|
||||
|
||||
@{
|
||||
// generate a unique id for the scripts section of this view, so it can be dynamically loaded/unloaded by the global AJAX navigator handler
|
||||
var scriptId = ScriptIdentifierHelper.GenerateScriptId();
|
||||
}
|
||||
|
||||
@inject IViewLocalizer _localizer
|
||||
@inject IUrlService _urlService
|
||||
|
||||
@model LibraryModel
|
||||
|
||||
<div class="cotton-candy">
|
||||
<div style="display: grid; grid-template-rows: auto 1fr;">
|
||||
<!--container with two rows, one fixed, one filling remaining space-->
|
||||
<div style="min-height: 1rem;"></div><!--the first row is a dummy row for "margin", because setting a margin on the next row would offset the parent's position-->
|
||||
<div class="pl-10 pr-10 pb-10">
|
||||
<div class="text-center">
|
||||
<h1 class="text-light-two engraved-title">@(Model.Title ?? string.Empty)</h1>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<input id="search-input" type="text" class="enlightenment-input w-200px" placeholder="@_localizer["Search"]" />
|
||||
<button id="search-button" type="button" class="confirm-button">@_localizer["Search"]</button>
|
||||
<button id="sort-toggle" type="button" class="confirm-button">@_localizer["SortAscending"]</button>
|
||||
<span id="count-label" class="text-light-two"></span>
|
||||
</div>
|
||||
<div style="display: flex; align-items: flex-start;">
|
||||
<div id="books-container" class="cards-container justify-start h-100" style="flex: 1; min-width: 0;">
|
||||
<p id="no-items" class="hidden text-light-two">@_localizer["NoItems"]</p>
|
||||
<p id="no-items-matching" class="hidden text-light-two">@_localizer["NoItemsMatchFilters"]</p>
|
||||
</div>
|
||||
<div id="alpha-picker" class="alpha-picker"></div>
|
||||
</div>
|
||||
<div id="pagination" class="form-row mx-auto w-25 hidden" style="justify-content: center;">
|
||||
<button id="prev-page" type="button" class="abort-button">@_localizer["Previous"]</button>
|
||||
<span id="page-indicator" class="text-light-two"></span>
|
||||
<button id="next-page" type="button" class="confirm-button">@_localizer["Next"]</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@section Scripts {
|
||||
<script type="text/javascript" data-form="@scriptId" defer>
|
||||
// create cleanup registry for this view
|
||||
const cleanupFunctions = [];
|
||||
let isInitialized = false;
|
||||
let requestSequence = 0;
|
||||
|
||||
const libraryId = '@(Model.Id ?? Guid.Empty)';
|
||||
const booksContainer = document.getElementById('books-container');
|
||||
const noItemsMessage = document.getElementById('no-items');
|
||||
const noItemsMatchingMessage = document.getElementById('no-items-matching');
|
||||
const searchInput = document.getElementById('search-input');
|
||||
const searchButton = document.getElementById('search-button');
|
||||
const sortToggle = document.getElementById('sort-toggle');
|
||||
const countLabel = document.getElementById('count-label');
|
||||
const alphaPicker = document.getElementById('alpha-picker');
|
||||
const pagination = document.getElementById('pagination');
|
||||
const prevPageButton = document.getElementById('prev-page');
|
||||
const nextPageButton = document.getElementById('next-page');
|
||||
const pageIndicator = document.getElementById('page-indicator');
|
||||
|
||||
// the special alpha keys for numbers and symbols, followed by the letters
|
||||
const alphaKeys = ['#', '*', ...Array.from({ length: 26 }, (_, index) => String.fromCharCode(65 + index))];
|
||||
|
||||
const state = {
|
||||
currentPage: 1,
|
||||
perPage: null,
|
||||
searchTerm: '',
|
||||
alphaKey: null,
|
||||
ignoreThePrefix: false,
|
||||
sortOrder: 'Ascending'
|
||||
};
|
||||
|
||||
const jsLocalizedStrings = {
|
||||
all: '@_localizer["All"]',
|
||||
items: '@_localizer["Items"]',
|
||||
of: '@_localizer["Of"]',
|
||||
page: '@_localizer["Page"]',
|
||||
sortAscending: '@_localizer["SortAscending"]',
|
||||
sortDescending: '@_localizer["SortDescending"]'
|
||||
};
|
||||
|
||||
// builds the URL of the retrieval endpoint, from the current state
|
||||
function buildItemsUrl() {
|
||||
const url = '@_urlService.GetAbsoluteUrl("GetLibraryItems", "Books")';
|
||||
const params = new URLSearchParams();
|
||||
params.set('libraryId', libraryId);
|
||||
if (state.perPage !== null) {
|
||||
params.set('currentPage', state.currentPage);
|
||||
params.set('perPage', state.perPage);
|
||||
}
|
||||
if (state.searchTerm !== '')
|
||||
params.set('searchTerm', state.searchTerm);
|
||||
if (state.alphaKey !== null)
|
||||
params.set('filterAlphaKey', state.alphaKey);
|
||||
params.set('ignoreThePrefixForAlphaPicker', state.ignoreThePrefix);
|
||||
params.set('sortOrder', state.sortOrder);
|
||||
return `${url}?${params.toString()}`;
|
||||
}
|
||||
|
||||
// retrieves the books and renders them, ignoring stale responses of earlier requests
|
||||
async function loadItemsAsync() {
|
||||
const requestId = ++requestSequence;
|
||||
const response = await callApiGetAsync(buildItemsUrl());
|
||||
if (requestId !== requestSequence)
|
||||
return;
|
||||
if (response)
|
||||
renderItems(response);
|
||||
}
|
||||
|
||||
// renders the retrieved books, the count label and the pagination controls
|
||||
function renderItems(response) {
|
||||
booksContainer.querySelectorAll('.media-panel').forEach(card => card.remove());
|
||||
|
||||
const hasActiveFilters = state.searchTerm !== '' || state.alphaKey !== null;
|
||||
if (response.count === 0) {
|
||||
booksContainer.classList.add('justify-center');
|
||||
noItemsMessage.classList.toggle('hidden', hasActiveFilters);
|
||||
noItemsMatchingMessage.classList.toggle('hidden', !hasActiveFilters);
|
||||
} else {
|
||||
booksContainer.classList.remove('justify-center');
|
||||
noItemsMessage.classList.add('hidden');
|
||||
noItemsMatchingMessage.classList.add('hidden');
|
||||
response.data.forEach(book => booksContainer.appendChild(createBookCard(book)));
|
||||
}
|
||||
|
||||
updateCountLabel(response);
|
||||
updatePagination(response);
|
||||
}
|
||||
|
||||
// creates a portrait card for a book, with its cover image (or a placeholder) and its title
|
||||
function createBookCard(book) {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'media-panel';
|
||||
card.style.width = '160px';
|
||||
card.style.height = '240px';
|
||||
|
||||
const image = document.createElement('img');
|
||||
image.src = book.coverPath
|
||||
? `${globalConfiguration.serverBasePath}${book.coverPath}`
|
||||
: `/images/ui/book-placeholder.svg`;
|
||||
image.alt = book.title;
|
||||
|
||||
const titleSpan = document.createElement('span');
|
||||
titleSpan.className = 'text-light-two';
|
||||
const title = document.createElement('strong');
|
||||
title.textContent = book.title;
|
||||
titleSpan.appendChild(title);
|
||||
|
||||
card.appendChild(image);
|
||||
card.appendChild(titleSpan);
|
||||
return card;
|
||||
}
|
||||
|
||||
// updates the count label: total items when pagination is off, displayed range out of total when it is on
|
||||
function updateCountLabel(response) {
|
||||
if (state.perPage === null)
|
||||
countLabel.textContent = `${response.count} ${jsLocalizedStrings.items}`;
|
||||
else if (response.count === 0)
|
||||
countLabel.textContent = `0 ${jsLocalizedStrings.items}`;
|
||||
else {
|
||||
const start = (response.currentPage - 1) * response.perPage + 1;
|
||||
const end = Math.min(response.currentPage * response.perPage, response.count);
|
||||
countLabel.textContent = `${start}-${end} ${jsLocalizedStrings.of} ${response.count}`;
|
||||
}
|
||||
}
|
||||
|
||||
// updates the pagination controls, which are only visible when pagination is enabled
|
||||
function updatePagination(response) {
|
||||
if (state.perPage === null) {
|
||||
pagination.classList.add('hidden');
|
||||
return;
|
||||
}
|
||||
const totalPages = Math.max(1, response.numberOfPages);
|
||||
pagination.classList.remove('hidden');
|
||||
pageIndicator.textContent = `${jsLocalizedStrings.page} ${response.currentPage} ${jsLocalizedStrings.of} ${totalPages}`;
|
||||
prevPageButton.disabled = response.currentPage <= 1;
|
||||
nextPageButton.disabled = response.currentPage >= totalPages;
|
||||
}
|
||||
|
||||
// builds the alpha picker column, with the "All" key followed by the numbers, symbols and letters keys
|
||||
function buildAlphaPicker() {
|
||||
const allKey = document.createElement('span');
|
||||
allKey.className = 'alpha-key';
|
||||
allKey.dataset.alphaKey = '';
|
||||
allKey.textContent = jsLocalizedStrings.all;
|
||||
allKey.addEventListener('click', () => handleAlphaKeyClick(null));
|
||||
alphaPicker.appendChild(allKey);
|
||||
|
||||
alphaKeys.forEach(key => {
|
||||
const alphaKey = document.createElement('span');
|
||||
alphaKey.className = 'alpha-key';
|
||||
alphaKey.dataset.alphaKey = key;
|
||||
alphaKey.textContent = key;
|
||||
alphaKey.addEventListener('click', () => handleAlphaKeyClick(key));
|
||||
alphaPicker.appendChild(alphaKey);
|
||||
});
|
||||
|
||||
updateAlphaPickerActiveState();
|
||||
}
|
||||
|
||||
// highlights the currently active key of the alpha picker
|
||||
function updateAlphaPickerActiveState() {
|
||||
alphaPicker.querySelectorAll('.alpha-key').forEach(key => {
|
||||
const keyValue = key.dataset.alphaKey === '' ? null : key.dataset.alphaKey;
|
||||
key.classList.toggle('alpha-key-active', keyValue === state.alphaKey);
|
||||
});
|
||||
}
|
||||
|
||||
// applies the given alpha key (null clears the alpha filter) and reloads the books
|
||||
function handleAlphaKeyClick(key) {
|
||||
state.alphaKey = key;
|
||||
state.currentPage = 1;
|
||||
updateAlphaPickerActiveState();
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
// applies the search term and reloads the books
|
||||
function handleSearch() {
|
||||
state.searchTerm = searchInput.value.trim();
|
||||
state.currentPage = 1;
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
// triggers the search when the Enter key is pressed in the search input
|
||||
function handleSearchKeydown(event) {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
handleSearch();
|
||||
}
|
||||
}
|
||||
|
||||
// toggles the sort direction and reloads the books
|
||||
function handleSortToggle() {
|
||||
state.sortOrder = state.sortOrder === 'Ascending' ? 'Descending' : 'Ascending';
|
||||
sortToggle.textContent = state.sortOrder === 'Ascending' ? jsLocalizedStrings.sortAscending : jsLocalizedStrings.sortDescending;
|
||||
state.currentPage = 1;
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
// applies an alpha filter when a letter is pressed while the search input does not have focus; Escape clears the alpha filter
|
||||
function handleAlphaKeydown(event) {
|
||||
if (document.activeElement === searchInput)
|
||||
return;
|
||||
if (event.key.length === 1 && /[a-zA-Z]/.test(event.key))
|
||||
handleAlphaKeyClick(event.key.toUpperCase());
|
||||
else if (event.key === 'Escape')
|
||||
handleAlphaKeyClick(null);
|
||||
}
|
||||
|
||||
// loads the settings of the current user, which drive pagination and the alpha picker prefix handling
|
||||
async function loadSettingsAsync() {
|
||||
const data = await callApiGetAsync('@_urlService.GetAbsoluteUrl("GetUserSettings", "Settings")');
|
||||
if (data) {
|
||||
state.ignoreThePrefix = data.ignoreThePrefixForAlphaPicker === true;
|
||||
state.perPage = data.isPaginationEnabled === true ? data.itemsPerPage : null;
|
||||
}
|
||||
}
|
||||
|
||||
// navigates to the previous page
|
||||
function handlePrevPageClick() {
|
||||
state.currentPage = Math.max(1, state.currentPage - 1);
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
// navigates to the next page
|
||||
function handleNextPageClick() {
|
||||
state.currentPage = state.currentPage + 1;
|
||||
loadItemsAsync();
|
||||
}
|
||||
|
||||
// add listeners
|
||||
searchButton.addEventListener('click', handleSearch);
|
||||
searchInput.addEventListener('keydown', handleSearchKeydown);
|
||||
sortToggle.addEventListener('click', handleSortToggle);
|
||||
prevPageButton.addEventListener('click', handlePrevPageClick);
|
||||
nextPageButton.addEventListener('click', handleNextPageClick);
|
||||
document.addEventListener('keydown', handleAlphaKeydown);
|
||||
document.addEventListener('DOMContentLoaded', InitializeAsync);
|
||||
|
||||
// register cleanup for these listeners
|
||||
cleanupFunctions.push(() => {
|
||||
searchButton.removeEventListener('click', handleSearch);
|
||||
searchInput.removeEventListener('keydown', handleSearchKeydown);
|
||||
sortToggle.removeEventListener('click', handleSortToggle);
|
||||
prevPageButton.removeEventListener('click', handlePrevPageClick);
|
||||
nextPageButton.removeEventListener('click', handleNextPageClick);
|
||||
document.removeEventListener('keydown', handleAlphaKeydown);
|
||||
document.removeEventListener('DOMContentLoaded', InitializeAsync);
|
||||
});
|
||||
|
||||
async function InitializeAsync() {
|
||||
if (isInitialized)
|
||||
return;
|
||||
isInitialized = true;
|
||||
sortToggle.textContent = jsLocalizedStrings.sortAscending;
|
||||
buildAlphaPicker();
|
||||
await loadSettingsAsync();
|
||||
await loadItemsAsync();
|
||||
}
|
||||
|
||||
// store all cleanups for this view on window object using the scriptId
|
||||
window.viewCleanups = window.viewCleanups || {};
|
||||
window.viewCleanups['@scriptId'] = () => {
|
||||
cleanupFunctions.forEach(cleanup => cleanup());
|
||||
console.log(`Unloaded @scriptId`);
|
||||
};
|
||||
console.log(`Loaded @scriptId`);
|
||||
</script>
|
||||
}
|
||||
@@ -1488,6 +1488,25 @@ th, td {
|
||||
margin-left: auto !important;
|
||||
}
|
||||
|
||||
.alpha-picker {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.1rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.alpha-key {
|
||||
padding: 0 0.6rem;
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.alpha-key:hover,
|
||||
.alpha-key.alpha-key-active {
|
||||
background-color: #00000066;
|
||||
}
|
||||
|
||||
/* For phones */
|
||||
@media only screen and (max-width: 768px) {
|
||||
main {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 300">
|
||||
<rect width="200" height="300" fill="#1c1c1c" />
|
||||
<g fill="none" stroke="#6DCBFE" stroke-width="6" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M60 90c0-14 10-24 24-24h56c14 0 24 10 24 24v120c0 14-10 24-24 24H84c-14 0-24-10-24-24z" />
|
||||
<path d="M60 94c0-14 10-24 24-24h24v140H84c-14 0-24-10-24-24z" />
|
||||
<path d="M84 150h32" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 447 B |
+7
-1
@@ -26,6 +26,8 @@ public class GetBooksLiteQueryFixture
|
||||
/// <param name="libraryId">Optional. The Id of the media library whose books are retrieved.</param>
|
||||
/// <param name="paginationData">Optional. The pagination data of the query.</param>
|
||||
/// <param name="searchTerm">Optional. The search term used to filter results.</param>
|
||||
/// <param name="filterAlphaKey">Optional. The alpha key used to filter the results by the first character of their title, for the alpha picker.</param>
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Optional. Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
|
||||
/// <param name="sortBy">Optional. The name of the field by which to sort the results.</param>
|
||||
/// <param name="sortOrder">Optional. The direction in which to sort the results.</param>
|
||||
/// <returns>The created query to get the lightweight details of books.</returns>
|
||||
@@ -33,6 +35,8 @@ public class GetBooksLiteQueryFixture
|
||||
Guid? libraryId = null,
|
||||
PaginationDataDto? paginationData = null,
|
||||
string? searchTerm = null,
|
||||
string? filterAlphaKey = null,
|
||||
bool ignoreThePrefixForAlphaPicker = false,
|
||||
string? sortBy = null,
|
||||
SortOrder? sortOrder = null)
|
||||
{
|
||||
@@ -45,7 +49,9 @@ public class GetBooksLiteQueryFixture
|
||||
new LibraryFilterDto
|
||||
{
|
||||
LibraryId = libraryId ?? _faker.Random.Guid(),
|
||||
SearchTerm = searchTerm
|
||||
SearchTerm = searchTerm,
|
||||
FilterAlphaKey = filterAlphaKey,
|
||||
IgnoreThePrefixForAlphaPicker = ignoreThePrefixForAlphaPicker
|
||||
},
|
||||
sortBy,
|
||||
sortOrder ?? _faker.PickRandom<SortOrder>()
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<PackageReference Include="AutoFixture" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+6
@@ -25,6 +25,8 @@ public class GetBooksLiteRequestFixture
|
||||
/// <param name="currentPage">Optional. The page of results to retrieve.</param>
|
||||
/// <param name="perPage">Optional. The maximum number of books to retrieve per page.</param>
|
||||
/// <param name="searchTerm">Optional. The search term used to filter results.</param>
|
||||
/// <param name="filterAlphaKey">Optional. The alpha key used to filter the results by the first character of their title, for the alpha picker.</param>
|
||||
/// <param name="ignoreThePrefixForAlphaPicker">Optional. Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
|
||||
/// <param name="sortBy">Optional. The name of the field by which to sort the results.</param>
|
||||
/// <param name="sortOrder">Optional. The direction in which to sort the results.</param>
|
||||
/// <returns>The created <see cref="GetBooksLiteRequest"/>.</returns>
|
||||
@@ -33,6 +35,8 @@ public class GetBooksLiteRequestFixture
|
||||
int? currentPage = null,
|
||||
int? perPage = null,
|
||||
string? searchTerm = null,
|
||||
string? filterAlphaKey = null,
|
||||
bool ignoreThePrefixForAlphaPicker = false,
|
||||
string? sortBy = null,
|
||||
SortOrder? sortOrder = null)
|
||||
{
|
||||
@@ -41,6 +45,8 @@ public class GetBooksLiteRequestFixture
|
||||
CurrentPage: currentPage ?? _faker.Random.Number(1, 100),
|
||||
PerPage: perPage ?? _faker.Random.Number(1, 200),
|
||||
SearchTerm: searchTerm ?? _faker.Lorem.Word(),
|
||||
FilterAlphaKey: filterAlphaKey,
|
||||
IgnoreThePrefixForAlphaPicker: ignoreThePrefixForAlphaPicker,
|
||||
SortBy: sortBy ?? _faker.Lorem.Word(),
|
||||
SortOrder: sortOrder ?? _faker.PickRandom<SortOrder>()
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
@@ -15,7 +15,7 @@
|
||||
<PackageReference Include="AutoFixture" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+2
-2
@@ -12,8 +12,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="4.1.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<PackageReference Include="AutoFixture" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
<PackageReference Include="AutoFixture" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+118
-1
@@ -82,6 +82,121 @@ public class GetBooksLiteEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
|
||||
Assert.Contains(paginatedBooks.Data, book => book.Title == "Book B");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetBooksLite_WhenCalledWithFilterAlphaKeyLetter_ShouldReturnOnlyBooksStartingWithThatLetter()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
await SeedLibraryAsync(libraryId, userId);
|
||||
await SeedBookAsync(libraryId, "Quiet Place");
|
||||
await SeedBookAsync(libraryId, "The Quiet");
|
||||
await SeedBookAsync(libraryId, "Racing");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/books/lite?libraryId={libraryId}&filterAlphaKey=q");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<BookLiteResponse>? paginatedBooks = await response.Content.ReadFromJsonAsync<PaginatedResponse<BookLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedBooks);
|
||||
BookLiteResponse book = Assert.Single(paginatedBooks!.Data);
|
||||
Assert.Equal("Quiet Place", book.Title);
|
||||
Assert.Equal(1, paginatedBooks.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetBooksLite_WhenCalledWithFilterAlphaKeyLetterAndIgnoreThePrefix_ShouldIncludeThePrefixedTitles()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
await SeedLibraryAsync(libraryId, userId);
|
||||
await SeedBookAsync(libraryId, "Quiet Place");
|
||||
await SeedBookAsync(libraryId, "The Quiet");
|
||||
await SeedBookAsync(libraryId, "Racing");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/books/lite?libraryId={libraryId}&filterAlphaKey=q&ignoreThePrefixForAlphaPicker=true");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<BookLiteResponse>? paginatedBooks = await response.Content.ReadFromJsonAsync<PaginatedResponse<BookLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedBooks);
|
||||
Assert.Equal(2, paginatedBooks!.Count);
|
||||
Assert.Contains(paginatedBooks.Data, book => book.Title == "Quiet Place");
|
||||
Assert.Contains(paginatedBooks.Data, book => book.Title == "The Quiet");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetBooksLite_WhenCalledWithFilterAlphaKeyNumber_ShouldReturnOnlyBooksStartingWithADigit()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
await SeedLibraryAsync(libraryId, userId);
|
||||
await SeedBookAsync(libraryId, "1984");
|
||||
await SeedBookAsync(libraryId, "7 Habits of Highly Effective People");
|
||||
await SeedBookAsync(libraryId, "Brave New World");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/books/lite?libraryId={libraryId}&filterAlphaKey=%23");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<BookLiteResponse>? paginatedBooks = await response.Content.ReadFromJsonAsync<PaginatedResponse<BookLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedBooks);
|
||||
Assert.Equal(2, paginatedBooks!.Count);
|
||||
Assert.Contains(paginatedBooks.Data, book => book.Title == "1984");
|
||||
Assert.Contains(paginatedBooks.Data, book => book.Title == "7 Habits of Highly Effective People");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetBooksLite_WhenCalledWithFilterAlphaKeySymbol_ShouldReturnOnlyBooksStartingWithASymbol()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
await SeedLibraryAsync(libraryId, userId);
|
||||
await SeedBookAsync(libraryId, "!Important");
|
||||
await SeedBookAsync(libraryId, "1984");
|
||||
await SeedBookAsync(libraryId, "Alpha");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/books/lite?libraryId={libraryId}&filterAlphaKey=%2A");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<BookLiteResponse>? paginatedBooks = await response.Content.ReadFromJsonAsync<PaginatedResponse<BookLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedBooks);
|
||||
BookLiteResponse book = Assert.Single(paginatedBooks!.Data);
|
||||
Assert.Equal("!Important", book.Title);
|
||||
Assert.Equal(1, paginatedBooks.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetBooksLite_WhenTitleIsEmptyAndFilterAlphaKeyIsProvided_ShouldUseOriginalTitle()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = GetCurrentUserId();
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
await SeedLibraryAsync(libraryId, userId);
|
||||
await SeedBookAsync(libraryId, "", "Rendezvous");
|
||||
await SeedBookAsync(libraryId, "Racing");
|
||||
await SeedBookAsync(libraryId, "Quiet Place");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/books/lite?libraryId={libraryId}&filterAlphaKey=r");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<BookLiteResponse>? paginatedBooks = await response.Content.ReadFromJsonAsync<PaginatedResponse<BookLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedBooks);
|
||||
Assert.Equal(2, paginatedBooks!.Count);
|
||||
Assert.Contains(paginatedBooks.Data, book => book.Title == ""); // the empty title book matches the filter through its original title
|
||||
Assert.Contains(paginatedBooks.Data, book => book.Title == "Racing");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetBooksLite_WhenCalledWithSearchTerm_ShouldReturnOnlyMatchingBooks()
|
||||
{
|
||||
@@ -204,8 +319,9 @@ public class GetBooksLiteEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library the book belongs to.</param>
|
||||
/// <param name="title">The title of the book.</param>
|
||||
/// <param name="originalTitle">Optional. The original title of the book.</param>
|
||||
/// <returns>A task representing the asynchronous operation.</returns>
|
||||
private async Task SeedBookAsync(Guid libraryId, string title)
|
||||
private async Task SeedBookAsync(Guid libraryId, string title, string? originalTitle = null)
|
||||
{
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
@@ -215,6 +331,7 @@ public class GetBooksLiteEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
|
||||
LibraryId = libraryId,
|
||||
Path = $"/books/{Guid.NewGuid()}.epub",
|
||||
Title = title,
|
||||
OriginalTitle = originalTitle,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
UpdatedBy = null
|
||||
|
||||
+8
-8
@@ -19,17 +19,17 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||
<PackageReference Include="coverlet.collector" Version="10.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.49">
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
|
||||
<PackageReference Include="NSubstitute" Version="6.2.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
+8
-8
@@ -19,17 +19,17 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||
<PackageReference Include="coverlet.collector" Version="10.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.49">
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
|
||||
<PackageReference Include="NSubstitute" Version="6.2.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
+42
@@ -46,4 +46,46 @@ public class GetBooksLiteQueryValidatorTests
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenFilterAlphaKeyIsNotASingleLetterOrSpecialKey_ShouldHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteQuery query = _getBooksLiteQueryFixture.Create();
|
||||
query = query with { Filter = query.Filter with { FilterAlphaKey = "AB" } };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.Library.InvalidFilterAlphaKey);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenFilterAlphaKeyIsASingleLetter_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteQuery query = _getBooksLiteQueryFixture.Create();
|
||||
query = query with { Filter = query.Filter with { FilterAlphaKey = "Q" } };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenFilterAlphaKeyIsNumberOrSymbol_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetBooksLiteQuery query = _getBooksLiteQueryFixture.Create();
|
||||
query = query with { Filter = query.Filter with { FilterAlphaKey = "#" } };
|
||||
|
||||
// Act
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
}
|
||||
@@ -19,16 +19,16 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||
<PackageReference Include="coverlet.collector" Version="10.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.49">
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
|
||||
<PackageReference Include="NSubstitute" Version="6.2.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -19,18 +19,18 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||
<PackageReference Include="coverlet.collector" Version="10.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
<PackageReference Include="EntityFrameworkCore.Testing.NSubstitute" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.49">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
|
||||
<PackageReference Include="EntityFrameworkCore.Testing.NSubstitute" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
|
||||
<PackageReference Include="NSubstitute" Version="6.2.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -18,18 +18,18 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="21.1.3" />
|
||||
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="22.2.0" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||
<PackageReference Include="coverlet.collector" Version="10.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.49">
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
|
||||
<PackageReference Include="NSubstitute" Version="6.2.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
+7
-7
@@ -19,16 +19,16 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||
<PackageReference Include="coverlet.collector" Version="10.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.49">
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
|
||||
<PackageReference Include="NSubstitute" Version="6.2.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
+4
-4
@@ -52,7 +52,7 @@ public class GetPermissionsEndpointTests
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
Ok<IEnumerable<PermissionResponse>> okResult = Assert.IsType<Ok<IEnumerable<PermissionResponse>>>(result);
|
||||
@@ -69,7 +69,7 @@ public class GetPermissionsEndpointTests
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
@@ -94,7 +94,7 @@ public class GetPermissionsEndpointTests
|
||||
.Returns(Result.From(response));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockHandler.Received(1).HandleAsync(
|
||||
@@ -120,7 +120,7 @@ public class GetPermissionsEndpointTests
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(EmptyRequest.Instance, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+4
-4
@@ -48,7 +48,7 @@ public class GetRolesEndpointTests
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
Ok<IEnumerable<RoleResponse>> okResult = Assert.IsType<Ok<IEnumerable<RoleResponse>>>(result);
|
||||
@@ -65,7 +65,7 @@ public class GetRolesEndpointTests
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
@@ -92,7 +92,7 @@ public class GetRolesEndpointTests
|
||||
} as IEnumerable<RoleResponse>));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockHandler.Received(1).HandleAsync(
|
||||
@@ -118,7 +118,7 @@ public class GetRolesEndpointTests
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(EmptyRequest.Instance, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+4
-4
@@ -48,7 +48,7 @@ public class GetDrivesEndpointTests
|
||||
.Returns(Result.From(expectedResponses.AsEnumerable()));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
Ok<IEnumerable<FileSystemTreeNodeResponse>> okResult = Assert.IsType<Ok<IEnumerable<FileSystemTreeNodeResponse>>>(result);
|
||||
@@ -65,7 +65,7 @@ public class GetDrivesEndpointTests
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemDetails = Assert.IsType<ProblemHttpResult>(result);
|
||||
@@ -89,7 +89,7 @@ public class GetDrivesEndpointTests
|
||||
.Returns(Result.From(Enumerable.Empty<FileSystemTreeNodeResponse>()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockHandler.Received(1).HandleAsync(Arg.Any<GetDrivesQuery>(), Arg.Is(cancellationToken));
|
||||
@@ -113,7 +113,7 @@ public class GetDrivesEndpointTests
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(EmptyRequest.Instance, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+4
-4
@@ -44,7 +44,7 @@ public class GetTypeEndpointTests
|
||||
.Returns(expectedResponse);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
Ok<FileSystemTypeResponse> okResult = Assert.IsType<Ok<FileSystemTypeResponse>>(result);
|
||||
@@ -63,7 +63,7 @@ public class GetTypeEndpointTests
|
||||
.Returns(expectedResponse);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
Ok<FileSystemTypeResponse> okResult = Assert.IsType<Ok<FileSystemTypeResponse>>(result);
|
||||
@@ -79,7 +79,7 @@ public class GetTypeEndpointTests
|
||||
.Returns(new FileSystemTypeResponse(PlatformType.Windows));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockHandler.Received(1).HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Is(cancellationToken));
|
||||
@@ -103,7 +103,7 @@ public class GetTypeEndpointTests
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(EmptyRequest.Instance, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+3
-3
@@ -43,7 +43,7 @@ public class CheckInitializationEndpointTests
|
||||
.Returns(expectedResponse);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
Ok<InitializationResponse> okResult = Assert.IsType<Ok<InitializationResponse>>(result);
|
||||
@@ -59,7 +59,7 @@ public class CheckInitializationEndpointTests
|
||||
.Returns(new InitializationResponse(IsInitialized: true));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockHandler.Received(1).HandleAsync(
|
||||
@@ -85,7 +85,7 @@ public class CheckInitializationEndpointTests
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(EmptyRequest.Instance, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+4
-4
@@ -47,7 +47,7 @@ public class GetUsersEndpointTests
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
Ok<IEnumerable<UserResponse>> okResult = Assert.IsType<Ok<IEnumerable<UserResponse>>>(result);
|
||||
@@ -64,7 +64,7 @@ public class GetUsersEndpointTests
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
@@ -88,7 +88,7 @@ public class GetUsersEndpointTests
|
||||
.Returns(Result.From(Array.Empty<UserResponse>() as IEnumerable<UserResponse>));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockHandler.Received(1).HandleAsync(
|
||||
@@ -114,7 +114,7 @@ public class GetUsersEndpointTests
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(EmptyRequest.Instance, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+4
-4
@@ -44,7 +44,7 @@ public class GetUserSettingsEndpointTests
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
Ok<UserSettingsResponse> okResult = Assert.IsType<Ok<UserSettingsResponse>>(result);
|
||||
@@ -61,7 +61,7 @@ public class GetUserSettingsEndpointTests
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
IResult result = await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
ProblemHttpResult problemResult = Assert.IsType<ProblemHttpResult>(result);
|
||||
@@ -82,7 +82,7 @@ public class GetUserSettingsEndpointTests
|
||||
.Returns(Result.From(new UserSettingsResponse(Guid.NewGuid(), true, 48, false)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockHandler.Received(1).HandleAsync(
|
||||
@@ -108,7 +108,7 @@ public class GetUserSettingsEndpointTests
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(EmptyRequest.Instance, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+8
-8
@@ -19,17 +19,17 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
|
||||
<PackageReference Include="Bogus" Version="35.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||
<PackageReference Include="coverlet.collector" Version="10.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="NSubstitute" Version="5.3.0" />
|
||||
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.49">
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
|
||||
<PackageReference Include="NSubstitute" Version="6.2.0" />
|
||||
<PackageReference Include="System.Linq.Async" Version="7.0.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
Reference in new issue
Block a user