mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 22:11:10 +00:00
Continues core Domain structure modeling
This commit is contained in:
1 parent
84229a5f1e
commit
6459b6f2c2
7 files changed
+157
-8
No files matched your search
@@ -16,6 +16,8 @@ public static partial class Errors
|
||||
public static Error InvalidIsbn10Format => Error.Validation(nameof(InvalidIsbn10Format));
|
||||
public static Error InvalidIsbn13Format => Error.Validation(nameof(InvalidIsbn13Format));
|
||||
public static Error UnknownIsbnFormat => Error.Unexpected(nameof(UnknownIsbnFormat));
|
||||
public static Error TheBookIsAlreadyInTheSeries => Error.Forbidden(nameof(TheBookIsAlreadyInTheSeries));
|
||||
public static Error TheBookIsNotInTheSeries => Error.Forbidden(nameof(TheBookIsNotInTheSeries));
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+3
@@ -10,6 +10,9 @@ namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggrega
|
||||
public sealed class MediaContributorId : AggregateRootId<Guid>
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets the value of this object.
|
||||
/// </summary>
|
||||
public override Guid Value { get; protected set; }
|
||||
#endregion
|
||||
|
||||
|
||||
+7
-6
@@ -6,16 +6,17 @@ using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Entity for a book.
|
||||
/// Aggregate root for a book.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Id}: {Title}")]
|
||||
public sealed class Book : Entity<BookId>
|
||||
public sealed class Book : AggregateRoot<BookId, Guid>
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly List<MediaContributorId> _contributors;
|
||||
@@ -47,7 +48,7 @@ public sealed class Book : Entity<BookId>
|
||||
/// <summary>
|
||||
/// Gets the series name, if the book is part of a series.
|
||||
/// </summary>
|
||||
public Optional<string> Series { get; private set; }
|
||||
public Optional<BookSeries> Series { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ASIN (Amazon Standard Identification Number) of the book.
|
||||
@@ -153,7 +154,7 @@ public sealed class Book : Entity<BookId>
|
||||
BookFormat format,
|
||||
Optional<string> edition,
|
||||
Optional<int> volumeNumber,
|
||||
Optional<string> series,
|
||||
Optional<BookSeries> series,
|
||||
Optional<string> asin,
|
||||
Optional<string> goodreadsId,
|
||||
Optional<string> lccn,
|
||||
@@ -228,7 +229,7 @@ public sealed class Book : Entity<BookId>
|
||||
BookFormat format,
|
||||
Optional<string> edition,
|
||||
Optional<int> volumeNumber,
|
||||
Optional<string> series,
|
||||
Optional<BookSeries> series,
|
||||
Optional<string> asin,
|
||||
Optional<string> goodreadsId,
|
||||
Optional<string> lccn,
|
||||
@@ -295,7 +296,7 @@ public sealed class Book : Entity<BookId>
|
||||
BookFormat format,
|
||||
Optional<string> edition,
|
||||
Optional<int> volumeNumber,
|
||||
Optional<string> series,
|
||||
Optional<BookSeries> series,
|
||||
Optional<string> asin,
|
||||
Optional<string> goodreadsId,
|
||||
Optional<string> lccn,
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Entity for a book series.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Id}: {Title}")]
|
||||
public sealed class BookSeries : Entity<BookSeriesId>
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly List<Book> _books;
|
||||
#endregion
|
||||
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets the written content metadata of the book series.
|
||||
/// </summary>
|
||||
public WrittenContentMetadata Metadata { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the series is complete.
|
||||
/// </summary>
|
||||
public bool IsComplete { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of books in the series.
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<Book> Books
|
||||
{
|
||||
get { return _books.AsReadOnly(); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookSeries"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The identifier of the book series.</param>
|
||||
/// <param name="title">The title of the book series.</param>
|
||||
public BookSeries(BookSeriesId id, WrittenContentMetadata metadata, bool isComplete, List<Book> books)
|
||||
: base(id)
|
||||
{
|
||||
Id = id;
|
||||
Metadata = metadata;
|
||||
IsComplete = isComplete;
|
||||
_books = books;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Adds a book to the series.
|
||||
/// </summary>
|
||||
/// <param name="book">The book to be added.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Created> AddBook(Book book)
|
||||
{
|
||||
if (_books.Contains(book))
|
||||
return Errors.WrittenContent.TheBookIsAlreadyInTheSeries;
|
||||
_books.Add(book);
|
||||
return Result.Created;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a book from the series.
|
||||
/// </summary>
|
||||
/// <param name="book">The book to be removed.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successful operation, or an error.</returns>
|
||||
public ErrorOr<Deleted> RemoveBook(Book book)
|
||||
{
|
||||
if (!_books.Contains(book))
|
||||
return Errors.WrittenContent.TheBookIsNotInTheSeries;
|
||||
_books.Remove(book);
|
||||
return Result.Deleted;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+5
-2
@@ -7,10 +7,13 @@ namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggrega
|
||||
/// <summary>
|
||||
/// Value Object for the Id of a book.
|
||||
/// </summary>
|
||||
public sealed class BookId : ValueObject
|
||||
public sealed class BookId : AggregateRootId<Guid>
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
public Guid Value { get; }
|
||||
/// <summary>
|
||||
/// Gets the value of the <see cref="BookId"/>.
|
||||
/// </summary>
|
||||
public override Guid Value { get; protected set; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for the Id of a book series.
|
||||
/// </summary>
|
||||
public sealed class BookSeriesId : ValueObject
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
public Guid Value { get; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookSeriesId"/> class.
|
||||
/// </summary>
|
||||
/// <param name="value">The value representing this object.</param>
|
||||
private BookSeriesId(Guid value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="BookSeriesId"/> class.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="BookSeriesId"/> instance.</returns>
|
||||
public static ErrorOr<BookSeriesId> CreateUnique()
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
return new BookSeriesId(Guid.NewGuid());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="BookSeriesId"/> class, from a pre-existing <paramref name="value"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value used to create the <see cref="BookSeriesId"/> instance.</param>
|
||||
/// <returns>The created <see cref="BookSeriesId"/> instance.</returns>
|
||||
public static ErrorOr<BookSeriesId> Create(Guid value)
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
return new BookSeriesId(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return Value;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user