mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Scopes books to a media library and tracks their metadata enrichment status
This commit is contained in:
1 parent
386d583a2b
commit
f33817f2d2
48 files changed
+2038
-63
No files matched your search
+26
-1
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -19,6 +19,16 @@ public class BookEntity : IStorageEntity, IAuditableEntity
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the media library this book belongs to.
|
||||
/// </summary>
|
||||
public required Guid LibraryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the file system path of the book.
|
||||
/// </summary>
|
||||
public required string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the media item.
|
||||
/// </summary>
|
||||
@@ -195,6 +205,21 @@ public class BookEntity : IStorageEntity, IAuditableEntity
|
||||
/// </summary>
|
||||
public List<BookRatingEntity> Ratings { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the status of the metadata enrichment of the book.
|
||||
/// </summary>
|
||||
public MetadataStatus MetadataStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the metadata of the book was last enriched.
|
||||
/// </summary>
|
||||
public DateTime? LastMetadataUpdateUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the plugin that enriched the metadata of the book.
|
||||
/// </summary>
|
||||
public string? MetadataProvider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
@@ -11,6 +16,43 @@ namespace Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
/// </summary>
|
||||
public interface IBookRepository : IRepository<BookEntity>,
|
||||
IInsertRepositoryAction<BookEntity>,
|
||||
IUpdateRepositoryAction<BookEntity>,
|
||||
IGetByIdRepositoryAction<BookEntity, Guid>,
|
||||
IGetAllRepositoryAction<BookEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all the books of the media library identified by <paramref name="libraryId"/>.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose books are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of <see cref="BookEntity"/>, or an error.</returns>
|
||||
Task<ErrorOr<IEnumerable<BookEntity>>> GetByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the book of the media library identified by <paramref name="libraryId"/> that is stored at the provided <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <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="ErrorOr{TValue}"/> containing either the <see cref="BookEntity"/> stored at the provided path, or an error.</returns>
|
||||
Task<ErrorOr<BookEntity?>> GetByPathAsync(Guid libraryId, string path, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a page of the books of the media library identified by <paramref name="libraryId"/> whose metadata has not been enriched yet,
|
||||
/// ordered by path, using keyset pagination.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose books are retrieved.</param>
|
||||
/// <param name="lastPath">The path of the last retrieved book, used for keyset pagination. Pass <see langword="null"/> to get the first page.</param>
|
||||
/// <param name="pageSize">The maximum number of books to retrieve.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a page of books needing their metadata enriched, or an error.</returns>
|
||||
Task<ErrorOr<IReadOnlyList<BookEntity>>> GetBooksNeedingMetadataAsync(Guid libraryId, string? lastPath, int pageSize, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of books of the media library identified by <paramref name="libraryId"/> whose metadata has not been enriched yet.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose books are counted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either the number of books needing their metadata enriched, or an error.</returns>
|
||||
Task<ErrorOr<int>> GetBooksNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
}
|
||||
+8
@@ -24,6 +24,14 @@ public interface ILibraryScanSnapshotRepository : IRepository<LibraryScanSnapsho
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of deleted media library scan snapshot item paths, or an error.</returns>
|
||||
Task<ErrorOr<IReadOnlyList<string>>> GetDeletedPathsAsync(Guid libraryId, Guid scanId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the paths of all the media library scan snapshot items of the media library identified by <paramref name="libraryId"/>.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The unique identifier of the library whose media library scan snapshot item paths are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{TValue}"/> containing either a collection of media library scan snapshot item paths, or an error.</returns>
|
||||
Task<ErrorOr<IReadOnlyList<string>>> GetPathsAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Atomically applies the results of the current scan to the storage medium, by replacing the media library scan snapshot of the previous scan with the snapshot of the current scan.
|
||||
/// The operation updates the changed media library scan snapshot items, deletes the ones that are no longer present on disk, adds audit entries for all changed, new and deleted items,
|
||||
|
||||
+2
@@ -19,6 +19,8 @@ public static class AddBookRequestMapping
|
||||
public static AddBookCommand ToCommand(this AddBookRequest request)
|
||||
{
|
||||
return new AddBookCommand(
|
||||
request.LibraryId,
|
||||
request.Path,
|
||||
request.Metadata,
|
||||
request.Format,
|
||||
request.Edition,
|
||||
|
||||
+9
-1
@@ -7,12 +7,13 @@ using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookL
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -110,6 +111,8 @@ public static class BookEntityMapping
|
||||
|
||||
return Book.Create(
|
||||
BookId.Create(repositoryEntity.Id),
|
||||
LibraryId.Create(repositoryEntity.LibraryId),
|
||||
repositoryEntity.Path,
|
||||
writtenContentMetadataResult.Value,
|
||||
bookFormat,
|
||||
Optional<string>.FromNullable(repositoryEntity.Edition),
|
||||
@@ -190,6 +193,8 @@ public static class BookEntityMapping
|
||||
);
|
||||
return new BookResponse(
|
||||
repositoryEntity.Id,
|
||||
repositoryEntity.LibraryId,
|
||||
repositoryEntity.Path,
|
||||
metadata,
|
||||
repositoryEntity.Format,
|
||||
repositoryEntity.Edition,
|
||||
@@ -207,6 +212,9 @@ public static class BookEntityMapping
|
||||
[.. repositoryEntity.ISBNs.ToResponses()],
|
||||
null,
|
||||
[.. repositoryEntity.Ratings.ToResponses()],
|
||||
repositoryEntity.MetadataStatus,
|
||||
repositoryEntity.LastMetadataUpdateUtc,
|
||||
repositoryEntity.MetadataProvider,
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
repositoryEntity.UpdatedOnUtc
|
||||
);
|
||||
|
||||
+5
@@ -24,6 +24,8 @@ public static class BookMapping
|
||||
return new BookEntity
|
||||
{
|
||||
Id = domainEntity.Id.Value,
|
||||
LibraryId = domainEntity.LibraryId.Value,
|
||||
Path = domainEntity.Path,
|
||||
Title = domainEntity.Metadata.Title,
|
||||
OriginalTitle = domainEntity.Metadata.OriginalTitle.HasValue ? domainEntity.Metadata.OriginalTitle.Value : null,
|
||||
Description = domainEntity.Metadata.Description.HasValue ? domainEntity.Metadata.Description.Value : null,
|
||||
@@ -57,6 +59,9 @@ public static class BookMapping
|
||||
AppleBooksId = domainEntity.AppleBooksId.HasValue ? domainEntity.AppleBooksId.Value : null,
|
||||
ISBNs = domainEntity.ISBNs.ToRepositoryEntities().ToList(),
|
||||
Ratings = domainEntity.Ratings.ToRepositoryEntities().ToList(),
|
||||
MetadataStatus = domainEntity.MetadataStatus,
|
||||
LastMetadataUpdateUtc = domainEntity.LastMetadataUpdateUtc.HasValue ? domainEntity.LastMetadataUpdateUtc.Value : null,
|
||||
MetadataProvider = domainEntity.MetadataProvider.HasValue ? domainEntity.MetadataProvider.Value : null,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc : null,
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetBooksRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetBooksRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetBooksQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetBooksQuery ToQuery(this GetBooksRequest request)
|
||||
{
|
||||
return new GetBooksQuery(request.LibraryId);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user