Adds book deletion and restore to the web client.

Soft deletes books so the scan keeps their paths reserved, lists the deleted books on a themed page, and lets the user restore them. Updates the API, bundled themes, localization, documentation and tests.

Closes #213
This commit is contained in:
BinaryAlley committed 2026-11-13 18:00:00 +02:00
1 parent ef5ede6325
commit f26b07d4ff
125 files changed
+9856 -378

No files matched your search

@@ -212,6 +212,17 @@ public class BookEntity : IStorageEntity, IAuditableEntity
/// </summary>
public List<BookRatingEntity> Ratings { get; set; } = [];
/// <summary>
/// Gets or sets a value indicating whether the book was deleted by the user and is waiting to be restored or permanently removed.
/// A deleted book is kept out of every catalogue read and is not materialized again by scans, so that an automatic scan never undoes the deletion.
/// </summary>
public bool IsDeleted { get; set; }
/// <summary>
/// Gets or sets the date and time when the book was deleted, or <see langword="null"/> when the book is not deleted.
/// </summary>
public DateTime? DeletedOnUtc { get; set; }
/// <summary>
/// Gets or sets the status of the metadata enrichment of the book.
/// </summary>
@@ -26,15 +26,53 @@ public interface IBookRepository : IRepository<BookEntity>,
/// <summary>
/// Gets the book of the media library identified by <paramref name="libraryId"/> that is stored at the provided <paramref name="path"/>.
/// </summary>
/// <remarks>
/// Soft deleted books are included on purpose, so that the scan deletion strategy can permanently remove a deleted book when its file disappears from disk.
/// </remarks>
/// <param name="libraryId">The Id of the media library whose book is retrieved.</param>
/// <param name="path">The file system path of the book to be retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="BookEntity"/> stored at the provided path, or an error.</returns>
Task<Result<BookEntity?>> GetByPathAsync(Guid libraryId, string path, CancellationToken cancellationToken);
/// <summary>
/// Gets the soft deleted book identified by <paramref name="id"/>.
/// </summary>
/// <param name="id">The Id of the soft deleted book to get.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted <see cref="BookEntity"/>, <see langword="null"/> when the book does not exist or is not soft deleted, or an error.</returns>
Task<Result<BookEntity?>> GetSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken);
/// <summary>
/// Gets the soft deleted books of the media library identified by <paramref name="libraryId"/>.
/// </summary>
/// <param name="libraryId">The Id of the media library whose soft deleted books are retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted books, or an error.</returns>
Task<Result<IReadOnlyList<BookEntity>>> GetSoftDeletedByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
/// <summary>
/// Soft deletes the book identified by <paramref name="id"/>, without removing its stored metadata or artwork.
/// </summary>
/// <param name="id">The Id of the book to soft delete.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Updated>> SoftDeleteByIdAsync(Guid id, CancellationToken cancellationToken);
/// <summary>
/// Restores the soft deleted book identified by <paramref name="id"/>.
/// </summary>
/// <param name="id">The Id of the book to restore.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
Task<Result<Updated>> RestoreSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken);
/// <summary>
/// Gets the subset of <paramref name="paths"/> that is already used by a book of the library identified by <paramref name="libraryId"/>.
/// </summary>
/// <remarks>
/// Soft deleted books are included on purpose: their paths must still count as taken, so that a scan never materializes a deleted book again.
/// </remarks>
/// <param name="libraryId">The Id of the library whose books are searched.</param>
/// <param name="paths">The book paths to check.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
@@ -83,6 +121,9 @@ public interface IBookRepository : IRepository<BookEntity>,
/// Resets the enrichment state of the books stored at the provided <paramref name="paths"/> in the media library identified by
/// <paramref name="libraryId"/>, so that they are re-enriched, because their content changed since the last scan.
/// </summary>
/// <remarks>
/// Soft deleted books are included on purpose: if such a book is restored after its content changed, it must be re-enriched instead of keeping stale metadata.
/// </remarks>
/// <param name="libraryId">The Id of the media library whose books are reset.</param>
/// <param name="paths">The file system paths of the books whose enrichment state is reset.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
@@ -93,6 +134,9 @@ public interface IBookRepository : IRepository<BookEntity>,
/// Resets the metadata enrichment status of all the books of the media library identified by <paramref name="libraryId"/>,
/// so that they are re-enriched, because the metadata provider configuration of the library changed.
/// </summary>
/// <remarks>
/// Soft deleted books are included on purpose: if such a book is restored after the provider configuration changed, it must be re-enriched with the new providers.
/// </remarks>
/// <param name="libraryId">The Id of the media library whose books are reset.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
@@ -102,6 +146,9 @@ public interface IBookRepository : IRepository<BookEntity>,
/// Resets the artwork status of all the artwork of the books of the media library identified by <paramref name="libraryId"/>,
/// so that they are re-resolved, because the artwork provider configuration of the library changed.
/// </summary>
/// <remarks>
/// Soft deleted books are included on purpose: if such a book is restored after the provider configuration changed, its artwork must be re-resolved with the new providers.
/// </remarks>
/// <param name="libraryId">The Id of the media library whose artwork is reset.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
@@ -258,6 +258,25 @@ public static class BookEntityMapping
);
}
/// <summary>
/// Converts a deleted <paramref name="repositoryEntity"/> to <see cref="DeletedBookResponse"/>.
/// </summary>
/// <param name="repositoryEntity">The deleted repository entity to be converted.</param>
/// <param name="deletedOnUtc">The date and time when the book was deleted.</param>
/// <returns>The converted deleted book response.</returns>
public static DeletedBookResponse ToResponse(this BookEntity repositoryEntity, DateTime deletedOnUtc)
{
return new DeletedBookResponse(
repositoryEntity.Id,
repositoryEntity.LibraryId,
repositoryEntity.Title,
repositoryEntity.OriginalTitle,
repositoryEntity.Path,
deletedOnUtc,
repositoryEntity.Artwork.FirstOrDefault(artwork => artwork.ArtworkType == ArtworkType.Cover)?.FileName
);
}
/// <summary>
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="Book"/>.
/// </summary>
@@ -1,15 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Artwork;
using Lumina.Domain.Common.Primitives;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Threading;
@@ -26,8 +23,6 @@ namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary
public class DeleteBookCommandHandler : ICommandHandler<DeleteBookCommand, Result<Deleted>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IBookArtworkService _bookArtworkService;
private readonly ILogger<DeleteBookCommandHandler> _logger;
private readonly IAuthorizationService _authorizationService;
private readonly ICurrentUserService _currentUserService;
private readonly IValidator<DeleteBookCommand> _validator;
@@ -36,22 +31,16 @@ public class DeleteBookCommandHandler : ICommandHandler<DeleteBookCommand, Resul
/// Initializes a new instance of the <see cref="DeleteBookCommandHandler"/> class.
/// </summary>
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
/// <param name="bookArtworkService">Injected service for removing the artwork of a book.</param>
/// <param name="logger">Injected logger used to report the issues encountered while removing the stored artwork.</param>
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
/// <param name="validator">Injected validator for application validation rules.</param>
public DeleteBookCommandHandler(
IUnitOfWork unitOfWork,
IBookArtworkService bookArtworkService,
ILogger<DeleteBookCommandHandler> logger,
IAuthorizationService authorizationService,
ICurrentUserService currentUserService,
IValidator<DeleteBookCommand> validator)
{
_unitOfWork = unitOfWork;
_bookArtworkService = bookArtworkService;
_logger = logger;
_authorizationService = authorizationService;
_currentUserService = currentUserService;
_validator = validator;
@@ -99,28 +88,9 @@ public class DeleteBookCommandHandler : ICommandHandler<DeleteBookCommand, Resul
if (!canAccessLibrary)
return ApplicationErrors.Authorization.NotAuthorized;
// A book can only belong to a library that exists, so a client can never delete a book of a library of the host that is not there.
Result<LibraryEntity?> getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(libraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsFailure)
return getLibraryResult.Errors;
if (getLibraryResult.Value is null)
return DomainErrors.Library.LibraryNotFound;
LibraryEntity library = getLibraryResult.Value;
// The artwork is stored under the library and author segments, so the author is resolved before the book is removed.
Result<IReadOnlyDictionary<Guid, string?>> getAuthorsResult = await _unitOfWork.BookRepository
.GetAuthorsDisplayNamesByBookIdsAsync([existingBook.Id], cancellationToken).ConfigureAwait(false);
if (getAuthorsResult.IsFailure)
return getAuthorsResult.Errors;
string authorName = getAuthorsResult.Value.TryGetValue(existingBook.Id, out string? authorDisplayName) && authorDisplayName is not null ? authorDisplayName : string.Empty;
// Delete the stored artwork of the book, best-effort, since a stale cover must not prevent the book from being removed.
Result<Deleted> deleteArtworkResult = _bookArtworkService.DeleteBookArtwork(libraryId, existingBook.Id, library.Title, authorName, existingBook.Title);
if (deleteArtworkResult.IsFailure)
_logger.LogWarning("Failed to delete the stored artwork of the book with Id '{BookId}' at path '{BookPath}', the artwork might remain orphaned.", existingBook.Id, existingBook.Path);
// Delete the book, whose stored artwork rows and participations are removed by the database cascade.
Result<Deleted> deleteBookResult = await _unitOfWork.BookRepository.DeleteByIdAsync(existingBook.Id, cancellationToken).ConfigureAwait(false);
// The book is soft deleted, so its metadata, artwork and path stay available until the user restores it or the file disappears from disk.
// Keeping the row is also what makes the deletion survive an automatic scan, because the scan treats its path as already catalogued.
Result<Updated> deleteBookResult = await _unitOfWork.BookRepository.SoftDeleteByIdAsync(existingBook.Id, cancellationToken).ConfigureAwait(false);
if (deleteBookResult.IsFailure)
return deleteBookResult.Errors;
@@ -0,0 +1,17 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using System.Diagnostics;
#endregion
namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.RestoreBook;
/// <summary>
/// Command for restoring a deleted book by its Id.
/// </summary>
/// <param name="LibraryId">The unique identifier of the media library this book belongs to, taken from the route.</param>
/// <param name="BookId">The unique identifier of the deleted book to restore, taken from the route.</param>
[DebuggerDisplay("BookId: {BookId}")]
public record RestoreBookCommand(
string? LibraryId,
string? BookId
) : ICommand;
@@ -0,0 +1,95 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.RestoreBook;
/// <summary>
/// Handler for the command to restore a deleted book by its Id.
/// </summary>
public class RestoreBookCommandHandler : ICommandHandler<RestoreBookCommand, Result<Updated>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IAuthorizationService _authorizationService;
private readonly ICurrentUserService _currentUserService;
private readonly IValidator<RestoreBookCommand> _validator;
/// <summary>
/// Initializes a new instance of the <see cref="RestoreBookCommandHandler"/> class.
/// </summary>
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
/// <param name="validator">Injected validator for application validation rules.</param>
public RestoreBookCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<RestoreBookCommand> validator)
{
_unitOfWork = unitOfWork;
_authorizationService = authorizationService;
_currentUserService = currentUserService;
_validator = validator;
}
/// <summary>
/// Handles the command to restore a deleted book by its Id.
/// </summary>
/// <param name="command">The command to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public async Task<Result<Updated>> HandleAsync(RestoreBookCommand command, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(command);
if (validationResult.Count > 0)
return validationResult;
// An authenticated request must always carry a user identity.
Guid? currentUserId = _currentUserService.UserId;
if (currentUserId is null)
return ApplicationErrors.Authorization.NotAuthorized;
Guid userId = currentUserId.Value;
// The validator guarantees that the route identifiers are non-empty Guids before this point.
Guid libraryId = Guid.Parse(command.LibraryId!);
Guid bookId = Guid.Parse(command.BookId!);
Result<BookEntity?> getBookResult = await _unitOfWork.BookRepository.GetSoftDeletedByIdAsync(bookId, cancellationToken).ConfigureAwait(false);
if (getBookResult.IsFailure)
return getBookResult.Errors;
if (getBookResult.Value is null)
return DomainErrors.WrittenContent.BookNotFound;
BookEntity existingBook = getBookResult.Value;
// Resource scoping: the book must belong to the library named by the route, so that a book can never be restored through another
// library's route; the mismatch is reported as not found, without disclosing that the book exists in another library.
if (existingBook.LibraryId != libraryId)
return DomainErrors.WrittenContent.BookNotFound;
// Admins can restore the books of all libraries; for everyone else, only the books of the libraries they own.
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
userId, new LibraryOwnershipPolicyContext(existingBook.LibraryId), cancellationToken).ConfigureAwait(false);
if (!canAccessLibrary)
return ApplicationErrors.Authorization.NotAuthorized;
Result<Updated> restoreBookResult = await _unitOfWork.BookRepository.RestoreSoftDeletedByIdAsync(existingBook.Id, cancellationToken).ConfigureAwait(false);
if (restoreBookResult.IsFailure)
return restoreBookResult.Errors;
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
if (saveChangesResult.IsFailure)
return saveChangesResult.Errors;
return Result.Updated;
}
}
@@ -0,0 +1,40 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.Common.Errors;
using System;
#endregion
namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.RestoreBook;
/// <summary>
/// Validates the needed validation rules for <see cref="RestoreBookCommand"/>.
/// </summary>
public class RestoreBookCommandValidator : AbstractValidator<RestoreBookCommand>
{
/// <summary>
/// Initializes a new instance of the <see cref="RestoreBookCommandValidator"/> class.
/// </summary>
public RestoreBookCommandValidator()
{
// Validates the identifier of the media library that owns the book, taken from the route.
RuleFor(command => command.LibraryId)
.NotEmpty()
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
RuleFor(command => command.LibraryId)
.Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty)
.When(command => command.LibraryId is not null && command.LibraryId.Length > 0)
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
// Validates the identifier of the deleted book, taken from the route.
RuleFor(command => command.BookId)
.NotEmpty()
.WithError(Errors.WrittenContent.BookIdCannotBeEmpty);
RuleFor(command => command.BookId)
.Must(bookId => Guid.TryParse(bookId, out Guid parsedBookId) && parsedBookId != Guid.Empty)
.When(command => command.BookId is not null && command.BookId.Length > 0)
.WithError(Errors.WrittenContent.BookIdCannotBeEmpty);
}
}
@@ -0,0 +1,13 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
#endregion
namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetDeletedBooks;
/// <summary>
/// Query for getting the deleted books of a media library.
/// </summary>
/// <param name="LibraryId">The unique identifier of the media library whose deleted books are retrieved, taken from the route.</param>
public record GetDeletedBooksQuery(
string? LibraryId
) : IQuery;
@@ -0,0 +1,80 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetDeletedBooks;
/// <summary>
/// Handler for the query to get the deleted books of a media library.
/// </summary>
public class GetDeletedBooksQueryHandler : IQueryHandler<GetDeletedBooksQuery, Result<IReadOnlyList<DeletedBookResponse>>>
{
private readonly IUnitOfWork _unitOfWork;
private readonly IAuthorizationService _authorizationService;
private readonly ICurrentUserService _currentUserService;
private readonly IValidator<GetDeletedBooksQuery> _validator;
/// <summary>
/// Initializes a new instance of the <see cref="GetDeletedBooksQueryHandler"/> class.
/// </summary>
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
/// <param name="validator">Injected validator for application validation rules.</param>
public GetDeletedBooksQueryHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<GetDeletedBooksQuery> validator)
{
_unitOfWork = unitOfWork;
_authorizationService = authorizationService;
_currentUserService = currentUserService;
_validator = validator;
}
/// <summary>
/// Handles the query to get the deleted books of a media library.
/// </summary>
/// <param name="query">The query to be handled.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>An <see cref="Result{TValue}"/> containing either the deleted books, or an error.</returns>
public async Task<Result<IReadOnlyList<DeletedBookResponse>>> HandleAsync(GetDeletedBooksQuery query, CancellationToken cancellationToken)
{
List<Error> validationResult = _validator.Validate(query);
if (validationResult.Count > 0)
return validationResult;
// An authenticated request must always carry a user identity.
Guid? currentUserId = _currentUserService.UserId;
if (currentUserId is null)
return ApplicationErrors.Authorization.NotAuthorized;
Guid userId = currentUserId.Value;
// The validator guarantees that the library id of the route is a non-empty Guid before this point.
Guid libraryId = Guid.Parse(query.LibraryId!);
// Admins can see all libraries; for everyone else, only the libraries they own.
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
userId, new LibraryOwnershipPolicyContext(libraryId), cancellationToken).ConfigureAwait(false);
if (!canAccessLibrary)
return ApplicationErrors.Authorization.NotAuthorized;
Result<IReadOnlyList<BookEntity>> getDeletedBooksResult = await _unitOfWork.BookRepository.GetSoftDeletedByLibraryIdAsync(libraryId, cancellationToken).ConfigureAwait(false);
if (getDeletedBooksResult.IsFailure)
return getDeletedBooksResult.Errors;
return Result.From<IReadOnlyList<DeletedBookResponse>>([.. getDeletedBooksResult.Value.Select(book => book.ToResponse(book.DeletedOnUtc ?? book.CreatedOnUtc))]);
}
}
@@ -0,0 +1,30 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Common.Utilities;
using Lumina.Domain.Common.Errors;
using System;
#endregion
namespace Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Queries.GetDeletedBooks;
/// <summary>
/// Validates the needed validation rules for <see cref="GetDeletedBooksQuery"/>.
/// </summary>
public class GetDeletedBooksQueryValidator : AbstractValidator<GetDeletedBooksQuery>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetDeletedBooksQueryValidator"/> class.
/// </summary>
public GetDeletedBooksQueryValidator()
{
// Validates the identifier of the media library whose deleted books are retrieved, taken from the route.
RuleFor(query => query.LibraryId)
.NotEmpty()
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
RuleFor(query => query.LibraryId)
.Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty)
.When(query => query.LibraryId is not null && query.LibraryId.Length > 0)
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
}
}