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

@@ -51,7 +51,7 @@ public class BookRepositoryTests
anchorConnection.Open();
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
context.Database.EnsureCreated();
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
Guid libraryId = Guid.NewGuid();
BookEntity changedBook = _bookEntityFixture.Create();
@@ -91,7 +91,7 @@ public class BookRepositoryTests
anchorConnection.Open();
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
context.Database.EnsureCreated();
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
Guid libraryId = Guid.NewGuid();
BookEntity book = _bookEntityFixture.Create();
@@ -120,7 +120,7 @@ public class BookRepositoryTests
anchorConnection.Open();
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
context.Database.EnsureCreated();
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
Guid libraryId = Guid.NewGuid();
BookEntity enrichedBook = _bookEntityFixture.Create();
@@ -155,7 +155,7 @@ public class BookRepositoryTests
anchorConnection.Open();
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
context.Database.EnsureCreated();
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
Guid libraryId = Guid.NewGuid();
BookEntity book = _bookEntityFixture.Create();
@@ -189,7 +189,7 @@ public class BookRepositoryTests
anchorConnection.Open();
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
context.Database.EnsureCreated();
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
BookEntity book = _bookEntityFixture.Create();
@@ -214,7 +214,7 @@ public class BookRepositoryTests
anchorConnection.Open();
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
context.Database.EnsureCreated();
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
Guid libraryId = Guid.NewGuid();
BookEntity existingBook = _bookEntityFixture.Create();
@@ -244,7 +244,7 @@ public class BookRepositoryTests
Guid userId = Guid.NewGuid();
DateTime utcNow = new(2025, 1, 1, 12, 0, 0, DateTimeKind.Utc);
using LuminaDbContext context = CreateAuditedContext(anchorConnection, userId, utcNow);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
BookEntity book = _bookEntityFixture.Create(includeMetadata: false);
book.Contributors = [_bookContributorEntityFixture.Create(bookId: book.Id)];
book.Ratings = [_bookRatingEntityFixture.Create(source: BookRatingSource.GoogleBooks)];
@@ -278,7 +278,7 @@ public class BookRepositoryTests
Guid userId = Guid.NewGuid();
DateTime utcNow = new(2025, 1, 1, 12, 0, 0, DateTimeKind.Utc);
using LuminaDbContext context = CreateAuditedContext(anchorConnection, userId, utcNow);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
BookEntity book = _bookEntityFixture.Create(includeMetadata: false);
book.Contributors = [_bookContributorEntityFixture.Create(bookId: book.Id)];
book.Ratings = [_bookRatingEntityFixture.Create(source: BookRatingSource.GoogleBooks)];
@@ -315,7 +315,7 @@ public class BookRepositoryTests
Guid userId = Guid.NewGuid();
DateTime utcNow = new(2025, 1, 1, 12, 0, 0, DateTimeKind.Utc);
using LuminaDbContext context = CreateAuditedContext(anchorConnection, userId, utcNow);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
BookEntity book = _bookEntityFixture.Create(includeMetadata: false);
Guid keptMediaContributorId = Guid.NewGuid();
BookContributorEntity keptContributor = _bookContributorEntityFixture.Create(bookId: book.Id, mediaContributorId: keptMediaContributorId);
@@ -348,7 +348,7 @@ public class BookRepositoryTests
Guid userId = Guid.NewGuid();
DateTime utcNow = new(2025, 1, 1, 12, 0, 0, DateTimeKind.Utc);
using LuminaDbContext context = CreateAuditedContext(anchorConnection, userId, utcNow);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
BookEntity book = _bookEntityFixture.Create(includeMetadata: false);
Guid keptMediaContributorId = Guid.NewGuid();
BookContributorEntity keptContributor = _bookContributorEntityFixture.Create(bookId: book.Id, mediaContributorId: keptMediaContributorId);
@@ -380,7 +380,7 @@ public class BookRepositoryTests
anchorConnection.Open();
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
context.Database.EnsureCreated();
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
BookEntity book = _bookEntityFixture.Create(includeMetadata: false);
book.Tags = [_tagEntityFixture.Create(name: $"noop-book-tag-{Guid.NewGuid():N}"), _tagEntityFixture.Create(name: $"noop-book-tag-two-{Guid.NewGuid():N}")];
@@ -429,7 +429,7 @@ public class BookRepositoryTests
anchorConnection.Open();
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
context.Database.EnsureCreated();
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
string keptTagName = $"remove-book-tag-{Guid.NewGuid():N}";
string keptGenreName = $"remove-book-genre-{Guid.NewGuid():N}";
@@ -483,7 +483,7 @@ public class BookRepositoryTests
anchorConnection.Open();
using LuminaDbContext context = new(new DbContextOptionsBuilder<LuminaDbContext>().UseSqlite(anchorConnection.ConnectionString).Options);
context.Database.EnsureCreated();
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
Guid libraryId = Guid.NewGuid();
BookEntity bookOfLibrary = _bookEntityFixture.Create();
@@ -513,7 +513,7 @@ public class BookRepositoryTests
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-bookrepo-getbyids-empty-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
anchorConnection.Open();
using LuminaDbContext context = CreateContext(anchorConnection);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
context.Books.Add(_bookEntityFixture.Create(includeMetadata: false));
await context.SaveChangesAsync();
@@ -533,7 +533,7 @@ public class BookRepositoryTests
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-bookrepo-getbyids-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
anchorConnection.Open();
using LuminaDbContext context = CreateContext(anchorConnection);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
BookEntity firstBook = _bookEntityFixture.Create(includeMetadata: false);
BookEntity secondBook = _bookEntityFixture.Create(includeMetadata: false);
BookEntity thirdBook = _bookEntityFixture.Create(includeMetadata: false);
@@ -559,7 +559,7 @@ public class BookRepositoryTests
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-bookrepo-getbyids-notracking-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
anchorConnection.Open();
using LuminaDbContext context = CreateContext(anchorConnection);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
MediaContributorEntity author = _mediaContributorEntityFixture.Create(displayName: "Frank Herbert");
BookEntity book = _bookEntityFixture.Create(includeMetadata: false);
book.Tags = [_tagEntityFixture.Create(name: "HiddenTag")];
@@ -600,7 +600,7 @@ public class BookRepositoryTests
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-bookrepo-getbyids-include-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
anchorConnection.Open();
using LuminaDbContext context = CreateContext(anchorConnection);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
MediaContributorEntity author = _mediaContributorEntityFixture.Create(displayName: "Frank Herbert");
BookEntity book = _bookEntityFixture.Create(includeMetadata: false);
book.Tags = [_tagEntityFixture.Create(name: "LoadedTag"), _tagEntityFixture.Create(name: "SecondLoadedTag")];
@@ -635,7 +635,7 @@ public class BookRepositoryTests
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-bookrepo-getbyids-boundary-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
anchorConnection.Open();
using LuminaDbContext context = CreateContext(anchorConnection);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
const int BOOK_COUNT = 500;
List<BookEntity> books = CreateBooks(BOOK_COUNT);
context.Books.AddRange(books);
@@ -661,7 +661,7 @@ public class BookRepositoryTests
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-bookrepo-getbyids-chunks-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
anchorConnection.Open();
using LuminaDbContext context = CreateContext(anchorConnection);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
const int BOOK_COUNT = 501;
List<BookEntity> books = CreateBooks(BOOK_COUNT);
context.Books.AddRange(books);
@@ -687,7 +687,7 @@ public class BookRepositoryTests
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-bookrepo-authors-min-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
anchorConnection.Open();
using LuminaDbContext context = CreateContext(anchorConnection);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
BookEntity book = _bookEntityFixture.Create(includeMetadata: false);
MediaContributorEntity firstAuthor = _mediaContributorEntityFixture.Create(displayName: "Zoe Author");
MediaContributorEntity secondAuthor = _mediaContributorEntityFixture.Create(displayName: "Alice Author");
@@ -717,7 +717,7 @@ public class BookRepositoryTests
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-bookrepo-authors-requested-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
anchorConnection.Open();
using LuminaDbContext context = CreateContext(anchorConnection);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
BookEntity requestedBook = _bookEntityFixture.Create(includeMetadata: false);
BookEntity bookNotRequested = _bookEntityFixture.Create(includeMetadata: false);
MediaContributorEntity requestedAuthor = _mediaContributorEntityFixture.Create(displayName: "Requested Author");
@@ -746,7 +746,7 @@ public class BookRepositoryTests
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-bookrepo-authors-empty-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
anchorConnection.Open();
using LuminaDbContext context = CreateContext(anchorConnection);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
BookEntity book = _bookEntityFixture.Create(includeMetadata: false);
MediaContributorEntity author = _mediaContributorEntityFixture.Create();
context.Books.Add(book);
@@ -772,7 +772,7 @@ public class BookRepositoryTests
using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-bookrepo-authors-chunks-{Guid.NewGuid()};Mode=Memory;Cache=Shared");
anchorConnection.Open();
using LuminaDbContext context = CreateContext(anchorConnection);
BookRepository sut = new(context);
BookRepository sut = new(context, Substitute.For<IDateTimeProvider>());
const int BOOK_COUNT = 501;
List<BookEntity> books = CreateBooks(BOOK_COUNT);
MediaContributorEntity author = _mediaContributorEntityFixture.Create(displayName: "Shared Author");
@@ -348,6 +348,30 @@ public class FavoriteRepositoryTests
Assert.Equal((Guid?)expectedLibraryId, result.Value);
}
[Fact]
public async Task GetMediaItemLibraryIdAsync_WhenTheBookIsSoftDeleted_ShouldReturnSuccessWithNull()
{
// Arrange
using SqliteConnection anchorConnection = CreateAnchorConnection("library-id-deleted-book");
using LuminaDbContext context = CreateContext(anchorConnection);
FavoriteRepository sut = new(context);
BookEntity deletedBook = _bookEntityFixture.Create(
libraryId: Guid.NewGuid(),
path: $"/books/{Guid.NewGuid()}.epub",
isDeleted: true,
includeMetadata: false);
context.Books.Add(deletedBook);
await context.SaveChangesAsync();
// Act
Result<Guid?> result = await sut.GetMediaItemLibraryIdAsync(FavoriteMediaKind.Book, deletedBook.Id, CancellationToken.None);
// Assert
// A deleted book is hidden from the catalogue, so adding it to favorites is rejected as if the book did not exist.
Assert.False(result.IsFailure);
Assert.Null(result.Value);
}
[Fact]
public async Task GetMediaItemLibraryIdAsync_WhenTheMediaItemDoesNotExist_ShouldReturnSuccessWithNull()
{
@@ -853,6 +877,38 @@ public class FavoriteRepositoryTests
Assert.Null(item.Display);
}
[Fact]
public async Task GetAllForUserAsync_WhenTheFavoritedBookIsDeleted_ShouldKeepTheFavoriteWithoutDisplayData()
{
// Arrange
using SqliteConnection anchorConnection = CreateAnchorConnection("list-deleted-book");
using LuminaDbContext context = CreateContext(anchorConnection);
FavoriteRepository sut = new(context);
Guid userId = Guid.NewGuid();
Guid libraryId = Guid.NewGuid();
context.Users.Add(_userEntityFixture.Create(id: userId));
BookEntity deletedBook = _bookEntityFixture.Create(
libraryId: libraryId,
path: $"/books/{Guid.NewGuid()}.epub",
title: "Deleted Book",
isDeleted: true,
includeMetadata: false);
FavoriteEntity favorite = CreateFavorite(userId, FavoriteMediaKind.Book, deletedBook.Id);
context.Books.Add(deletedBook);
context.Favorites.Add(favorite);
await context.SaveChangesAsync();
// Act
Result<PaginatedResultDto<FavoriteItemDto>> result = await sut.GetAllForUserAsync(userId, FavoriteMediaKind.Book, paginationData: null, cancellationToken: CancellationToken.None);
// Assert
// A deleted book is hidden from the catalogue, so its favorite must fall back to the unavailable state instead of exposing its display data.
Assert.False(result.IsFailure);
FavoriteItemDto item = Assert.Single(result.Value.Data);
Assert.Equal(favorite.Id, item.Favorite.Id);
Assert.Null(item.Display);
}
[Theory]
[InlineData(FavoriteMediaKind.Video)] // planned kind, so no display data can be resolved yet
[InlineData(FavoriteMediaKind.Photo)] // planned kind, so no display data can be resolved yet
@@ -47,7 +47,7 @@ public class UnitOfWorkTests
{
using (dbContext)
{
UnitOfWork sut = new(dbContext);
UnitOfWork sut = new(dbContext, Substitute.For<IDateTimeProvider>());
// Act
await sut.BeginTransactionAsync(CancellationToken.None);
@@ -67,7 +67,7 @@ public class UnitOfWorkTests
{
using (dbContext)
{
UnitOfWork sut = new(dbContext);
UnitOfWork sut = new(dbContext, Substitute.For<IDateTimeProvider>());
RoleEntity role = _roleEntityFixture.Create(roleName: "Admin");
// Act
@@ -95,7 +95,7 @@ public class UnitOfWorkTests
{
using (dbContext)
{
UnitOfWork sut = new(dbContext);
UnitOfWork sut = new(dbContext, Substitute.For<IDateTimeProvider>());
// Act
await sut.CommitTransactionAsync(CancellationToken.None);
@@ -115,7 +115,7 @@ public class UnitOfWorkTests
{
using (dbContext)
{
UnitOfWork sut = new(dbContext);
UnitOfWork sut = new(dbContext, Substitute.For<IDateTimeProvider>());
RoleEntity role = _roleEntityFixture.Create(roleName: "Admin");
// Act
@@ -142,7 +142,7 @@ public class UnitOfWorkTests
{
using (dbContext)
{
UnitOfWork sut = new(dbContext);
UnitOfWork sut = new(dbContext, Substitute.For<IDateTimeProvider>());
// Act
await sut.RollbackTransactionAsync(CancellationToken.None);
@@ -162,7 +162,7 @@ public class UnitOfWorkTests
{
using (dbContext)
{
UnitOfWork sut = new(dbContext);
UnitOfWork sut = new(dbContext, Substitute.For<IDateTimeProvider>());
// Act
await sut.BeginTransactionAsync(CancellationToken.None);
@@ -183,7 +183,7 @@ public class UnitOfWorkTests
{
using (dbContext)
{
UnitOfWork sut = new(dbContext);
UnitOfWork sut = new(dbContext, Substitute.For<IDateTimeProvider>());
// Act
sut.Dispose();
@@ -203,7 +203,7 @@ public class UnitOfWorkTests
{
using (dbContext)
{
UnitOfWork sut = new(dbContext);
UnitOfWork sut = new(dbContext, Substitute.For<IDateTimeProvider>());
Guid libraryId = Guid.NewGuid();
BookEntity firstBook = _bookEntityFixture.Create();
firstBook.LibraryId = libraryId;
@@ -237,7 +237,7 @@ public class UnitOfWorkTests
{
using (dbContext)
{
UnitOfWork sut = new(dbContext);
UnitOfWork sut = new(dbContext, Substitute.For<IDateTimeProvider>());
// Act
IFavoriteRepository firstRepository = sut.FavoriteRepository;
@@ -259,7 +259,7 @@ public class UnitOfWorkTests
{
using (dbContext)
{
UnitOfWork sut = new(dbContext);
UnitOfWork sut = new(dbContext, Substitute.For<IDateTimeProvider>());
Guid userId = Guid.NewGuid();
dbContext.Users.Add(_userEntityFixture.Create(id: userId));
Result<Success> userSaveResult = await sut.SaveChangesAsync(CancellationToken.None);
@@ -303,7 +303,7 @@ public class UnitOfWorkTests
{
using (dbContext)
{
UnitOfWork sut = new(dbContext);
UnitOfWork sut = new(dbContext, Substitute.For<IDateTimeProvider>());
Guid userId = Guid.NewGuid();
UserEntity user = _userEntityFixture.Create(id: userId);
FavoriteEntity favorite = _favoriteEntityFixture.Create(
@@ -337,7 +337,7 @@ public class UnitOfWorkTests
{
using (dbContext)
{
UnitOfWork sut = new(dbContext);
UnitOfWork sut = new(dbContext, Substitute.For<IDateTimeProvider>());
dbContext.Users.Add(_userEntityFixture.Create(id: userId));
Guid mediaItemId = Guid.NewGuid();
// The fixture populates the update audit columns, so the test also proves the interceptor owns them on insert.