mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 02:11:10 +00:00
Adds the capability of adding a Book via API
This commit is contained in:
1 parent
6459b6f2c2
commit
0eb7b453f6
61 files changed
+1276
-255
No files matched your search
@@ -1,27 +0,0 @@
|
||||
namespace Lumina.Domain.Common.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the various roles of media contributors across different types of media.
|
||||
/// </summary>
|
||||
public enum MediaContributorRole
|
||||
{
|
||||
/// <summary>
|
||||
/// A person who portrays a character in a performance, typically in films, television shows, or theater productions.
|
||||
/// </summary>
|
||||
Actor,
|
||||
|
||||
/// <summary>
|
||||
/// The person responsible for overseeing and directing the production of a film, play, television show, or other performing art.
|
||||
/// </summary>
|
||||
Director,
|
||||
|
||||
/// <summary>
|
||||
/// A person who uses their voice to produce musical sounds, typically with a melody and often with lyrics in songs.
|
||||
/// </summary>
|
||||
Singer,
|
||||
|
||||
/// <summary>
|
||||
/// The creator or originator of a written work, such as a book, article, or other literary piece.
|
||||
/// </summary>
|
||||
Author
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public readonly struct Optional<T>
|
||||
{
|
||||
get
|
||||
{
|
||||
return HasValue ? _value! : throw new InvalidOperationException("Optional has no value.");
|
||||
return HasValue ? _value! : default!;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -34,10 +34,11 @@ public readonly struct Optional<T>
|
||||
/// Initializes a new instance of the <see cref="Optional{T}"/> structure.
|
||||
/// </summary>
|
||||
/// <param name="value">The value represented by this structure.</param>
|
||||
public Optional(T value)
|
||||
/// <param name="hasValue"><see langword="true"/> if <paramref name="value"/> is not <see langword="null"/>, <see langword="false"/>otherwise.</param>
|
||||
private Optional(T? value, bool hasValue)
|
||||
{
|
||||
_value = value;
|
||||
HasValue = true;
|
||||
HasValue = hasValue;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -48,7 +49,47 @@ public readonly struct Optional<T>
|
||||
/// <param name="value">The value to be converted.</param>
|
||||
public static implicit operator Optional<T>(T value)
|
||||
{
|
||||
return new Optional<T>(value);
|
||||
return Some(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="Optional{T}"/> with a value.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to wrap in the <see cref="Optional{T}"/>.</param>
|
||||
/// <returns>An <see cref="Optional{T}"/> containing the specified value.</returns>
|
||||
public static Optional<T> Some(T value)
|
||||
{
|
||||
return new Optional<T>(value, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="Optional{T}"/> with no value.
|
||||
/// </summary>
|
||||
/// <returns>An empty <see cref="Optional{T}"/>.</returns>
|
||||
public static Optional<T> None()
|
||||
{
|
||||
return new(default, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="Optional{T}"/> from a nullable reference type.
|
||||
/// </summary>
|
||||
/// <param name="value">The nullable value to convert.</param>
|
||||
/// <returns>An <see cref="Optional{T}"/> representing the nullable value.</returns>
|
||||
public static Optional<T> FromNullable(T? value)
|
||||
{
|
||||
return value is null ? None() : Some(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="Optional{T}"/> from a nullable value type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TValue">The underlying value type.</typeparam>
|
||||
/// <param name="value">The nullable value to convert.</param>
|
||||
/// <returns>An <see cref="Optional{T}"/> representing the nullable value.</returns>
|
||||
public static Optional<T> FromNullable<TValue>(TValue? value) where TValue : struct, T
|
||||
{
|
||||
return value.HasValue ? Some(value.Value) : None();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -71,8 +71,8 @@ public abstract class BaseMetadata : ValueObject
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="originalTitle">The optional original title of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="releaseInfo">The optional release information of the media item.</param>
|
||||
/// <param name="description">The optional description of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="releaseInfo">The optional release information of the media item.</param>
|
||||
/// <param name="genres">The list of genres of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="tags">The list of tags of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="language">The optional language of the element to which this metadata object belongs to.</param>
|
||||
@@ -81,8 +81,8 @@ public abstract class BaseMetadata : ValueObject
|
||||
protected BaseMetadata(
|
||||
string title,
|
||||
Optional<string> originalTitle,
|
||||
ReleaseInfo releaseInfo,
|
||||
Optional<string> description,
|
||||
ReleaseInfo releaseInfo,
|
||||
List<Genre> genres,
|
||||
List<Tag> tags,
|
||||
Optional<LanguageInfo> language,
|
||||
@@ -90,8 +90,8 @@ public abstract class BaseMetadata : ValueObject
|
||||
{
|
||||
Title = title ?? throw new ArgumentNullException(nameof(title));
|
||||
OriginalTitle = originalTitle;
|
||||
ReleaseInfo = releaseInfo;
|
||||
Description = description;
|
||||
ReleaseInfo = releaseInfo;
|
||||
_genres = genres;
|
||||
_tags = tags;
|
||||
Language = language;
|
||||
@@ -105,8 +105,8 @@ public abstract class BaseMetadata : ValueObject
|
||||
{
|
||||
yield return Title;
|
||||
yield return OriginalTitle;
|
||||
yield return ReleaseInfo;
|
||||
yield return Description;
|
||||
yield return ReleaseInfo;
|
||||
foreach (var genre in _genres)
|
||||
yield return genre;
|
||||
foreach (var tag in _tags)
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Genre : ValueObject
|
||||
/// </summary>
|
||||
/// <param name="name">The value of the genre.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Genre"/> or an error message.
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Genre"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Genre> Create(string name)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Enums;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Diagnostics;
|
||||
@@ -38,8 +37,6 @@ public class LanguageInfo : ValueObject
|
||||
/// <param name="languageCode">The ISO 639-1 two-letter language code.</param>
|
||||
/// <param name="languageName">The full name of the language in English.</param>
|
||||
/// <param name="nativeName">The optional native name of the language.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown if languageCode or languageName is null.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if languageCode is not a valid ISO 639-1 code.</exception>
|
||||
private LanguageInfo(string languageCode, string languageName, Optional<string> nativeName)
|
||||
{
|
||||
LanguageCode = languageCode.ToLowerInvariant();
|
||||
@@ -56,7 +53,7 @@ public class LanguageInfo : ValueObject
|
||||
/// <param name="languageName">The full name of the language in English.</param>
|
||||
/// <param name="nativeName">The optional native name of the language.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="LanguageInfo"/> or an error message.
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="LanguageInfo"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<LanguageInfo> Create(string languageCode, string languageName, Optional<string> nativeName)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Enums;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Diagnostics;
|
||||
@@ -12,28 +10,23 @@ namespace Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
/// Value Object for the rating of a media element.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Value}/{MaxValue}")]
|
||||
public class Rating : ValueObject
|
||||
public abstract class Rating : ValueObject
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets the numeric value of the rating.
|
||||
/// </summary>
|
||||
public decimal Value { get; }
|
||||
public decimal Value { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum possible rating value.
|
||||
/// </summary>
|
||||
public decimal MaxValue { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional source of the rating (e.g., "IMDB", "Rotten Tomatoes").
|
||||
/// </summary>
|
||||
public Optional<VideoRatingSource> Source { get; }
|
||||
public decimal MaxValue { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional number of votes or reviews this rating is based on.
|
||||
/// </summary>
|
||||
public Optional<int> VoteCount { get; }
|
||||
public Optional<int> VoteCount { get; private set; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
@@ -42,37 +35,16 @@ public class Rating : ValueObject
|
||||
/// </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 Rating(decimal value, decimal maxValue, Optional<VideoRatingSource> source, Optional<int> voteCount)
|
||||
protected Rating(decimal value, decimal maxValue, Optional<int> voteCount)
|
||||
{
|
||||
Value = value;
|
||||
MaxValue = maxValue;
|
||||
Source = source;
|
||||
VoteCount = voteCount;
|
||||
}
|
||||
#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<Rating> Create(decimal value, decimal maxValue, Optional<VideoRatingSource> source, Optional<int> voteCount)
|
||||
{
|
||||
if (maxValue < 0 || value < 0)
|
||||
return Errors.Errors.Metadata.RatingMustBePositive;
|
||||
if (value > maxValue)
|
||||
return Errors.Errors.Metadata.RatingValueCannotBeGreaterThanMaxValue;
|
||||
return new Rating(value, maxValue, source, voteCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the rating as a percentage.
|
||||
/// </summary>
|
||||
@@ -81,28 +53,5 @@ public class Rating : ValueObject
|
||||
{
|
||||
return (Value / MaxValue) * 100;
|
||||
}
|
||||
|
||||
/// <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
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class ReleaseInfo : ValueObject
|
||||
/// <param name="releaseCountry">The optional country or region of release.</param>
|
||||
/// <param name="releaseVersion">The optional release version or edition.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="ReleaseInfo"/> or an error message.
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="ReleaseInfo"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<ReleaseInfo> Create(
|
||||
Optional<DateOnly> originalReleaseDate,
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Tag : ValueObject
|
||||
/// </summary>
|
||||
/// <param name="name">The value of the tag.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Tag"/> or an error message.
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Tag"/>, or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Tag> Create(string name)
|
||||
{
|
||||
|
||||
+4
-4
@@ -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,
|
||||
|
||||
+1
-1
@@ -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)
|
||||
{
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
+59
@@ -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
|
||||
}
|
||||
+7
-7
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -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,
|
||||
|
||||
+51
-2
@@ -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>
|
||||
|
||||
-2
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+83
@@ -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
|
||||
}
|
||||
+2
-5
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+42
-4
@@ -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()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user