Adds alpha picker filtering to the books lite query

This commit is contained in:
BinaryAlley committed 2026-08-16 10:34:08 -07:00
1 parent e72625de7c
commit 6fa154a2e7
12 files changed
+376 -10

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 = "*";
}
@@ -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);
@@ -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);
}
}