Adds the capability of adding a Book via API

This commit is contained in:
BinaryAlley committed 2024-08-24 22:11:55 +03:00
1 parent 6459b6f2c2
commit 0eb7b453f6
61 files changed
+1276 -255

No files matched your search

@@ -54,7 +54,7 @@ public class AudioMetadata : BaseMetadata
/// <param name="durationInSeconds">The duration of the audio, in seconds.</param>
/// <param name="sampleRate">The sample rate of the audio, in Hz.</param>
/// <param name="channels">The number of audio channels.</param>
/// <param name="release">The release information of the audio.</param>
/// <param name="releaseInfo">The release information of the audio.</param>
/// <param name="description">The description of the audio.</param>
/// <param name="language">The language of the audio.</param>
/// <param name="originalLanguage">The optional original language of the video.</param>
@@ -68,7 +68,7 @@ public class AudioMetadata : BaseMetadata
int durationInSeconds,
int sampleRate,
int channels,
ReleaseInfo release,
ReleaseInfo releaseInfo,
Optional<string> description,
List<Genre> genres,
List<Tag> tags,
@@ -77,7 +77,7 @@ public class AudioMetadata : BaseMetadata
Optional<int> bitDepth,
Optional<string> audioCodec,
Optional<int> bitrate)
: base(title, originalTitle, release, description, genres, tags, language, originalLanguage)
: base(title, originalTitle, description, releaseInfo, genres, tags, language, originalLanguage)
{
DurationInSeconds = durationInSeconds;
SampleRate = sampleRate;
@@ -106,7 +106,7 @@ public class AudioMetadata : BaseMetadata
/// <param name="genres">The genres of the audio.</param>
/// <param name="tags">The tags associated with the audio.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="AudioMetadata"/> or an error message.
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="AudioMetadata"/>, or an error message.
/// </returns>
public static ErrorOr<AudioMetadata> Create(
string title,
@@ -68,7 +68,7 @@ public class FileInfo : ValueObject
/// <param name="lastModified">The date and time when the file was last modified.</param>
/// <param name="mimeType">The MIME type of the file, if available.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="FileInfo"/> or an error message.
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="FileInfo"/>, or an error message.
/// </returns>
public static ErrorOr<FileInfo> Create(string path, string fileExtension, long sizeInBytes, DateTime lastModified, Optional<string> mimeType)
{
@@ -100,7 +100,7 @@ public class StreamInfo : ValueObject
/// <param name="sampleRate">The sample rate of the stream (for audio).</param>
/// <param name="channels">The number of channels (for audio).</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="StreamInfo"/> or an error message.
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="StreamInfo"/>, or an error message.
/// </returns>
public static ErrorOr<StreamInfo> Create(
string streamId,
@@ -0,0 +1,59 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using Lumina.Domain.Common.Models.Core;
#endregion
namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
/// <summary>
/// Value Object for the role of a media contributor.
/// </summary>
[DebuggerDisplay("{DisplayName}")]
public sealed class MediaContributorRole : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the value representing this object.
/// </summary>
public string Name { get; }
/// <summary>
/// Gets the category of this object.
/// </summary>
public string Category { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="MediaContributorRole"/> class.
/// </summary>
/// <param name="name">The value representing this object.</param>
/// <param name="category">The category of this object.</param>
private MediaContributorRole(string name, string category)
{
Name = name;
Category = category;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="MediaContributorRole"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="name">The value representing this object.</param>
/// <param name="category">The category of this object.</param>
/// <returns>The created <see cref="MediaContributorRole"/> instance.</returns>
public static MediaContributorRole Create(string name, string category)
{
// TODO: enforce invariants
return new MediaContributorRole(name, category);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Name;
yield return Category;
}
#endregion
}
@@ -48,7 +48,7 @@ public class VideoMetadata : BaseMetadata
/// <param name="originalTitle">The optional original title of the video.</param>
/// <param name="durationInSeconds">The duration of the video, in seconds.</param>
/// <param name="resolution">The resolution of the video.</param>
/// <param name="release">The release information of the video.</param>
/// <param name="releaseInfo">The release information of the video.</param>
/// <param name="description">The optional description of the video.</param>
/// <param name="language">The language of the video.</param>
/// <param name="originalLanguage">The optional original language of the video.</param>
@@ -62,8 +62,8 @@ public class VideoMetadata : BaseMetadata
Optional<string> originalTitle,
int durationInSeconds,
string resolution,
ReleaseInfo release,
Optional<string> description,
ReleaseInfo releaseInfo,
Optional<LanguageInfo> language,
Optional<LanguageInfo> originalLanguage,
Optional<float> frameRate,
@@ -71,7 +71,7 @@ public class VideoMetadata : BaseMetadata
Optional<string> audioCodec,
List<Genre> genres,
List<Tag> tags)
: base(title, originalTitle, release, description, genres, tags, language, originalLanguage)
: base(title, originalTitle, description, releaseInfo, genres, tags, language, originalLanguage)
{
DurationInSeconds = durationInSeconds;
Resolution = resolution ?? throw new ArgumentNullException(nameof(resolution));
@@ -89,8 +89,8 @@ public class VideoMetadata : BaseMetadata
/// <param name="originalTitle">The optional original title of the video.</param>
/// <param name="durationInSeconds">The duration of the video in seconds.</param>
/// <param name="resolution">The resolution of the video.</param>
/// <param name="release">The release information of the video.</param>
/// <param name="description">The optional description of the video.</param>
/// <param name="releaseInfo">The release information of the video.</param>
/// <param name="language">The language of the video.</param>
/// <param name="originalLanguage">The optional original language of the video.</param>
/// <param name="frameRate">The optional frame rate of the video.</param>
@@ -100,15 +100,15 @@ public class VideoMetadata : BaseMetadata
/// <param name="tags">The tags associated with the video.</param>
/// <param name="contributors">The list of contributors for this video.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="VideoMetadata"/> or an error message.
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="VideoMetadata"/>, or an error message.
/// </returns>
public static ErrorOr<VideoMetadata> Create(
string title,
Optional<string> originalTitle,
int durationInSeconds,
string resolution,
ReleaseInfo release,
Optional<string> description,
ReleaseInfo releaseInfo,
Optional<LanguageInfo> language,
Optional<LanguageInfo> originalLanguage,
Optional<float> frameRate,
@@ -117,7 +117,7 @@ public class VideoMetadata : BaseMetadata
List<Genre> genres,
List<Tag> tags)
{
return new VideoMetadata(title, originalTitle, durationInSeconds, resolution, release, description,
return new VideoMetadata(title, originalTitle, durationInSeconds, resolution, description, releaseInfo,
language, originalLanguage, frameRate, videoCodec, audioCodec, genres, tags);
}
@@ -223,7 +223,9 @@ public sealed class Book : AggregateRoot<BookId, Guid>
/// <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="ratings">The list of ratings for the book.</param>
/// <returns>The created <see cref="Book"/>.</returns>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Book"/>, or an error message.
/// </returns>
public static ErrorOr<Book> Create(
WrittenContentMetadata metadata,
BookFormat format,
@@ -289,7 +291,9 @@ public sealed class Book : AggregateRoot<BookId, Guid>
/// <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="ratings">The list of ratings for the book.</param>
/// <returns>The created <see cref="Book"/>.</returns>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Book"/>, or an error message.
/// </returns>
public static ErrorOr<Book> Create(
BookId id,
WrittenContentMetadata metadata,
@@ -43,8 +43,10 @@ public sealed class BookSeries : Entity<BookSeriesId>
/// 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)
/// <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>
private BookSeries(BookSeriesId id, WrittenContentMetadata metadata, bool isComplete, List<Book> books)
: base(id)
{
Id = id;
@@ -56,6 +58,53 @@ public sealed class BookSeries : Entity<BookSeriesId>
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="BookSeries"/> class.
/// </summary>
/// <param name="id">The 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>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="BookSeries"/>, or an error message.
/// </returns>
public static ErrorOr<BookSeries> Create(
BookSeriesId id,
WrittenContentMetadata metadata,
bool isComplete,
List<Book> books)
{
// TODO: enforce invariants
return new BookSeries(
id,
metadata,
isComplete,
books
);
}
/// <summary>
/// Creates a new instance of the <see cref="BookSeries"/> class.
/// </summary>
/// <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>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="BookSeries"/>, or an error message.
/// </returns>
public static ErrorOr<BookSeries> Create(
WrittenContentMetadata metadata,
bool isComplete,
List<Book> books)
{
// TODO: enforce invariants
return new BookSeries(
BookSeriesId.CreateUnique(),
metadata,
isComplete,
books
);
}
/// <summary>
/// Adds a book to the series.
/// </summary>
/// <param name="book">The book to be added.</param>
@@ -34,7 +34,6 @@ public sealed class BookId : AggregateRootId<Guid>
/// <returns>The created <see cref="BookId"/> instance.</returns>
public static BookId CreateUnique()
{
// TODO: enforce invariants
return new BookId(Guid.NewGuid());
}
@@ -45,7 +44,6 @@ public sealed class BookId : AggregateRootId<Guid>
/// <returns>The created <see cref="BookId"/> instance.</returns>
public static BookId Create(Guid value)
{
// TODO: enforce invariants
return new BookId(value);
}
@@ -0,0 +1,83 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the rating of a media element.
/// </summary>
[DebuggerDisplay("{Value}/{MaxValue}")]
public class BookRating : Rating
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the optional source of the rating (e.g., "Goodreads", "Amazon").
/// </summary>
public Optional<BookRatingSource> Source { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="Rating"/> class.
/// </summary>
/// <param name="value">The numeric value of the rating.</param>
/// <param name="maxValue">The maximum possible rating value.</param>
/// <param name="source">The optional source of the rating.</param>
/// <param name="voteCount">The optional number of votes or reviews.</param>
private BookRating(decimal value, decimal maxValue, Optional<BookRatingSource> source, Optional<int> voteCount)
: base(value, maxValue, voteCount)
{
Source = source;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="Rating"/> class.
/// </summary>
/// <param name="value">The numeric value of the rating.</param>
/// <param name="maxValue">The maximum possible rating value.</param>
/// <param name="source">The optional source of the rating.</param>
/// <param name="voteCount">The optional number of votes or reviews.</param>
/// <returns>
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Rating"/>, or an error message.
/// </returns>
public static ErrorOr<BookRating> Create(decimal value, decimal maxValue, Optional<BookRatingSource> source, Optional<int> voteCount)
{
if (maxValue < 0 || value < 0)
return Errors.Metadata.RatingMustBePositive;
if (value > maxValue)
return Errors.Metadata.RatingValueCannotBeGreaterThanMaxValue;
return new BookRating(value, maxValue, source, voteCount);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
yield return MaxValue;
yield return Source;
yield return VoteCount;
}
/// <summary>
/// Customized ToString() method.
/// </summary>
/// <returns>Custom string value showing relevant data for current class.</returns>
public override string ToString()
{
string baseString = $"{Value}/{MaxValue}";
if (Source.HasValue)
baseString += $" ({Source.Value})";
if (VoteCount.HasValue)
baseString += $" [{VoteCount.Value} votes]";
return baseString;
}
#endregion
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
#endregion
@@ -30,9 +29,8 @@ public sealed class BookSeriesId : ValueObject
/// Creates a new instance of the <see cref="BookSeriesId"/> class.
/// </summary>
/// <returns>The created <see cref="BookSeriesId"/> instance.</returns>
public static ErrorOr<BookSeriesId> CreateUnique()
public static BookSeriesId CreateUnique()
{
// TODO: enforce invariants
return new BookSeriesId(Guid.NewGuid());
}
@@ -41,9 +39,8 @@ public sealed class BookSeriesId : ValueObject
/// </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)
public static BookSeriesId Create(Guid value)
{
// TODO: enforce invariants
return new BookSeriesId(value);
}
@@ -30,26 +30,26 @@ public class WrittenContentMetadata : BaseMetadata
/// </summary>
/// <param name="title">The title of the written content.</param>
/// <param name="originalTitle">The optional original title of the video.</param>
/// <param name="release">The release information of the written content.</param>
/// <param name="description">The description of the written content.</param>
/// <param name="releaseInfo">The release information of the written content.</param>
/// <param name="genres">The genres of the written content.</param>
/// <param name="tags">The tags associated with the written content.</param>
/// <param name="language">The language of the written content.</param>
/// <param name="originalLanguage">The optional original language of the video.</param>
/// <param name="publisher">The publisher of the written content.</param>
/// <param name="pageCount">The number of pages in the written content.</param>
public WrittenContentMetadata(
private WrittenContentMetadata(
string title,
Optional<string> originalTitle,
ReleaseInfo release,
Optional<string> description,
ReleaseInfo releaseInfo,
List<Genre> genres,
List<Tag> tags,
Optional<LanguageInfo> language,
Optional<LanguageInfo> originalLanguage,
Optional<string> publisher,
Optional<int> pageCount)
: base(title, originalTitle, release, description, genres, tags, language, originalLanguage)
: base(title, originalTitle, description, releaseInfo, genres, tags, language, originalLanguage)
{
Publisher = publisher;
PageCount = pageCount;
@@ -57,6 +57,44 @@ public class WrittenContentMetadata : BaseMetadata
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="WrittenContentMetadata"/> class.
/// </summary>
/// <param name="title">The title of the written content.</param>
/// <param name="originalTitle">The optional original title of the video.</param>
/// <param name="description">The description of the written content.</param>
/// <param name="releaseInfo">The release information of the written content.</param>
/// <param name="genres">The genres of the written content.</param>
/// <param name="tags">The tags associated with the written content.</param>
/// <param name="language">The language of the written content.</param>
/// <param name="originalLanguage">The optional original language of the video.</param>
/// <param name="publisher">The publisher of the written content.</param>
/// <param name="pageCount">The number of pages in the written content.</param>
public static WrittenContentMetadata Create(
string title,
Optional<string> originalTitle,
Optional<string> description,
ReleaseInfo releaseInfo,
List<Genre> genres,
List<Tag> tags,
Optional<LanguageInfo> language,
Optional<LanguageInfo> originalLanguage,
Optional<string> publisher,
Optional<int> pageCount)
{
return new WrittenContentMetadata(
title,
originalTitle,
description,
releaseInfo,
genres, tags,
language,
originalLanguage,
publisher,
pageCount
);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{