mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 04: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
+129
-1
@@ -1,11 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
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.Diagnostics;
|
||||
@@ -28,6 +29,31 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
/// </summary>
|
||||
public WrittenContentMetadata Metadata { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the media library this book belongs to.
|
||||
/// </summary>
|
||||
public LibraryId LibraryId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the file system path of the book.
|
||||
/// </summary>
|
||||
public string Path { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the status of the metadata enrichment of the book.
|
||||
/// </summary>
|
||||
public MetadataStatus MetadataStatus { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time when the metadata of the book was last enriched, if applicable.
|
||||
/// </summary>
|
||||
public Optional<DateTime> LastMetadataUpdateUtc { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the plugin that enriched the metadata of the book, if applicable.
|
||||
/// </summary>
|
||||
public Optional<string> MetadataProvider { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the format of the book (e.g., Hardcover, Paperback), if applicable.
|
||||
/// </summary>
|
||||
@@ -133,6 +159,8 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
/// <param name="ratings">The list of ratings for the book.</param>
|
||||
private Book(
|
||||
BookId id,
|
||||
LibraryId libraryId,
|
||||
string path,
|
||||
WrittenContentMetadata metadata,
|
||||
Optional<BookFormat> format,
|
||||
Optional<string> edition,
|
||||
@@ -154,7 +182,12 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
List<BookRating> ratings) : base(id)
|
||||
{
|
||||
Id = id;
|
||||
LibraryId = libraryId;
|
||||
Path = path;
|
||||
Metadata = metadata;
|
||||
MetadataStatus = MetadataStatus.Pending;
|
||||
LastMetadataUpdateUtc = Optional<DateTime>.None();
|
||||
MetadataProvider = Optional<string>.None();
|
||||
Format = format;
|
||||
Edition = edition;
|
||||
VolumeNumber = volumeNumber;
|
||||
@@ -178,6 +211,8 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="Book"/> class.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library this book belongs to.</param>
|
||||
/// <param name="path">The file system path 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>
|
||||
@@ -199,6 +234,8 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="Book"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Book> Create(
|
||||
LibraryId libraryId,
|
||||
string path,
|
||||
WrittenContentMetadata metadata,
|
||||
Optional<BookFormat> format,
|
||||
Optional<string> edition,
|
||||
@@ -220,6 +257,8 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
// TODO: enforce invariants
|
||||
return new Book(
|
||||
BookId.CreateUnique(),
|
||||
libraryId,
|
||||
path,
|
||||
metadata,
|
||||
format,
|
||||
edition,
|
||||
@@ -246,6 +285,8 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
/// Creates a new instance of the <see cref="Book"/>, with a pre-existing <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The object representing the unique identifier of the book.</param>
|
||||
/// <param name="libraryId">The Id of the media library this book belongs to.</param>
|
||||
/// <param name="path">The file system path 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>
|
||||
@@ -270,6 +311,8 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
/// </returns>
|
||||
public static ErrorOr<Book> Create(
|
||||
BookId id,
|
||||
LibraryId libraryId,
|
||||
string path,
|
||||
WrittenContentMetadata metadata,
|
||||
Optional<BookFormat> format,
|
||||
Optional<string> edition,
|
||||
@@ -293,6 +336,8 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
// TODO: enforce invariants
|
||||
return new Book(
|
||||
id,
|
||||
libraryId,
|
||||
path,
|
||||
metadata,
|
||||
format,
|
||||
edition,
|
||||
@@ -314,4 +359,87 @@ public sealed class Book : AggregateRoot<BookId>
|
||||
ratings
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks the metadata of the book as enriched by the provided <paramref name="providerName"/>.
|
||||
/// </summary>
|
||||
/// <param name="providerName">The name of the metadata provider that enriched the book.</param>
|
||||
/// <param name="lastUpdateUtc">The date and time when the metadata of the book was enriched.</param>
|
||||
public void MarkMetadataAsEnriched(string providerName, DateTime lastUpdateUtc)
|
||||
{
|
||||
MetadataProvider = providerName;
|
||||
LastMetadataUpdateUtc = lastUpdateUtc;
|
||||
MetadataStatus = MetadataStatus.Enriched;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks the metadata enrichment of the book as failed.
|
||||
/// </summary>
|
||||
public void MarkMetadataAsFailed()
|
||||
{
|
||||
MetadataStatus = MetadataStatus.Failed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the enriched <paramref name="metadata"/> and the related fields to the book, marking its metadata as enriched by the provided <paramref name="providerName"/>.
|
||||
/// </summary>
|
||||
/// <param name="metadata">The enriched metadata of the book.</param>
|
||||
/// <param name="format">The optional format of the book.</param>
|
||||
/// <param name="edition">The optional edition of the book.</param>
|
||||
/// <param name="volumeNumber">The optional volume or book number in the series.</param>
|
||||
/// <param name="series">The optional series the book is part of.</param>
|
||||
/// <param name="asin">The optional ASIN of the book.</param>
|
||||
/// <param name="goodreadsId">The optional Goodreads ID of the book.</param>
|
||||
/// <param name="lccn">The optional LCCN of the book.</param>
|
||||
/// <param name="oclcNumber">The optional OCLC Number of the book.</param>
|
||||
/// <param name="openLibraryId">The optional Open Library ID of the book.</param>
|
||||
/// <param name="libraryThingId">The optional LibraryThing ID of the book.</param>
|
||||
/// <param name="googleBooksId">The optional Google Books ID of the book.</param>
|
||||
/// <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="ratings">The list of ratings for the book.</param>
|
||||
/// <param name="providerName">The name of the metadata provider that enriched the book.</param>
|
||||
/// <param name="lastUpdateUtc">The date and time when the metadata was enriched.</param>
|
||||
public void ApplyEnrichedMetadata(
|
||||
WrittenContentMetadata metadata,
|
||||
Optional<BookFormat> format,
|
||||
Optional<string> edition,
|
||||
Optional<int> volumeNumber,
|
||||
Optional<BookSeries> series,
|
||||
Optional<string> asin,
|
||||
Optional<string> goodreadsId,
|
||||
Optional<string> lccn,
|
||||
Optional<string> oclcNumber,
|
||||
Optional<string> openLibraryId,
|
||||
Optional<string> libraryThingId,
|
||||
Optional<string> googleBooksId,
|
||||
Optional<string> barnesAndNobleId,
|
||||
Optional<string> appleBooksId,
|
||||
List<Isbn> isbns,
|
||||
List<BookRating> ratings,
|
||||
string providerName,
|
||||
DateTime lastUpdateUtc)
|
||||
{
|
||||
Metadata = metadata;
|
||||
Format = format;
|
||||
Edition = edition;
|
||||
VolumeNumber = volumeNumber;
|
||||
Series = series;
|
||||
ASIN = asin;
|
||||
GoodreadsId = goodreadsId;
|
||||
LCCN = lccn;
|
||||
OCLCNumber = oclcNumber;
|
||||
OpenLibraryId = openLibraryId;
|
||||
LibraryThingId = libraryThingId;
|
||||
GoogleBooksId = googleBooksId;
|
||||
BarnesAndNobleId = barnesAndNobleId;
|
||||
AppleBooksId = appleBooksId;
|
||||
// replace the contents of the collections in place, preserving the readonly reference invariants of the aggregate
|
||||
_isbns.Clear();
|
||||
_isbns.AddRange(isbns);
|
||||
_ratings.Clear();
|
||||
_ratings.AddRange(ratings);
|
||||
MarkMetadataAsEnriched(providerName, lastUpdateUtc);
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for the Id of a media library, duplicated from the LibraryManagement bounded context to keep the cross bounded context references decoupled.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Value}")]
|
||||
public sealed class LibraryId : EntityId<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryId"/> class.
|
||||
/// </summary>
|
||||
/// <param name="value">The value representing this object.</param>
|
||||
private LibraryId(Guid value) : base(value)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="LibraryId"/> class.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="LibraryId"/> instance.</returns>
|
||||
public static LibraryId CreateUnique()
|
||||
{
|
||||
return new LibraryId(Guid.NewGuid());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="LibraryId"/> class, from a pre-existing <paramref name="value"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value used to create the <see cref="LibraryId"/> instance.</param>
|
||||
/// <returns>The created <see cref="LibraryId"/> instance.</returns>
|
||||
public static LibraryId Create(Guid value)
|
||||
{
|
||||
return new LibraryId(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return Value;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user