Continues core Domain structure modeling

This commit is contained in:
BinaryAlley committed 2024-08-23 10:07:04 +03:00
1 parent c39652066e
commit 50c15cf889
54 files changed
+2318 -159

No files matched your search

@@ -0,0 +1,158 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.AudioLibrary.AudioLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the audio metadata of a media element.
/// </summary>
[DebuggerDisplay("{Title}")]
public class AudioMetadata : BaseMetadata
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the duration of the video in seconds.
/// </summary>
public int DurationInSeconds { get; }
/// <summary>
/// Gets the sample rate of the audio in Hz.
/// </summary>
public int SampleRate { get; }
/// <summary>
/// Gets the number of audio channels.
/// </summary>
public int Channels { get; }
/// <summary>
/// Gets the bit depth of the audio.
/// </summary>
public Optional<int> BitDepth { get; }
/// <summary>
/// Gets the audio codec used.
/// </summary>
public Optional<string> AudioCodec { get; }
/// <summary>
/// Gets the bitrate of the audio in kbps.
/// </summary>
public Optional<int> Bitrate { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="AudioMetadata"/> class.
/// </summary>
/// <param name="title">The title of the audio.</param>
/// <param name="originalTitle">The optional original title of the video.</param>
/// <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="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>
/// <param name="bitDepth">The bit depth of the audio.</param>
/// <param name="audioCodec">The audio codec used.</param>
/// <param name="genres">The genres of the audio.</param>
/// <param name="tags">The tags associated with the audio.</param>
public AudioMetadata(
string title,
Optional<string> originalTitle,
int durationInSeconds,
int sampleRate,
int channels,
ReleaseInfo release,
Optional<string> description,
List<Genre> genres,
List<Tag> tags,
Optional<LanguageInfo> language,
Optional<LanguageInfo> originalLanguage,
Optional<int> bitDepth,
Optional<string> audioCodec,
Optional<int> bitrate)
: base(title, originalTitle, release, description, genres, tags, language, originalLanguage)
{
DurationInSeconds = durationInSeconds;
SampleRate = sampleRate;
Channels = channels;
BitDepth = bitDepth;
AudioCodec = audioCodec;
Bitrate = bitrate;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="AudioMetadata"/> class.
/// </summary>
/// <param name="title">The title of the audio.</param>
/// <param name="originalTitle">The optional original title of the video.</param>
/// <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="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>
/// <param name="bitDepth">The bit depth of the audio.</param>
/// <param name="audioCodec">The audio codec used.</param>
/// <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.
/// </returns>
public static ErrorOr<AudioMetadata> Create(
string title,
Optional<string> originalTitle,
int durationInSeconds,
int sampleRate,
int channels,
ReleaseInfo release,
Optional<string>
description,
List<Genre> genres,
List<Tag> tags,
Optional<LanguageInfo> language,
Optional<LanguageInfo> originalLanguage,
Optional<int> bitDepth,
Optional<string> audioCodec,
Optional<int> bitrate)
{
return new AudioMetadata(
title,
originalTitle,
durationInSeconds,
sampleRate,
channels,
release,
description,
genres,
tags,
language,
originalLanguage,
bitDepth,
audioCodec,
bitrate);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
foreach (var component in base.GetEqualityComponents())
yield return component;
yield return DurationInSeconds;
yield return SampleRate;
yield return Channels;
yield return BitDepth;
yield return AudioCodec;
yield return Bitrate;
}
#endregion
}
@@ -0,0 +1,92 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
/// <summary>
/// Value Object for the information of a file.
/// </summary>
public class FileInfo : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the path of the file.
/// </summary>
public string Path { get; }
/// <summary>
/// Gets the extension of the file.
/// </summary>
public string FileExtension { get; }
/// <summary>
/// Gets the size of the file, in bytes.
/// </summary>
public long SizeInBytes { get; }
/// <summary>
/// Gets the last modification date of the file.
/// </summary>
public DateTime LastModified { get; }
/// <summary>
/// Gets the optional MIME type of the file.
/// </summary>
public Optional<string> MimeType { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="FileInfo"/> class.
/// </summary>
/// <param name="path">The full path of the file.</param>
/// <param name="fileExtension">The file extension.</param>
/// <param name="sizeInBytes">The size of the file in bytes.</param>
/// <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>
private FileInfo(string path, string fileExtension, long sizeInBytes, DateTime lastModified, Optional<string> mimeType)
{
Path = path;
FileExtension = fileExtension;
SizeInBytes = sizeInBytes;
LastModified = lastModified;
MimeType = mimeType;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="FileInfo"/> class.
/// </summary>
/// <param name="path">The full path of the file.</param>
/// <param name="fileExtension">The file extension.</param>
/// <param name="sizeInBytes">The size of the file in bytes.</param>
/// <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.
/// </returns>
public static ErrorOr<FileInfo> Create(string path, string fileExtension, long sizeInBytes, DateTime lastModified, Optional<string> mimeType)
{
if (path is null)
return Errors.FileManagement.PathCannotBeEmpty;
if (fileExtension is null)
return Errors.FileManagement.ExtensionCannotBeEmpty;
return new FileInfo(path, fileExtension, sizeInBytes, lastModified, mimeType);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Path;
yield return SizeInBytes;
yield return FileExtension;
yield return LastModified;
yield return MimeType;
}
#endregion
}
@@ -0,0 +1,137 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
/// <summary>
/// Value Object for the information about a media stream.
/// </summary>
public class StreamInfo : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the id of the stream.
/// </summary>
public string StreamId { get; }
/// <summary>
/// Gets the MimeType of the stream.
/// </summary>
public string MimeType { get; }
/// <summary>
/// Gets the bitrate of the stream.
/// </summary>
public int Bitrate { get; }
/// <summary>
/// Gets the codec of the stream.
/// </summary>
public string Codec { get; }
/// <summary>
/// Gets the optional resolution of the stream.
/// </summary>
public Optional<string> Resolution { get; }
/// <summary>
/// Gets the optional frame rate of the stream.
/// </summary>
public Optional<float> FrameRate { get; }
/// <summary>
/// Gets the optional sample rate of the stream.
/// </summary>
public Optional<int> SampleRate { get; }
/// <summary>
/// Gets the optional channels of the stream.
/// </summary>
public Optional<int> Channels { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="StreamInfo"/> class.
/// </summary>
/// <param name="streamId">The unique identifier for the stream.</param>
/// <param name="mimeType">The MIME type of the stream content.</param>
/// <param name="bitrate">The bitrate of the stream in bits per second.</param>
/// <param name="codec">The codec used for the stream.</param>
/// <param name="resolution">The resolution of the stream (for video).</param>
/// <param name="frameRate">The frame rate of the stream (for video).</param>
/// <param name="sampleRate">The sample rate of the stream (for audio).</param>
/// <param name="channels">The number of channels (for audio).</param>
private StreamInfo(
string streamId,
string mimeType,
int bitrate,
string codec,
Optional<string> resolution,
Optional<float> frameRate,
Optional<int> sampleRate,
Optional<int> channels)
{
StreamId = streamId;
MimeType = mimeType;
Bitrate = bitrate;
Codec = codec;
Resolution = resolution;
FrameRate = frameRate;
SampleRate = sampleRate;
Channels = channels;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="StreamInfo"/> class.
/// </summary>
/// <param name="streamId">The unique identifier for the stream.</param>
/// <param name="mimeType">The MIME type of the stream content.</param>
/// <param name="bitrate">The bitrate of the stream in bits per second.</param>
/// <param name="codec">The codec used for the stream.</param>
/// <param name="resolution">The resolution of the stream (for video).</param>
/// <param name="frameRate">The frame rate of the stream (for video).</param>
/// <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.
/// </returns>
public static ErrorOr<StreamInfo> Create(
string streamId,
string mimeType,
int bitrate,
string codec,
Optional<string> resolution,
Optional<float> frameRate,
Optional<int> sampleRate,
Optional<int> channels)
{
if (streamId is null)
return Errors.FileManagement.StreamIdCannotBeEmpty;
if (codec is null)
return Errors.FileManagement.CodecCannotBeEmpty;
if (bitrate <= 0)
return Errors.FileManagement.BitrateMustBeAPositiveNumber;
return new StreamInfo(streamId, mimeType, bitrate, codec, resolution, frameRate, sampleRate, channels);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return StreamId;
yield return MimeType;
yield return Bitrate;
yield return Codec;
yield return Resolution;
yield return FrameRate;
yield return SampleRate;
yield return Channels;
}
#endregion
}
@@ -0,0 +1,100 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
#endregion
namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate;
/// <summary>
/// Aggregate Root for a media contributor.
/// </summary>
[DebuggerDisplay("{Id}: {Name}")]
public class MediaContributor : AggregateRoot<MediaContributorId, Guid>
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the name of the contributor.
/// </summary>
public MediaContributorName Name { get; private set; }
/// <summary>
/// Gets the role of the contributor.
/// </summary>
public MediaContributorRole Role { get; private set; }
/// <summary>
/// Gets the biography of the contributor.
/// </summary>
public Optional<string> Biography { get; private set; }
/// <summary>
/// Gets the date of birth of the contributor.
/// </summary>
public Optional<DateOnly> DateOfBirth { get; private set; }
/// <summary>
/// Gets the date of death of the contributor.
/// </summary>
public Optional<DateOnly> DateOfDeath { get; private set; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="MediaContributor"/> class.
/// </summary>
/// <param name="id">The unique identifier of the contributor.</param>
/// <param name="name">The name of the contributor.</param>
/// <param name="role">The role of the contributor.</param>
/// <param name="dateOfBirth">The optional date of birth of the contributor.</param>
/// <param name="dateOfBirth">The optional date of death of the contributor.</param>
private MediaContributor(
MediaContributorId id,
MediaContributorName name,
MediaContributorRole role,
Optional<DateOnly> dateOfBirth,
Optional<DateOnly> dateOfDeath)
{
Id = id;
Name = name;
Role = role;
DateOfBirth = dateOfBirth;
DateOfDeath = dateOfDeath;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="MediaContributor"/> class.
/// </summary>
/// <param name="id">The unique identifier of the contributor.</param>
/// <param name="name">The name of the contributor.</param>
/// <returns>The created <see cref="MediaContributor"/> instance.</returns>
public static ErrorOr<MediaContributor> Create(MediaContributorName name)
{
// TODO: enforce invariants
throw new NotImplementedException();
//return new MediaContributor(id, name);
}
/// <summary>
/// Creates a new instance of the <see cref="MediaContributor"/> class, from a pre-existing <paramref name="id"/>.
/// </summary>
/// <param name="id">The unique identifier of the contributor.</param>
/// <param name="name">The name of the contributor.</param>
/// <returns>The created <see cref="MediaContributor"/> instance.</returns>
public static ErrorOr<MediaContributor> Create(
MediaContributorId id,
MediaContributorName name,
MediaContributorRole role,
Optional<DateOnly> dateOfBirth,
Optional<DateOnly> dateOfDeath)
{
return new MediaContributor(id, name, role, dateOfBirth, dateOfDeath);
}
#endregion
}
@@ -0,0 +1,61 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
#endregion
namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
/// <summary>
/// Value Object for the name of a person.
/// </summary>
[DebuggerDisplay("{DisplayName}")]
public sealed class MediaContributorName : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the name by which the contributor is popularly known.
/// </summary>
public string DisplayName { get; private set; }
/// <summary>
/// Gets the legal name of the contributor.
/// </summary>
public Optional<string> LegalName { get; private set; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="MediaContributorName"/> class.
/// </summary>
/// <param name="displayName">The name by which the contributor is popularly known.</param>
/// <param name="legalName">The legal name of the contributor.</param>
private MediaContributorName(string displayName, Optional<string> legalName)
{
DisplayName = displayName;
LegalName = legalName;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="MediaContributorName"/> class.
/// </summary>
/// <param name="displayName">The name by which the contributor is popularly known.</param>
/// <param name="legalName">The legal name of the contributor.</param>
/// <returns>The created <see cref="MediaContributorName"/> instance.</returns>
public static ErrorOr<MediaContributorName> Create(string displayName, Optional<string> legalName)
{
// TODO: enforce invariants
return new MediaContributorName(displayName, legalName);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return DisplayName;
yield return LegalName;
}
#endregion
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
#endregion
namespace Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
/// <summary>
/// Value Object for the Id of a media contributor.
/// </summary>
public sealed class MediaContributorId : AggregateRootId<Guid>
{
#region ==================================================================== PROPERTIES =================================================================================
public override Guid Value { get; protected set; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="MediaContributorId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private MediaContributorId(Guid value)
{
Value = value;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="MediaContributorId"/> class.
/// </summary>
/// <returns>The created <see cref="MediaContributorId"/> instance.</returns>
public static MediaContributorId CreateUnique()
{
// TODO: enforce invariants
return new MediaContributorId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="MediaContributorId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="MediaContributorId"/> instance.</param>
/// <returns>The created <see cref="MediaContributorId"/> instance.</returns>
public static MediaContributorId Create(Guid value)
{
// TODO: enforce invariants
return new MediaContributorId(value);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
#endregion
}
@@ -0,0 +1,101 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using ErrorOr;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.Aggregates.MediaContributor.MediaContributorAggregate.ValueObjects;
using Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.ValueObjects;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate;
/// <summary>
/// Entity for a movie.
/// </summary>
[DebuggerDisplay("{Id}: {Title}")]
public sealed class Movie : Entity<MovieId>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly List<MediaContributorId> _contributors;
private readonly List<Rating> _ratings;
#endregion
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the video metadata of the movie.
/// </summary>
public VideoMetadata Metadata { get; private set; }
/// <summary>
/// Gets the list of ratings for this movie.
/// </summary>
public IReadOnlyCollection<Rating> Ratings
{
get { return _ratings.AsReadOnly(); }
}
/// <summary>
/// Gets the list of media contributors (actors, directors, etc) starring in this movie.
/// </summary>
public IReadOnlyCollection<MediaContributorId> Contributors
{
get { return _contributors.AsReadOnly(); }
}
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="Movie"/> class.
/// </summary>
/// <param name="id">The unique identifier of the movie.</param>
/// <param name="metadata">The metadata of the movie.</param>
/// <param name="contributors">The list of the contributors of the movie.</param>
/// <param name="ratings">The list of ratings for the movie.</param>
public Movie(MovieId id, VideoMetadata metadata, List<MediaContributorId> contributors, List<Rating> ratings) : base(id)
{
Id = id;
Metadata = metadata;
_contributors = contributors;
_ratings = ratings;
}
#pragma warning disable CS8618
/// <summary>
/// Initializes a new instance of the <see cref="Movie"/> class.
/// </summary>
private Movie() // only needed during reflection
{
}
#pragma warning restore CS8618
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="Movie"/> class.
/// </summary>
/// <param name="metadata">The metadata of the movie.</param>
/// <param name="contributors">The list of media contributors of the movie.</param>
/// <param name="ratings">The list of ratings for the movie.</param>
/// <returns>The created <see cref="Movie"/>.</returns>
public static ErrorOr<Movie> Create(VideoMetadata metadata, List<MediaContributorId> contributors, List<Rating> ratings)
{
// TODO: enforce invariants
return new Movie(MovieId.CreateUnique(), metadata, contributors, ratings);
}
/// <summary>
/// Creates a new instance of the <see cref="Movie"/> class, with a pre-existing <paramref name="id"/>.
/// </summary>
/// <param name="id">The object representing the id of the movie.</param>
/// <param name="metadata">The metadata of the movie.</param>
/// <param name="contributors">The list of media contributors of the movie.</param>
/// <param name="ratings">The list of ratings for the movie.</param>
/// <returns>The created <see cref="Movie"/>.</returns>
public static ErrorOr<Movie> Create(MovieId id, VideoMetadata metadata, List<MediaContributorId> contributors, List<Rating> ratings)
{
// TODO: enforce invariants
return new Movie(id, metadata, contributors, ratings);
}
#endregion
}
@@ -0,0 +1,14 @@
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.Services;
/// <summary>
/// Service for managing movie libraries.
/// </summary>
public interface IMovieLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the collection of movies in the library.
/// </summary>
public ICollection<Movie> Movies { get; }
#endregion
}
@@ -0,0 +1,14 @@
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.Services;
public sealed class MovieLibraryService : IMovieLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the collection of movies in the library.
/// </summary>
public ICollection<Movie> Movies
{
get { throw new NotImplementedException(); }
}
#endregion
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the Id of a movie.
/// </summary>
public sealed class MovieId : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
public Guid Value { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="MovieId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private MovieId(Guid value)
{
Value = value;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="MovieId"/> class.
/// </summary>
/// <returns>The created <see cref="MovieId"/> instance.</returns>
public static MovieId CreateUnique()
{
// TODO: enforce invariants
return new MovieId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="MovieId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="MovieId"/> instance.</param>
/// <returns>The created <see cref="MovieId"/> instance.</returns>
public static MovieId Create(Guid value)
{
// TODO: enforce invariants
return new MovieId(value);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
#endregion
}
@@ -0,0 +1,136 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the video metadata of a media element.
/// </summary>
[DebuggerDisplay("{Title}")]
public class VideoMetadata : BaseMetadata
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the duration of the video in seconds.
/// </summary>
public int DurationInSeconds { get; }
/// <summary>
/// Gets the resolution of the video.
/// </summary>
public string Resolution { get; } // TODO: should be implemented as a value object with width, height, aspet ratio, etc.
/// <summary>
/// Gets the frame rate of the video.
/// </summary>
public Optional<float> FrameRate { get; }
/// <summary>
/// Gets the video codec used.
/// </summary>
public Optional<string> VideoCodec { get; }
/// <summary>
/// Gets the audio codec used.
/// </summary>
public Optional<string> AudioCodec { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="VideoMetadata"/> class.
/// </summary>
/// <param name="title">The title of the video.</param>
/// <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="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>
/// <param name="videoCodec">The optional video codec used.</param>
/// <param name="audioCodec">The optional audio codec used.</param>
/// <param name="genres">The genres of the video.</param>
/// <param name="tags">The tags associated with the video.</param>
private VideoMetadata(
string title,
Optional<string> originalTitle,
int durationInSeconds,
string resolution,
ReleaseInfo release,
Optional<string> description,
Optional<LanguageInfo> language,
Optional<LanguageInfo> originalLanguage,
Optional<float> frameRate,
Optional<string> videoCodec,
Optional<string> audioCodec,
List<Genre> genres,
List<Tag> tags)
: base(title, originalTitle, release, description, genres, tags, language, originalLanguage)
{
DurationInSeconds = durationInSeconds;
Resolution = resolution ?? throw new ArgumentNullException(nameof(resolution));
FrameRate = frameRate;
VideoCodec = videoCodec;
AudioCodec = audioCodec;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="VideoMetadata"/> class.
/// </summary>
/// <param name="title">The title of the video.</param>
/// <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="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>
/// <param name="videoCodec">The optional video codec used.</param>
/// <param name="audioCodec">The optional audio codec used.</param>
/// <param name="genres">The genres of the video.</param>
/// <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.
/// </returns>
public static ErrorOr<VideoMetadata> Create(
string title,
Optional<string> originalTitle,
int durationInSeconds,
string resolution,
ReleaseInfo release,
Optional<string> description,
Optional<LanguageInfo> language,
Optional<LanguageInfo> originalLanguage,
Optional<float> frameRate,
Optional<string> videoCodec,
Optional<string> audioCodec,
List<Genre> genres,
List<Tag> tags)
{
return new VideoMetadata(title, originalTitle, durationInSeconds, resolution, release, description,
language, originalLanguage, frameRate, videoCodec, audioCodec, genres, tags);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
foreach (var component in base.GetEqualityComponents())
yield return component;
yield return DurationInSeconds;
yield return Resolution;
yield return FrameRate;
yield return VideoCodec;
yield return AudioCodec;
}
#endregion
}
@@ -0,0 +1,24 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.Services;
using Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Services;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.Services;
/// <summary>
/// Interface for the service for managing video content.
/// </summary>
public interface IVideoLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the service for managing a movie library.
/// </summary>
public IMovieLibraryService MovieLibraryService { get; }
/// <summary>
/// Gets the service for managing a TV shows library.
/// </summary>
public ITvShowLibraryService TvShowLibraryService { get; }
#endregion
}
@@ -0,0 +1,40 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.Aggregates.VideoLibrary.MovieLibraryAggregate.Services;
using Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Services;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.Services;
/// <summary>
/// Service for managing video content.
/// </summary>
public class VideoLibraryService : IVideoLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the service for managing a movie library.
/// </summary>
public IMovieLibraryService MovieLibraryService { get; private set; }
/// <summary>
/// Gets the service for managing a TV shows library.
/// </summary>
public ITvShowLibraryService TvShowLibraryService { get; private set; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="VideoLibraryService"/> class.
/// </summary>
/// <param name="movieLibraryService">Injected movie library service.</param>
/// <param name="tvShowLibraryService">Injected TV show library service.</param>
public VideoLibraryService(IMovieLibraryService movieLibraryService, ITvShowLibraryService tvShowLibraryService)
{
MovieLibraryService = movieLibraryService;
TvShowLibraryService = tvShowLibraryService;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
#endregion
}
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.ValueObjects;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Entities;
/// <summary>
/// Entity for an episode.
/// </summary>
[DebuggerDisplay("{Id}: {Title}")]
public sealed class Episode : Entity<EpisodeId>
{
}
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.ValueObjects;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Entities;
/// <summary>
/// Entity for a season.
/// </summary>
[DebuggerDisplay("{Id}: {Title}")]
public sealed class Season : Entity<SeasonId>
{
}
@@ -0,0 +1,15 @@
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Services
{
/// <summary>
/// Interface for the service for managing TV show libraries.
/// </summary>
public interface ITvShowLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the collection of TV shows in the library.
/// </summary>
public ICollection<TvShow> TvShows { get; }
#endregion
}
}
@@ -0,0 +1,17 @@
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.Services;
/// <summary>
/// Service for managing TV show libraries.
/// </summary>
public class TvShowLibraryService : ITvShowLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the collection of TV shows in the library.
/// </summary>
public ICollection<TvShow> TvShows
{
get { throw new NotImplementedException(); }
}
#endregion
}
@@ -0,0 +1,16 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.ValueObjects;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate;
/// <summary>
/// Entity for a TV show.
/// </summary>
[DebuggerDisplay("{Id}: {Title}")]
public sealed class TvShow : Entity<TvShowId>
{
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the Id of an episode.
/// </summary>
public sealed class EpisodeId : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
public Guid Value { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="EpisodeId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private EpisodeId(Guid value)
{
Value = value;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="EpisodeId"/> class.
/// </summary>
/// <returns>The created <see cref="EpisodeId"/> instance.</returns>
public static EpisodeId CreateUnique()
{
// TODO: enforce invariants
return new EpisodeId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="EpisodeId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="EpisodeId"/> instance.</param>
/// <returns>The created <see cref="EpisodeId"/> instance.</returns>
public static EpisodeId Create(Guid value)
{
// TODO: enforce invariants
return new EpisodeId(value);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
#endregion
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the Id of a season.
/// </summary>
public sealed class SeasonId : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
public Guid Value { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="SeasonId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private SeasonId(Guid value)
{
Value = value;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="SeasonId"/> class.
/// </summary>
/// <returns>The created <see cref="SeasonId"/> instance.</returns>
public static SeasonId CreateUnique()
{
// TODO: enforce invariants
return new SeasonId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="SeasonId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="SeasonId"/> instance.</param>
/// <returns>The created <see cref="SeasonId"/> instance.</returns>
public static SeasonId Create(Guid value)
{
// TODO: enforce invariants
return new SeasonId(value);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
#endregion
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
#endregion
namespace Lumina.Domain.Core.Aggregates.VideoLibrary.TvShowLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the Id of a TV show.
/// </summary>
public sealed class TvShowId : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
public Guid Value { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="TvShowId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private TvShowId(Guid value)
{
Value = value;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="TvShowId"/> class.
/// </summary>
/// <returns>The created <see cref="TvShowId"/> instance.</returns>
public static TvShowId CreateUnique()
{
// TODO: enforce invariants
return new TvShowId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="TvShowId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="TvShowId"/> instance.</param>
/// <returns>The created <see cref="TvShowId"/> instance.</returns>
public static TvShowId Create(Guid value)
{
// TODO: enforce invariants
return new TvShowId(value);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
#endregion
}
@@ -0,0 +1,336 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics;
using ErrorOr;
using Lumina.Domain.Common.Enums;
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.ValueObjects;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
/// <summary>
/// Entity for a book.
/// </summary>
[DebuggerDisplay("{Id}: {Title}")]
public sealed class Book : Entity<BookId>
{
#region ================================================================== FIELD MEMBERS ================================================================================
private readonly List<MediaContributorId> _contributors;
private readonly List<Rating> _ratings;
private readonly List<Isbn> _isbns;
#endregion
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the written content metadata of the book.
/// </summary>
public WrittenContentMetadata Metadata { get; private set; }
/// <summary>
/// Gets the format of the book (e.g., Hardcover, Paperback).
/// </summary>
public BookFormat Format { get; private set; }
/// <summary>
/// Gets the edition of the book, if applicable.
/// </summary>
public Optional<string> Edition { get; private set; }
/// <summary>
/// Gets the volume or book number in the series, if applicable.
/// </summary>
public Optional<int> VolumeNumber { get; private set; }
/// <summary>
/// Gets the series name, if the book is part of a series.
/// </summary>
public Optional<string> Series { get; private set; }
/// <summary>
/// Gets the ASIN (Amazon Standard Identification Number) of the book.
/// </summary>
public Optional<string> ASIN { get; private set; }
/// <summary>
/// Gets the Goodreads ID of the book.
/// </summary>
public Optional<string> GoodreadsId { get; private set; }
/// <summary>
/// Gets the Library of Congress Control Number (LCCN) of the book.
/// </summary>
public Optional<string> LCCN { get; private set; }
/// <summary>
/// Gets the OCLC Number (WorldCat identifier) of the book.
/// </summary>
public Optional<string> OCLCNumber { get; private set; }
/// <summary>
/// Gets the Open Library ID of the book.
/// </summary>
public Optional<string> OpenLibraryId { get; private set; }
/// <summary>
/// Gets the LibraryThing ID of the book.
/// </summary>
public Optional<string> LibraryThingId { get; private set; }
/// <summary>
/// Gets the Google Books ID of the book.
/// </summary>
public Optional<string> GoogleBooksId { get; private set; }
/// <summary>
/// Gets the Barnes & Noble ID of the book.
/// </summary>
public Optional<string> BarnesAndNobleId { get; private set; }
/// <summary>
/// Gets the Kobo ID of the book.
/// </summary>
public Optional<string> KoboId { get; private set; }
/// <summary>
/// Gets the Apple Books ID of the book.
/// </summary>
public Optional<string> AppleBooksId { get; private set; }
/// <summary>
/// Gets the list of ISBN (International Standard Book Number) of the book.
/// </summary>
public IReadOnlyCollection<Isbn> ISBNs
{
get { return _isbns.AsReadOnly(); }
}
/// <summary>
/// Gets the list of media contributors (actors, directors, etc) starring in this book.
/// </summary>
public IReadOnlyCollection<MediaContributorId> Contributors
{
get { return _contributors.AsReadOnly(); }
}
/// <summary>
/// Gets the list of ratings for this book.
/// </summary>
public IReadOnlyCollection<Rating> Ratings
{
get { return _ratings.AsReadOnly(); }
}
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="Book"/> class.
/// </summary>
/// <param name="id">The unique identifier of the book.</param>
/// <param name="metadata">The metadata of the book.</param>
/// <param name="format">The format of the book (e.g., Hardcover, Paperback).</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 name, if the book is part of a series.</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="koboId">The optional Kobo 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="ratings">The list of ratings for the book.</param>
public Book(
BookId id,
WrittenContentMetadata metadata,
BookFormat format,
Optional<string> edition,
Optional<int> volumeNumber,
Optional<string> 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> koboId,
Optional<string> appleBooksId,
List<Isbn> isbns,
List<MediaContributorId> contributors,
List<Rating> ratings) : base(id)
{
Id = id;
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;
KoboId = koboId;
AppleBooksId = appleBooksId;
_isbns = isbns;
_contributors = contributors;
_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
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="Book"/> class.
/// </summary>
/// <param name="metadata">The metadata of the book.</param>
/// <param name="format">The format of the book (e.g., Hardcover, Paperback).</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 name, if the book is part of a series.</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="koboId">The optional Kobo 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="ratings">The list of ratings for the book.</param>
/// <returns>The created <see cref="Book"/>.</returns>
public static ErrorOr<Book> Create(
WrittenContentMetadata metadata,
BookFormat format,
Optional<string> edition,
Optional<int> volumeNumber,
Optional<string> 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> koboId,
Optional<string> appleBooksId,
List<Isbn> isbns,
List<MediaContributorId> contributors,
List<Rating> ratings)
{
// TODO: enforce invariants
return new Book(
BookId.CreateUnique(),
metadata,
format,
edition,
volumeNumber,
series,
asin,
goodreadsId,
lccn,
oclcNumber,
openLibraryId,
libraryThingId,
googleBooksId,
barnesAndNobleId,
koboId,
appleBooksId,
isbns,
contributors,
ratings);
}
/// <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="metadata">The metadata of the book.</param>
/// <param name="format">The format of the book (e.g., Hardcover, Paperback).</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 name, if the book is part of a series.</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="koboId">The optional Kobo 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="ratings">The list of ratings for the book.</param>
/// <returns>The created <see cref="Book"/>.</returns>
public static ErrorOr<Book> Create(
BookId id,
WrittenContentMetadata metadata,
BookFormat format,
Optional<string> edition,
Optional<int> volumeNumber,
Optional<string> 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> koboId,
Optional<string> appleBooksId,
List<Isbn> isbns,
List<MediaContributorId> contributors,
List<Rating> ratings)
{
// TODO: enforce invariants
return new Book(
id,
metadata,
format,
edition,
volumeNumber,
series,
asin,
goodreadsId,
lccn,
oclcNumber,
openLibraryId,
libraryThingId,
googleBooksId,
barnesAndNobleId,
koboId,
appleBooksId,
isbns,
contributors,
ratings);
}
#endregion
}
@@ -0,0 +1,17 @@
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Services;
/// <summary>
/// Service for managing book libraries.
/// </summary>
public sealed class BookLibraryService : IBookLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the collection of books in the library.
/// </summary>
public ICollection<Book> Books
{
get { throw new NotImplementedException(); }
}
#endregion
}
@@ -0,0 +1,23 @@
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Services;
/// <summary>
/// Service for managing book libraries.
/// </summary>
public interface IBookLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the collection of books in the library.
/// </summary>
ICollection<Book> Books { get; }
// ICollection<BookSeries> Series { get; }
#endregion
// void AddBook(Book book);
// void RemoveBook(Guid bookId);
// void AddSeries(BookSeries series);
// void RemoveSeries(Guid seriesId);
// Book GetBook(Guid bookId);
// BookSeries GetSeries(Guid seriesId);
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the Id of a book.
/// </summary>
public sealed class BookId : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
public Guid Value { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="BookId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private BookId(Guid value)
{
Value = value;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="BookId"/> class.
/// </summary>
/// <returns>The created <see cref="BookId"/> instance.</returns>
public static BookId CreateUnique()
{
// TODO: enforce invariants
return new BookId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="BookId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="BookId"/> instance.</param>
/// <returns>The created <see cref="BookId"/> instance.</returns>
public static BookId Create(Guid value)
{
// TODO: enforce invariants
return new BookId(value);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
#endregion
}
@@ -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 library.
/// </summary>
public sealed class BookLibraryId : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
public Guid Value { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="BookLibraryId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private BookLibraryId(Guid value)
{
Value = value;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="BookLibraryId"/> class.
/// </summary>
/// <returns>The created <see cref="BookLibraryId"/> instance.</returns>
public static ErrorOr<BookLibraryId> CreateUnique()
{
// TODO: enforce invariants
return new BookLibraryId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="BookLibraryId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="BookLibraryId"/> instance.</param>
/// <returns>The created <see cref="BookLibraryId"/> instance.</returns>
public static ErrorOr<BookLibraryId> Create(Guid value)
{
// TODO: enforce invariants
return new BookLibraryId(value);
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
#endregion
}
@@ -0,0 +1,136 @@
#region ========================================================================= USING =====================================================================================
using System.Text.RegularExpressions;
using ErrorOr;
using Lumina.Domain.Common.Enums;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the ISBN of a book.
/// </summary>
public sealed class Isbn : ValueObject
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the value of the ISBN.
/// </summary>
public string Value { get; private set; }
/// <summary>
/// Gets the format of the ISBN.
/// </summary>
public IsbnFormat Format { get; private set; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="Isbn"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
/// <param name="format">The format of the ISBN representing this object.</param>
private Isbn(string value, IsbnFormat format)
{
Value = value;
Format = format;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Creates a new instance of the <see cref="Isbn"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
/// <param name="format">The format of the ISBN representing this object.</param>
/// <returns>The created <see cref="Isbn"/> instance.</returns>
public static ErrorOr<Isbn> Create(string value, IsbnFormat format)
{
// enforce invariants
if (string.IsNullOrWhiteSpace(value))
return Errors.WrittenContent.IsbnCannotBeEmpty;
// remove hyphens and spaces, for validation
string cleanedValue = Regex.Replace(value, @"[-\s]", string.Empty);
switch (format)
{
case IsbnFormat.Isbn10:
if (!IsValidIsbn10(cleanedValue))
return Errors.WrittenContent.InvalidIsbn10Format;
break;
case IsbnFormat.Isbn13:
if (!IsValidIsbn13(cleanedValue))
return Errors.WrittenContent.InvalidIsbn13Format;
break;
default:
return Errors.WrittenContent.UnknownIsbnFormat;
}
return new Isbn(value, format);
}
/// <summary>
/// Validates an ISBN-10 string.
/// </summary>
/// <param name="isbn">The ISBN-10 string to validate, without hyphens or spaces.</param>
/// <returns><see langword="true"/> if the ISBN-10 is valid, <see langword="false"/> otherwise.</returns>
public static bool IsValidIsbn10(string isbn)
{
// ISBN-10 must be exactly 10 characters long
if (isbn.Length != 10)
return false;
int sum = 0;
for (int i = 0; i < 9; i++)
{
// each of the first 9 characters must be a digit
if (!char.IsDigit(isbn[i]))
return false;
// calculate the sum: each digit is multiplied by its position (10 to 2) and added
sum += (10 - i) * (isbn[i] - '0');
}
// check the last character, which can be a digit or 'X'
char lastChar = isbn[9];
if (lastChar == 'X' || lastChar == 'x')
sum += 10;
else if (char.IsDigit(lastChar))
sum += lastChar - '0';
else
return false;
// the ISBN-10 is valid if the sum is divisible by 11
return sum % 11 == 0;
}
/// <summary>
/// Validates an ISBN-13 string.
/// </summary>
/// <param name="isbn">The ISBN-13 string to validate, without hyphens or spaces.</param>
/// <returns><see langword="true"/> if the ISBN-13 is valid, <see langword="false"/> otherwise.</returns>
public static bool IsValidIsbn13(string isbn)
{
// ISBN-13 must be exactly 13 characters long
if (isbn.Length != 13)
return false;
int sum = 0;
for (int i = 0; i < 12; i++)
{
// each of the first 12 characters must be a digit
if (!char.IsDigit(isbn[i]))
return false;
// calculate the sum: alternate digits are multiplied by 3
sum += (i % 2 == 0) ? isbn[i] - '0' : 3 * (isbn[i] - '0');
}
// calculate the check digit
int checkDigit = 10 - (sum % 10);
if (checkDigit == 10)
checkDigit = 0;
// the ISBN-13 is valid if the calculated check digit matches the last digit
return checkDigit == (isbn[12] - '0');
}
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
yield return Format;
}
#endregion
}
@@ -0,0 +1,69 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the metadata of a written media element.
/// </summary>
[DebuggerDisplay("{Title}")]
public class WrittenContentMetadata : BaseMetadata
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the publisher of the written content.
/// </summary>
public Optional<string> Publisher { get; }
/// <summary>
/// Gets the number of pages in the written content.
/// </summary>
public Optional<int> PageCount { get; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes 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="release">The release information of the written content.</param>
/// <param name="description">The description 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(
string title,
Optional<string> originalTitle,
ReleaseInfo release,
Optional<string> description,
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)
{
Publisher = publisher;
PageCount = pageCount;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
/// <inheritdoc/>
public override IEnumerable<object> GetEqualityComponents()
{
foreach (var component in base.GetEqualityComponents())
yield return component;
yield return Publisher;
yield return PageCount;
}
#endregion
}
@@ -0,0 +1,18 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Services;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.Services;
/// <summary>
/// Interface for the service for managing written content.
/// </summary>
public interface IWrittenContentLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the service for managing book libraries.
/// </summary>
public IBookLibraryService BookLibraryService { get; }
#endregion
}
@@ -0,0 +1,32 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.Services;
#endregion
namespace Lumina.Domain.Core.Aggregates.WrittenContentLibrary.Services;
/// <summary>
/// Service for managing written content.
/// </summary>
public class WrittenContentLibraryService : IWrittenContentLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the service for managing book libraries.
/// </summary>
public IBookLibraryService BookLibraryService { get; private set; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="WrittenContentLibraryService"/> class.
/// </summary>
/// <param name="bookLibraryService">Injected book library service.</param>
public WrittenContentLibraryService(IBookLibraryService bookLibraryService)
{
BookLibraryService = bookLibraryService;
}
#endregion
#region ===================================================================== METHODS ===================================================================================
#endregion
}
@@ -0,0 +1,29 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.Aggregates.VideoLibrary.Services;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.Services;
#endregion
namespace Lumina.Domain.Core.Services;
/// <summary>
/// Interface for the service for managing a media library.
/// </summary>
public interface IMediaLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the service for managing a audio library.
/// </summary>
//public IAudioLibraryService AudioLibraryService { get; }
/// <summary>
/// Gets the service for managing a video library.
/// </summary>
public IVideoLibraryService VideoLibraryService { get; }
/// <summary>
/// Gets the service for managing a written content library.
/// </summary>
public IWrittenContentLibraryService WrittenContentLibraryService { get; }
#endregion
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.Aggregates.VideoLibrary.Services;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.Services;
#endregion
namespace Lumina.Domain.Core.Services;
/// <summary>
/// Service for managing media libraries.
/// </summary>
public class MediaLibraryService : IMediaLibraryService
{
#region ==================================================================== PROPERTIES =================================================================================
/// <summary>
/// Gets the service for managing a video library.
/// </summary>
public IVideoLibraryService VideoLibraryService { get; private set; }
/// <summary>
/// Gets the service for managing a written content library.
/// </summary>
public IWrittenContentLibraryService WrittenContentLibraryService { get; private set; }
#endregion
#region ====================================================================== CTOR =====================================================================================
/// <summary>
/// Initializes a new instance of the <see cref="MediaLibraryService"/> class.
/// </summary>
/// <param name="videoLibraryService">Injected video library service.</param>
/// <param name="writtenContentLibraryService">Injected written content library service.</param>
public MediaLibraryService(IVideoLibraryService videoLibraryService, IWrittenContentLibraryService writtenContentLibraryService)
{
VideoLibraryService = videoLibraryService;
WrittenContentLibraryService = writtenContentLibraryService;
}
#endregion
}