Moves media library scanning to domain layer

This commit is contained in:
BinaryAlley committed 2025-02-16 21:45:26 +02:00
1 parent 8b51abe0b2
commit c4246d2e69
209 files changed
+3793 -641

No files matched your search

@@ -99,7 +99,7 @@ public sealed class Book : AggregateRoot<BookId>
public IReadOnlyCollection<Isbn> ISBNs => _isbns.AsReadOnly();
/// <summary>
/// Gets the list of media contributors (actors, directors, etc) starring in this book.
/// Gets the list of objects representing the unique identifiers of the media contributors (actors, directors, etc) starring in this book.
/// </summary>
public IReadOnlyCollection<MediaContributorId> Contributors => _contributors.AsReadOnly();
@@ -111,7 +111,7 @@ public sealed class Book : AggregateRoot<BookId>
/// <summary>
/// Initializes a new instance of the <see cref="Book"/> class.
/// </summary>
/// <param name="id">The unique identifier of the book.</param>
/// <param name="id">The object representing the unique identifier of the book.</param>
/// <param name="metadata">The metadata of the book.</param>
/// <param name="format">The optional format of the book (e.g., Hardcover, Paperback).</param>
/// <param name="edition">The optional edition of the book.</param>
@@ -129,7 +129,7 @@ public sealed class Book : AggregateRoot<BookId>
/// <param name="createdOnUtc">The date and time when the entity was created.</param>
/// <param name="updatedOnUtc">The date and time when the entity was last updated.</param>
/// <param name="isbns">The list of ISBNs of the book.</param>
/// <param name="contributors">The list of media contributors of the book.</param>
/// <param name="contributors">The list of objects representing the unique identifiers of the media contributors of the book.</param>
/// <param name="ratings">The list of ratings for the book.</param>
private Book(
BookId id,
@@ -175,16 +175,6 @@ public sealed class Book : AggregateRoot<BookId>
_ratings = ratings;
}
#pragma warning disable CS8618
/// <summary>
/// Initializes a new instance of the <see cref="Book"/> class.
/// </summary>
private Book() // only needed during reflection
{
}
#pragma warning restore CS8618
/// <summary>
/// Creates a new instance of the <see cref="Book"/> class.
/// </summary>
@@ -203,7 +193,7 @@ public sealed class Book : AggregateRoot<BookId>
/// <param name="barnesAndNobleId">The optional Barnes & Noble ID of the book.</param>
/// <param name="appleBooksId">The optional Apple Books ID of the book.</param>
/// <param name="isbns">The list of ISBNs of the book.</param>
/// <param name="contributors">The list of media contributors of the book.</param>
/// <param name="contributors">The list of objects representing the unique identifiers of the media contributors of the book.</param>
/// <param name="ratings">The list of ratings for the book.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfuly created <see cref="Book"/>, or an error message.
@@ -255,7 +245,7 @@ public sealed class Book : AggregateRoot<BookId>
/// <summary>
/// Creates a new instance of the <see cref="Book"/>, with a pre-existing <paramref name="id"/>.
/// </summary>
/// <param name="id">The object representing the id of the book.</param>
/// <param name="id">The object representing the unique identifier of the book.</param>
/// <param name="metadata">The metadata of the book.</param>
/// <param name="format">The optional format of the book (e.g., Hardcover, Paperback).</param>
/// <param name="edition">The optional edition of the book.</param>
@@ -273,7 +263,7 @@ public sealed class Book : AggregateRoot<BookId>
/// <param name="createdOnUtc">The date and time when the entity was created.</param>
/// <param name="updatedOnUtc">The date and time when the entity was last updated.</param>
/// <param name="isbns">The list of ISBNs of the book.</param>
/// <param name="contributors">The list of media contributors of the book.</param>
/// <param name="contributors">The list of objects representing the unique identifiers of the media contributors of the book.</param>
/// <param name="ratings">The list of ratings for the book.</param>
/// <returns>
/// An <see cref="ErrorOr{TValue}"/> containing either a successfuly created <see cref="Book"/>, or an error message.
@@ -35,7 +35,7 @@ public sealed class BookSeries : Entity<BookSeriesId>
/// <summary>
/// Initializes a new instance of the <see cref="BookSeries"/> class.
/// </summary>
/// <param name="id">The identifier of the book series.</param>
/// <param name="id">The object representing the unique identifier of the book series.</param>
/// <param name="metadata">The metadata of the book series.</param>
/// <param name="isComplete">The current status of the book series.</param>
/// <param name="books">The books of the book series.</param>
@@ -51,7 +51,7 @@ public sealed class BookSeries : Entity<BookSeriesId>
/// <summary>
/// Creates a new instance of the <see cref="BookSeries"/> class.
/// </summary>
/// <param name="id">The identifier of the book series.</param>
/// <param name="id">The object representing the unique identifier of the book series.</param>
/// <param name="metadata">The metadata of the book series.</param>
/// <param name="isComplete">The current status of the book series.</param>
/// <param name="books">The books of the book series.</param>
@@ -0,0 +1,13 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Jobs;
/// <summary>
/// Interface for the media library scan job for retrieving written content metadata from GoodReads.
/// </summary>
public interface IGoodReadsMetadataScrapJob : IMediaLibraryScanJob
{
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Enums.MediaLibrary;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Jobs;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Scanners;
/// <summary>
/// Media library scanner for a books media library type.
/// </summary>
internal class BookLibraryTypeScanner : IBookLibraryTypeScanner
{
private readonly IMediaLibraryScanJobFactory _mediaScanJobFactory;
/// <inheritdoc/>
public LibraryType SupportedType { get; } = LibraryType.Book;
/// <summary>
/// Initializes a new instance of the <see cref="BookLibraryTypeScanner"/> class.
/// </summary>
/// <param name="mediaScanJobFactory">Injected factory for creating media library scan jobs.</param>
public BookLibraryTypeScanner(IMediaLibraryScanJobFactory mediaScanJobFactory)
{
_mediaScanJobFactory = mediaScanJobFactory;
}
/// <inheritdoc/>
public IEnumerable<IMediaLibraryScanJob> CreateScanJobsForLibrary(LibraryId libraryId, bool downloadMedatadaFromWeb)
{
// declare the list of jobs that this scanner requires
IFileSystemDiscoveryJob fileSystemDiscoveryJob = _mediaScanJobFactory.CreateJob<IFileSystemDiscoveryJob>(libraryId);
IRepositoryMetadataDiscoveryJob repositoryMetadataDiscoveryJob = _mediaScanJobFactory.CreateJob<IRepositoryMetadataDiscoveryJob>(libraryId);
IHashComparerJob hashComparerJob = _mediaScanJobFactory.CreateJob<IHashComparerJob>(libraryId);
IGoodReadsMetadataScrapJob goodReadsMetadataScrapJob = _mediaScanJobFactory.CreateJob<IGoodReadsMetadataScrapJob>(libraryId);
// establish the hierarchical relationships between jobs
fileSystemDiscoveryJob.AddChild(hashComparerJob);
repositoryMetadataDiscoveryJob.AddChild(hashComparerJob);
hashComparerJob.AddParent(fileSystemDiscoveryJob);
hashComparerJob.AddParent(repositoryMetadataDiscoveryJob);
if (downloadMedatadaFromWeb)
{
hashComparerJob.AddChild(goodReadsMetadataScrapJob);
goodReadsMetadataScrapJob.AddParent(hashComparerJob);
}
// return the top level jobs that will be triggered when the scan will be started
yield return fileSystemDiscoveryJob;
yield return repositoryMetadataDiscoveryJob;
}
}
@@ -0,0 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Scanners.Common;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Scanners;
/// <summary>
/// Interface defining a media library scanner for a books media library type.
/// </summary>
public interface IBookLibraryTypeScanner : IMediaTypeScanner
{
}