From 12de2b27f0bd25409246f9c4daadaee10ab71c7a Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Sun, 18 Aug 2024 20:24:01 +0300 Subject: [PATCH] Adds first value objects of the domain --- docs/technical/Aggregates.FileManagement.md | 51 ++++++++ docs/technical/Common.Metadata.md | 100 ++++++++++++++ .../Common/Enums/MediaContributorRole.cs | 12 ++ .../Common/Enums/RatingSource.cs | 13 ++ .../Common/Errors/Errors.FileManagement.cs | 22 ++++ .../Common/Errors/Errors.Metadata.cs | 28 ++++ .../Common/Models/Metadata/BaseMetadata.cs | 58 --------- .../ValueObjects/Media/MediaContributor.cs | 54 ++++++++ .../Common/ValueObjects/Media/PersonId.cs | 55 ++++++++ .../ValueObjects/Metadata/BaseMetadata.cs | 98 ++++++++++++++ .../Common/ValueObjects/Metadata/Genre.cs | 63 +++++++++ .../ValueObjects/Metadata/LanguageInfo.cs | 89 +++++++++++++ .../Common/ValueObjects/Metadata/Rating.cs | 108 +++++++++++++++ .../ValueObjects/Metadata/ReleaseInfo.cs | 109 ++++++++++++++++ .../Common/ValueObjects/Metadata/Tag.cs | 63 +++++++++ .../ValueObjects/Metadata/VideoMetadata.cs | 123 ++++++++++++++++++ .../ValueObjects/FileInfo.cs | 92 +++++++++++++ .../ValueObjects/StreamInfo.cs | 123 ++++++++++++++++++ src/Lumina.Domain/Lumina.Domain.csproj | 4 + 19 files changed, 1207 insertions(+), 58 deletions(-) create mode 100644 docs/technical/Aggregates.FileManagement.md create mode 100644 docs/technical/Common.Metadata.md create mode 100644 src/Lumina.Domain/Common/Enums/MediaContributorRole.cs create mode 100644 src/Lumina.Domain/Common/Enums/RatingSource.cs create mode 100644 src/Lumina.Domain/Common/Errors/Errors.FileManagement.cs create mode 100644 src/Lumina.Domain/Common/Errors/Errors.Metadata.cs delete mode 100644 src/Lumina.Domain/Common/Models/Metadata/BaseMetadata.cs create mode 100644 src/Lumina.Domain/Common/ValueObjects/Media/MediaContributor.cs create mode 100644 src/Lumina.Domain/Common/ValueObjects/Media/PersonId.cs create mode 100644 src/Lumina.Domain/Common/ValueObjects/Metadata/BaseMetadata.cs create mode 100644 src/Lumina.Domain/Common/ValueObjects/Metadata/Genre.cs create mode 100644 src/Lumina.Domain/Common/ValueObjects/Metadata/LanguageInfo.cs create mode 100644 src/Lumina.Domain/Common/ValueObjects/Metadata/Rating.cs create mode 100644 src/Lumina.Domain/Common/ValueObjects/Metadata/ReleaseInfo.cs create mode 100644 src/Lumina.Domain/Common/ValueObjects/Metadata/Tag.cs create mode 100644 src/Lumina.Domain/Common/ValueObjects/Metadata/VideoMetadata.cs create mode 100644 src/Lumina.Domain/FileManagementAggregate/ValueObjects/FileInfo.cs create mode 100644 src/Lumina.Domain/FileManagementAggregate/ValueObjects/StreamInfo.cs diff --git a/docs/technical/Aggregates.FileManagement.md b/docs/technical/Aggregates.FileManagement.md new file mode 100644 index 00000000..afbe293c --- /dev/null +++ b/docs/technical/Aggregates.FileManagement.md @@ -0,0 +1,51 @@ +- [Lumina Domain](#lumina-domain) + - [File Management Aggregate](#file-management-aggregate) + - [File Info](#file-info) + - [Stream Info](#stream-info) + +# [Lumina Domain](#lumina-domain) + +## [File Management Aggregate](#file-management-aggregate) + +### [File Info](#file-info) + +```csharp +class FileInfo +{ + ErrorOr Create(string path, string fileExtension, long sizeInBytes, DateTime lastModified, Optional mimeType); +} +``` + +```json +{ + "path": "/media/movies/The Lord of the Rings - The Fellowship of the Ring.mkw", + "fileExtension": "mkv", + "sizeInBytes": 15797942704, + "lastModified": "2024-08-18", + "mimeType": "video/x-matroska" +} +``` + +### [Stream Info](#stream-info) + +```csharp +class StreamInfo +{ + ErrorOr Create(string streamId, string mimeType, int bitrate, string codec, + Optional resolution = default, Optional frameRate = default, + Optional sampleRate = default, Optional channels = default); +} +``` + +```json +{ + "streamId": "stream_001", + "mimeType": "video/mp4", + "bitrate": 5000000, + "codec": "h264", + "resolution": "1920x1080", + "frameRate": 29.97, + "sampleRate": 48000, + "channels": 2 +} +``` \ No newline at end of file diff --git a/docs/technical/Common.Metadata.md b/docs/technical/Common.Metadata.md new file mode 100644 index 00000000..8b6e4a3c --- /dev/null +++ b/docs/technical/Common.Metadata.md @@ -0,0 +1,100 @@ +- [Lumina Domain](#lumina-domain) + - [Common](#common) + - [Metadata](#metadata) + - [Genre](#genre) + - [Tag](#tag) + - [Rating](#rating) + - [Release Info](#release-info) + - [Language Info](#language-info) + +# [Lumina Domain](#lumina-domain) + +## [Common](#common) + +### [Metadata](#metadata) + +#### [Genre](#genre) + +```csharp +class Genre +{ + ErrorOr Create(string name); +} +``` + +```json +{ + "name": "SF" +} +``` + +#### [Tag](#tag) + +```csharp +class Tag +{ + ErrorOr Create(string name); +} +``` + +```json +{ + "name": "artificial intelligence" +} +``` + +#### [Rating](#rating) + +```csharp +class Rating +{ + ErrorOr Create(decimal value, decimal maxValue, Optional source = default, Optional voteCount = default); +} +``` + +```json +{ + "value": 9.3, + "maxValue": 10.0, + "source": "Imdb", + "voteCount": 84 +} +``` + +#### [Release Info](#release-info) + +```csharp +class ReleaseInfo +{ + ErrorOr Create(Optional originalReleaseDate, Optional originalReleaseYear, + Optional reReleaseDate, Optional reReleaseYear, Optional releaseCountry, Optional releaseVersion); +} +``` + +```json +{ + "originalReleaseDate": "2024-08-18", + "originalReleaseYear": 2024, + "reReleaseDate": "2024-08-18", + "reReleaseYear": 2024, + "releaseCountry": "JP", + "releaseVersion": "director's cut" +} +``` + +#### [Language Info](#language-info) + +```csharp +class LanguageInfo +{ + ErrorOr Create(string languageCode, string languageName, Optional nativeName); +} +``` + +```json +{ + "languageCode": "FR", + "languageName": "French", + "nativeName": "Française", +} +``` \ No newline at end of file diff --git a/src/Lumina.Domain/Common/Enums/MediaContributorRole.cs b/src/Lumina.Domain/Common/Enums/MediaContributorRole.cs new file mode 100644 index 00000000..87f2e1c6 --- /dev/null +++ b/src/Lumina.Domain/Common/Enums/MediaContributorRole.cs @@ -0,0 +1,12 @@ +namespace Lumina.Domain.Common.Enums; + +/// +/// Enumeration for the roles of media contributors. +/// +public enum MediaContributorRole +{ + Actor, + Director, + Singer, + Author +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/Enums/RatingSource.cs b/src/Lumina.Domain/Common/Enums/RatingSource.cs new file mode 100644 index 00000000..2464671f --- /dev/null +++ b/src/Lumina.Domain/Common/Enums/RatingSource.cs @@ -0,0 +1,13 @@ +namespace Lumina.Domain.Common.Enums; + +/// +/// Enumeration for the ratings sources. +/// +public enum RatingSource +{ + User, + Imdb, + TheTvDb, + TheMovieDb, + RottenTomatoes, +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/Errors/Errors.FileManagement.cs b/src/Lumina.Domain/Common/Errors/Errors.FileManagement.cs new file mode 100644 index 00000000..3cda1556 --- /dev/null +++ b/src/Lumina.Domain/Common/Errors/Errors.FileManagement.cs @@ -0,0 +1,22 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +#endregion + +namespace Lumina.Domain.Common.Errors; + +/// +/// File management error types. +/// +public static partial class Errors +{ + public static class FileManagement + { + #region ==================================================================== PROPERTIES ================================================================================= + public static Error PathCannotBeEmpty => Error.Validation(nameof(PathCannotBeEmpty)); + public static Error ExtensionCannotBeEmpty => Error.Validation(nameof(ExtensionCannotBeEmpty)); + public static Error StreamIdCannotBeEmpty => Error.Validation(nameof(StreamIdCannotBeEmpty)); + public static Error CodecCannotBeEmpty => Error.Validation(nameof(CodecCannotBeEmpty)); + public static Error BitrateMustBeAPositiveNumber => Error.Validation(nameof(BitrateMustBeAPositiveNumber)); + #endregion + } +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/Errors/Errors.Metadata.cs b/src/Lumina.Domain/Common/Errors/Errors.Metadata.cs new file mode 100644 index 00000000..a6f72dbf --- /dev/null +++ b/src/Lumina.Domain/Common/Errors/Errors.Metadata.cs @@ -0,0 +1,28 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +#endregion + +namespace Lumina.Domain.Common.Errors; + +/// +/// Metadata error types. +/// +public static partial class Errors +{ + public static class Metadata + { + #region ==================================================================== PROPERTIES ================================================================================= + public static Error TagCannotBeEmpty => Error.Validation(nameof(TagCannotBeEmpty)); + public static Error GenreCannotBeEmpty => Error.Validation(nameof(GenreCannotBeEmpty)); + public static Error OriginalReleaseDateAndYearMustMatch => Error.Validation(nameof(OriginalReleaseDateAndYearMustMatch)); + public static Error ReReleaseDateAndYearMustMatch => Error.Validation(nameof(ReReleaseDateAndYearMustMatch)); + public static Error ReReleaseDateCannotBeEarlierThanOriginalReleaseDate => Error.Validation(nameof(ReReleaseDateCannotBeEarlierThanOriginalReleaseDate)); + public static Error ReReleaseYearCannotBeEarlierThanOriginalReleaseYear => Error.Validation(nameof(ReReleaseYearCannotBeEarlierThanOriginalReleaseYear)); + public static Error RatingMustBePositive => Error.Validation(nameof(RatingMustBePositive)); + public static Error RatingValueCannotBeGreaterThanMaxValue => Error.Validation(nameof(RatingValueCannotBeGreaterThanMaxValue)); + public static Error LanguageCodeCannotBeEmpty => Error.Validation(nameof(LanguageCodeCannotBeEmpty)); + public static Error LanguageNameCannotBeEmpty => Error.Validation(nameof(LanguageNameCannotBeEmpty)); + public static Error InvalidIsoCode => Error.Validation(nameof(InvalidIsoCode)); + #endregion + } +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/Models/Metadata/BaseMetadata.cs b/src/Lumina.Domain/Common/Models/Metadata/BaseMetadata.cs deleted file mode 100644 index 14afd1ed..00000000 --- a/src/Lumina.Domain/Common/Models/Metadata/BaseMetadata.cs +++ /dev/null @@ -1,58 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Domain.Common.Models.Core; -using Lumina.Domain.Common.Primitives; -#endregion - -namespace Lumina.Domain.Common.Models.Metadata; - -/// -/// Base class for all metadata-related value objects. -/// -public class BaseMetadata : ValueObject -{ - #region ==================================================================== PROPERTIES ================================================================================= - public string Title { get; } - public Optional Description { get; } - public Optional ReleaseDate { get; } - public IReadOnlyList Tags { get; } - public IReadOnlyList Genres { get; } - public Optional Language { get; } - #endregion - - #region ====================================================================== CTOR ===================================================================================== - /// - /// Overload C-tor. - /// - /// The title of the element to which this metadata object belongs to. - /// The optional release date of the element to which this metadata object belongs to. - /// The optional description of the element to which this metadata object belongs to. - /// The list of genres of the element to which this metadata object belongs to. - /// The list of tags of the element to which this metadata object belongs to. - /// The optional language of the element to which this metadata object belongs to. - /// - public BaseMetadata(string title, Optional releaseDate, Optional description, IEnumerable? genres, IEnumerable? tags, Optional language) - { - Title = title ?? throw new ArgumentNullException(nameof(title)); - ReleaseDate = releaseDate; - Description = description; - Genres = genres?.ToList().AsReadOnly() ?? new List().AsReadOnly(); - Tags = tags?.ToList().AsReadOnly() ?? new List().AsReadOnly(); - Language = language; - } - #endregion - - #region ===================================================================== METHODS =================================================================================== - /// - public override IEnumerable GetEqualityComponents() - { - yield return Title; - yield return ReleaseDate; - yield return Description; - foreach (var genre in Genres) - yield return genre; - foreach (var tag in Tags) - yield return tag; - yield return Language; - } - #endregion -} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/ValueObjects/Media/MediaContributor.cs b/src/Lumina.Domain/Common/ValueObjects/Media/MediaContributor.cs new file mode 100644 index 00000000..5d5731af --- /dev/null +++ b/src/Lumina.Domain/Common/ValueObjects/Media/MediaContributor.cs @@ -0,0 +1,54 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Domain.Common.Enums; +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; +#endregion + +namespace Lumina.Domain.Common.ValueObjects.Media; + +/// +/// Value Object for a contributor of a media element. +/// +public sealed class MediaContributor : ValueObject +{ + #region ==================================================================== PROPERTIES ================================================================================= + public PersonId PersonId { get; } + public Optional Role { get; } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Overload C-tor. + /// + /// The id of the person represented by this object. + /// The role of the person represented by this object. + private MediaContributor(PersonId personId, Optional role) + { + Role = role; + PersonId = personId; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of . + /// + /// The id of the person represented by this object. + /// The role of the person represented by this object. + /// + /// An containing either a successfully created or an error message. + /// + public static ErrorOr Create(PersonId personId, Optional role) + { + return new MediaContributor(personId, role); + } + + /// + public override IEnumerable GetEqualityComponents() + { + yield return PersonId; + yield return Role; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/ValueObjects/Media/PersonId.cs b/src/Lumina.Domain/Common/ValueObjects/Media/PersonId.cs new file mode 100644 index 00000000..52b51af2 --- /dev/null +++ b/src/Lumina.Domain/Common/ValueObjects/Media/PersonId.cs @@ -0,0 +1,55 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Models.Core; +#endregion + +namespace Lumina.Domain.Common.ValueObjects.Media; + +/// +/// Value Object for the Id of a person. +/// +public sealed class PersonId : ValueObject +{ + #region ==================================================================== PROPERTIES ================================================================================= + public Guid Value { get; } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Overload C-tor. + /// + /// The value representing this object. + private PersonId(Guid value) + { + Value = value; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of . + /// + /// The created instance. + public static PersonId CreateUnique() + { + // TODO: enforce invariants + return new PersonId(Guid.NewGuid()); + } + + /// + /// Creates a new instance of from . + /// + /// The value used to create the instance. + /// The created instance. + public static PersonId Create(Guid value) + { + // TODO: enforce invariants + return new PersonId(value); + } + + /// + public override IEnumerable GetEqualityComponents() + { + yield return Value; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/ValueObjects/Metadata/BaseMetadata.cs b/src/Lumina.Domain/Common/ValueObjects/Metadata/BaseMetadata.cs new file mode 100644 index 00000000..004a49b6 --- /dev/null +++ b/src/Lumina.Domain/Common/ValueObjects/Metadata/BaseMetadata.cs @@ -0,0 +1,98 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; +#endregion + +namespace Lumina.Domain.Common.ValueObjects.Metadata; + +/// +/// Base template for all metadata-related value objects. +/// +public abstract class BaseMetadata : ValueObject +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the title of the media item. + /// + public string Title { get; } + + /// + /// Gets the original title of the media item. + /// + public Optional OriginalTitle { get; } + + /// + /// Gets the optional description of the media item. + /// + public Optional Description { get; } + + /// + /// Gets the release information of the media item. + /// + public ReleaseInfo ReleaseInfo { get; } + + /// + /// Gets the list of tags associated with the media item. + /// + public IReadOnlyList Tags { get; } + + /// + /// Gets the list of genres associated with the media item. + /// + public IReadOnlyList Genres { get; } + + /// + /// Gets the optional language of the media item. + /// + public Optional Language { get; } + + /// + /// Gets the optional original language of the media item. + /// + public Optional OriginalLanguage { get; } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Overload C-tor. + /// + /// The title of the element to which this metadata object belongs to. + /// The optional original title of the element to which this metadata object belongs to. + /// The optional release information of the media item. + /// The optional description of the element to which this metadata object belongs to. + /// The list of genres of the element to which this metadata object belongs to. + /// The list of tags of the element to which this metadata object belongs to. + /// The optional language of the element to which this metadata object belongs to. + /// The optional original language of the element to which this metadata object belongs to. + /// Thrown when the value is + protected BaseMetadata(string title, Optional originalTitle, ReleaseInfo releaseInfo, Optional description, + IEnumerable? genres, IEnumerable? tags, Optional language, Optional originalLanguage) + { + Title = title ?? throw new ArgumentNullException(nameof(title)); + OriginalTitle = originalTitle; + ReleaseInfo = releaseInfo; + Description = description; + Genres = genres?.ToList().AsReadOnly() ?? new List().AsReadOnly(); + Tags = tags?.ToList().AsReadOnly() ?? new List().AsReadOnly(); + Language = language; + OriginalLanguage = originalLanguage; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + public override IEnumerable GetEqualityComponents() + { + yield return Title; + yield return OriginalTitle; + yield return ReleaseInfo; + yield return Description; + foreach (var genre in Genres) + yield return genre; + foreach (var tag in Tags) + yield return tag; + yield return Language; + yield return OriginalLanguage; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/ValueObjects/Metadata/Genre.cs b/src/Lumina.Domain/Common/ValueObjects/Metadata/Genre.cs new file mode 100644 index 00000000..72d364e0 --- /dev/null +++ b/src/Lumina.Domain/Common/ValueObjects/Metadata/Genre.cs @@ -0,0 +1,63 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Domain.Common.Models.Core; +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.Common.ValueObjects.Metadata; + +/// +/// Value Object for the genres of a media element. +/// +[DebuggerDisplay("{Name}")] +public class Genre : ValueObject +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the name of the genre element of the media item. + /// + public string Name { get; } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Overload C-tor. + /// + /// The value representing this object. + private Genre(string name) + { + Name = name.Trim(); + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of . + /// + /// The value of the genre. + /// + /// An containing either a successfully created or an error message. + /// + public static ErrorOr Create(string name) + { + if (string.IsNullOrWhiteSpace(name)) + return Errors.Errors.Metadata.GenreCannotBeEmpty; + return new Genre(name); + } + + /// + public override IEnumerable GetEqualityComponents() + { + yield return Name; + } + + /// + /// Customized ToString() method. + /// + /// Custom string value showing relevant data for current class. + public override string ToString() + { + return Name; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/ValueObjects/Metadata/LanguageInfo.cs b/src/Lumina.Domain/Common/ValueObjects/Metadata/LanguageInfo.cs new file mode 100644 index 00000000..a51ac8e4 --- /dev/null +++ b/src/Lumina.Domain/Common/ValueObjects/Metadata/LanguageInfo.cs @@ -0,0 +1,89 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Domain.Common.Enums; +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.Common.ValueObjects.Metadata; + +/// +/// Value Object for the language used in a media element. +/// +[DebuggerDisplay("{LanguageCode}")] +public class LanguageInfo : ValueObject +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the ISO 639-1 two-letter language code. + /// + public string LanguageCode { get; } + + /// + /// Gets the full name of the language in English. + /// + public string LanguageName { get; } + + /// + /// Gets an optional native name of the language. + /// + public Optional NativeName { get; } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Overload C-tor. + /// + /// The ISO 639-1 two-letter language code. + /// The full name of the language in English. + /// The optional native name of the language. + /// Thrown if languageCode or languageName is null. + /// Thrown if languageCode is not a valid ISO 639-1 code. + private LanguageInfo(string languageCode, string languageName, Optional nativeName) + { + LanguageCode = languageCode.ToLowerInvariant(); + LanguageName = languageName; + NativeName = nativeName; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of . + /// + /// The ISO 639-1 two-letter language code. + /// The full name of the language in English. + /// The optional native name of the language. + /// + /// An containing either a successfully created or an error message. + /// + public static ErrorOr Create(string languageCode, string languageName, Optional nativeName) + { + if (string.IsNullOrWhiteSpace(languageCode)) + return Errors.Errors.Metadata.LanguageCodeCannotBeEmpty; + if (string.IsNullOrWhiteSpace(languageName)) + return Errors.Errors.Metadata.LanguageNameCannotBeEmpty; + if (languageCode.Length != 2) + return Errors.Errors.Metadata.InvalidIsoCode; + return new LanguageInfo(languageCode, languageName, nativeName); + } + + /// + public override IEnumerable GetEqualityComponents() + { + yield return LanguageCode; + yield return LanguageName; + yield return NativeName; + } + + /// + /// Customized ToString() method. + /// + /// Custom string value showing relevant data for current class. + public override string ToString() + { + return $"{LanguageCode} - {LanguageName}"; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/ValueObjects/Metadata/Rating.cs b/src/Lumina.Domain/Common/ValueObjects/Metadata/Rating.cs new file mode 100644 index 00000000..9b760305 --- /dev/null +++ b/src/Lumina.Domain/Common/ValueObjects/Metadata/Rating.cs @@ -0,0 +1,108 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Domain.Common.Enums; +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.Common.ValueObjects.Metadata; + +/// +/// Value Object for the rating of a media element. +/// +[DebuggerDisplay("{Value}/{MaxValue}")] +public class Rating : ValueObject +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the numeric value of the rating. + /// + public decimal Value { get; } + + /// + /// Gets the maximum possible rating value. + /// + public decimal MaxValue { get; } + + /// + /// Gets the optional source of the rating (e.g., "IMDB", "Rotten Tomatoes"). + /// + public Optional Source { get; } + + /// + /// Gets the optional number of votes or reviews this rating is based on. + /// + public Optional VoteCount { get; } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Overload C-tor. + /// + /// The numeric value of the rating. + /// The maximum possible rating value. + /// The optional source of the rating. + /// The optional number of votes or reviews. + private Rating(decimal value, decimal maxValue, Optional source = default, Optional voteCount = default) + { + Value = value; + MaxValue = maxValue; + Source = source; + VoteCount = voteCount; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of . + /// + /// The numeric value of the rating. + /// The maximum possible rating value. + /// The optional source of the rating. + /// The optional number of votes or reviews. + /// + /// An containing either a successfully created or an error message. + /// + public static ErrorOr Create(decimal value, decimal maxValue, Optional source = default, Optional voteCount = default) + { + 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); + } + + /// + /// Returns the rating as a percentage. + /// + /// The rating value as a percentage of the maximum value. + public decimal AsPercentage() + { + return (Value / MaxValue) * 100; + } + + /// + public override IEnumerable GetEqualityComponents() + { + yield return Value; + yield return MaxValue; + yield return Source; + yield return VoteCount; + } + + /// + /// Customized ToString() method. + /// + /// Custom string value showing relevant data for current class. + public override string ToString() + { + string baseString = $"{Value}/{MaxValue}"; + if (Source.HasValue) + baseString += $" ({Source.Value})"; + if (VoteCount.HasValue) + baseString += $" [{VoteCount.Value} votes]"; + return baseString; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/ValueObjects/Metadata/ReleaseInfo.cs b/src/Lumina.Domain/Common/ValueObjects/Metadata/ReleaseInfo.cs new file mode 100644 index 00000000..7024c9f7 --- /dev/null +++ b/src/Lumina.Domain/Common/ValueObjects/Metadata/ReleaseInfo.cs @@ -0,0 +1,109 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.Common.ValueObjects.Metadata; + +/// +/// Value Object for the release info of a media element. +/// +[DebuggerDisplay("{ReleaseYear}")] +public class ReleaseInfo : ValueObject +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the optional original release date of the media item. + /// + public Optional OriginalReleaseDate { get; } + + /// + /// Gets the optional original release year of the media item. + /// This is useful when only the year of original release is known. + /// + public Optional OriginalReleaseYear { get; } + + /// + /// Gets the optional re-release or reissue date of the media item. + /// + public Optional ReReleaseDate { get; } + + /// + /// Gets the optional re-release or reissue year of the media item. + /// + public Optional ReReleaseYear { get; } + + /// + /// Gets the optional country or region of release. + /// + public Optional ReleaseCountry { get; } + + /// + /// Gets the optional release version or edition. (e.g. "Original", "Director's Cut", "2.0") + /// + public Optional ReleaseVersion { get; } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Overload C-tor. + /// + /// The optional original release date of the media item. + /// The optional original release year of the media item. + /// The optional re-release date of the media item. + /// The optional re-release year of the media item. + /// The optional country or region of release. + /// The optional release version or edition. + private ReleaseInfo(Optional originalReleaseDate, Optional originalReleaseYear, + Optional reReleaseDate, Optional reReleaseYear, Optional releaseCountry, Optional releaseVersion) + { + OriginalReleaseDate = originalReleaseDate; + OriginalReleaseYear = originalReleaseYear; + ReReleaseDate = reReleaseDate; + ReReleaseYear = reReleaseYear; + ReleaseCountry = releaseCountry; + ReleaseVersion = releaseVersion; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of . + /// + /// The optional original release date of the media item. + /// The optional original release year of the media item. + /// The optional re-release date of the media item. + /// The optional re-release year of the media item. + /// The optional country or region of release. + /// The optional release version or edition. + /// + /// An containing either a successfully created or an error message. + /// + public static ErrorOr Create(Optional originalReleaseDate, Optional originalReleaseYear, + Optional reReleaseDate, Optional reReleaseYear, Optional releaseCountry, Optional releaseVersion) + { + if (originalReleaseDate.HasValue && originalReleaseYear.HasValue && originalReleaseDate.Value.Year != originalReleaseYear.Value) + return Errors.Errors.Metadata.OriginalReleaseDateAndYearMustMatch; + if (reReleaseDate.HasValue && reReleaseYear.HasValue && reReleaseDate.Value.Year != reReleaseYear.Value) + return Errors.Errors.Metadata.ReReleaseDateAndYearMustMatch; + if (originalReleaseDate.HasValue && reReleaseDate.HasValue && originalReleaseDate.Value > reReleaseDate.Value) + return Errors.Errors.Metadata.ReReleaseDateCannotBeEarlierThanOriginalReleaseDate; + if (originalReleaseYear.HasValue && reReleaseYear.HasValue && originalReleaseYear.Value > reReleaseYear.Value) + return Errors.Errors.Metadata.ReReleaseYearCannotBeEarlierThanOriginalReleaseYear; + return new ReleaseInfo(originalReleaseDate, originalReleaseYear, reReleaseDate, reReleaseYear, releaseCountry, releaseVersion); + } + + /// + public override IEnumerable GetEqualityComponents() + { + yield return OriginalReleaseDate; + yield return OriginalReleaseYear; + yield return ReReleaseDate; + yield return ReReleaseYear; + yield return ReleaseCountry; + yield return ReleaseVersion; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/ValueObjects/Metadata/Tag.cs b/src/Lumina.Domain/Common/ValueObjects/Metadata/Tag.cs new file mode 100644 index 00000000..1614ca87 --- /dev/null +++ b/src/Lumina.Domain/Common/ValueObjects/Metadata/Tag.cs @@ -0,0 +1,63 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Domain.Common.Models.Core; +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.Common.ValueObjects.Metadata; + +/// +/// Value Object for the tags of a media element. +/// +[DebuggerDisplay("{Name}")] +public class Tag : ValueObject +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the name of the tag element of the media item. + /// + public string Name { get; } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Overload C-tor. + /// + /// The value representing this object. + private Tag(string name) + { + Name = name.Trim(); + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of . + /// + /// The value of the tag. + /// + /// An containing either a successfully created or an error message. + /// + public static ErrorOr Create(string name) + { + if (string.IsNullOrWhiteSpace(name)) + return Errors.Errors.Metadata.TagCannotBeEmpty; + return new Tag(name); + } + + /// + public override IEnumerable GetEqualityComponents() + { + yield return Name; + } + + /// + /// Customized ToString() method. + /// + /// Custom string value showing relevant data for current class. + public override string ToString() + { + return Name; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/Common/ValueObjects/Metadata/VideoMetadata.cs b/src/Lumina.Domain/Common/ValueObjects/Metadata/VideoMetadata.cs new file mode 100644 index 00000000..ff7df349 --- /dev/null +++ b/src/Lumina.Domain/Common/ValueObjects/Metadata/VideoMetadata.cs @@ -0,0 +1,123 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Common.ValueObjects.Media; +using System.Diagnostics; +#endregion + +namespace Lumina.Domain.Common.ValueObjects.Metadata; + +/// +/// Value Object for the rating of a media element. +/// +[DebuggerDisplay("{Value}/{MaxValue}")] +public class VideoMetadata : BaseMetadata +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the duration of the video in seconds. + /// + public int DurationInSeconds { get; } + + /// + /// Gets the resolution of the video. + /// + public string Resolution { get; } + + /// + /// Gets the frame rate of the video. + /// + public Optional FrameRate { get; } + + /// + /// Gets the video codec used. + /// + public Optional VideoCodec { get; } + + /// + /// Gets the audio codec used. + /// + public Optional AudioCodec { get; } + + /// + /// Gets the list of actors starring in this video. + /// + public IReadOnlyList Contributors { get; } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Overload C-tor. + /// + /// The title of the video. + /// The optional original title of the video. + /// The duration of the video in seconds. + /// The resolution of the video. + /// The release information of the video. + /// The optional description of the video. + /// The language of the video. + /// The optional original language of the video. + /// The optional frame rate of the video. + /// The optional video codec used. + /// The optional audio codec used. + /// The genres of the video. + /// The tags associated with the video. + /// The list of contributors for this video. + private VideoMetadata(string title, Optional originalTitle, int durationInSeconds, string resolution, ReleaseInfo release, Optional description, + Optional language, Optional originalLanguage, Optional frameRate, Optional videoCodec, Optional audioCodec, + IEnumerable? genres = null, IEnumerable? tags = null, IEnumerable? contributors = null) + : base(title, originalTitle, release, description, genres, tags, language, originalLanguage) + { + DurationInSeconds = durationInSeconds; + Resolution = resolution ?? throw new ArgumentNullException(nameof(resolution)); + FrameRate = frameRate; + VideoCodec = videoCodec; + AudioCodec = audioCodec; + Contributors = contributors?.ToList().AsReadOnly() ?? new List().AsReadOnly(); + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of . + /// + /// The title of the video. + /// The optional original title of the video. + /// The duration of the video in seconds. + /// The resolution of the video. + /// The release information of the video. + /// The optional description of the video. + /// The language of the video. + /// The optional original language of the video. + /// The optional frame rate of the video. + /// The optional video codec used. + /// The optional audio codec used. + /// The genres of the video. + /// The tags associated with the video. + /// The list of contributors for this video. + /// + /// An containing either a successfully created or an error message. + /// + public static ErrorOr Create(string title, Optional originalTitle, int durationInSeconds, string resolution, ReleaseInfo release, Optional description, + Optional language, Optional originalLanguage, Optional frameRate, Optional videoCodec, Optional audioCodec, + IEnumerable? genres = null, IEnumerable? tags = null, IEnumerable? contributors = null) + { + return new VideoMetadata(title, originalTitle, durationInSeconds, resolution, release, description, + language, originalLanguage, frameRate, videoCodec, audioCodec, genres, tags, contributors); + } + + /// + public override IEnumerable 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; + foreach (var contributor in Contributors) + yield return contributor; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/FileManagementAggregate/ValueObjects/FileInfo.cs b/src/Lumina.Domain/FileManagementAggregate/ValueObjects/FileInfo.cs new file mode 100644 index 00000000..ee557566 --- /dev/null +++ b/src/Lumina.Domain/FileManagementAggregate/ValueObjects/FileInfo.cs @@ -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.FileManagementAggregate.ValueObjects; + +/// +/// Value Object for the information of a file. +/// +public class FileInfo : ValueObject +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the path of the file. + /// + public string Path { get; } + + /// + /// Gets the extension of the file. + /// + public string FileExtension { get; } + + /// + /// Gets the size of the file, in bytes. + /// + public long SizeInBytes { get; } + + /// + /// Gets the last modification date of the file. + /// + public DateTime LastModified { get; } + + /// + /// Gets the optional MIME type of the file. + /// + public Optional MimeType { get; } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Overload C-tor. + /// + /// The full path of the file. + /// The file extension. + /// The size of the file in bytes. + /// The date and time when the file was last modified. + /// The MIME type of the file, if available. + private FileInfo(string path, string fileExtension, long sizeInBytes, DateTime lastModified, Optional mimeType) + { + Path = path; + FileExtension = fileExtension; + SizeInBytes = sizeInBytes; + LastModified = lastModified; + MimeType = mimeType; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of . + /// + /// The full path of the file. + /// The file extension. + /// The size of the file in bytes. + /// The date and time when the file was last modified. + /// The MIME type of the file, if available. + /// + /// An containing either a successfully created or an error message. + /// + public static ErrorOr Create(string path, string fileExtension, long sizeInBytes, DateTime lastModified, Optional 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); + } + + /// + public override IEnumerable GetEqualityComponents() + { + yield return Path; + yield return SizeInBytes; + yield return FileExtension; + yield return LastModified; + yield return MimeType; + } + #endregion +} \ No newline at end of file diff --git a/src/Lumina.Domain/FileManagementAggregate/ValueObjects/StreamInfo.cs b/src/Lumina.Domain/FileManagementAggregate/ValueObjects/StreamInfo.cs new file mode 100644 index 00000000..aa166220 --- /dev/null +++ b/src/Lumina.Domain/FileManagementAggregate/ValueObjects/StreamInfo.cs @@ -0,0 +1,123 @@ +#region ========================================================================= USING ===================================================================================== +using ErrorOr; +using Lumina.Domain.Common.Models.Core; +using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Common.Errors; +#endregion + +namespace Lumina.Domain.FileManagementAggregate.ValueObjects; + +/// +/// Value Object for the information about a media stream. +/// +public class StreamInfo : ValueObject +{ + #region ==================================================================== PROPERTIES ================================================================================= + /// + /// Gets the id of the stream. + /// + public string StreamId { get; } + + /// + /// Gets the MimeType of the stream. + /// + public string MimeType { get; } + + /// + /// Gets the bitrate of the stream. + /// + public int Bitrate { get; } + + /// + /// Gets the codec of the stream. + /// + public string Codec { get; } + + /// + /// Gets the optional resolution of the stream. + /// + public Optional Resolution { get; } + + /// + /// Gets the optional frame rate of the stream. + /// + public Optional FrameRate { get; } + + /// + /// Gets the optional sample rate of the stream. + /// + public Optional SampleRate { get; } + + /// + /// Gets the optional channels of the stream. + /// + public Optional Channels { get; } + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Overload C-tor. + /// + /// The unique identifier for the stream. + /// The MIME type of the stream content. + /// The bitrate of the stream in bits per second. + /// The codec used for the stream. + /// The resolution of the stream (for video). + /// The frame rate of the stream (for video). + /// The sample rate of the stream (for audio). + /// The number of channels (for audio). + private StreamInfo(string streamId, string mimeType, int bitrate, string codec, + Optional resolution = default, Optional frameRate = default, Optional sampleRate = default, Optional channels = default) + { + StreamId = streamId; + MimeType = mimeType; + Bitrate = bitrate; + Codec = codec; + Resolution = resolution; + FrameRate = frameRate; + SampleRate = sampleRate; + Channels = channels; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Creates a new instance of . + /// + /// The unique identifier for the stream. + /// The MIME type of the stream content. + /// The bitrate of the stream in bits per second. + /// The codec used for the stream. + /// The resolution of the stream (for video). + /// The frame rate of the stream (for video). + /// The sample rate of the stream (for audio). + /// The number of channels (for audio). + /// + /// An containing either a successfully created or an error message. + /// + public static ErrorOr Create(string streamId, string mimeType, int bitrate, string codec, + Optional resolution = default, Optional frameRate = default, Optional sampleRate = default, Optional channels = default) + { + 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); + } + + /// + public override IEnumerable 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 +} \ No newline at end of file diff --git a/src/Lumina.Domain/Lumina.Domain.csproj b/src/Lumina.Domain/Lumina.Domain.csproj index 69269f15..c3f6698c 100644 --- a/src/Lumina.Domain/Lumina.Domain.csproj +++ b/src/Lumina.Domain/Lumina.Domain.csproj @@ -7,4 +7,8 @@ ..\..\bin\ + + + +