mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Adds first value objects of the domain
This commit is contained in:
1 parent
1e902e47dc
commit
12de2b27f0
19 files changed
+1207
-58
No files matched your search
@@ -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<FileInfo> Create(string path, string fileExtension, long sizeInBytes, DateTime lastModified, Optional<string> 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<StreamInfo> Create(string streamId, string mimeType, int bitrate, string codec,
|
||||
Optional<string> resolution = default, Optional<float> frameRate = default,
|
||||
Optional<int> sampleRate = default, Optional<int> channels = default);
|
||||
}
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"streamId": "stream_001",
|
||||
"mimeType": "video/mp4",
|
||||
"bitrate": 5000000,
|
||||
"codec": "h264",
|
||||
"resolution": "1920x1080",
|
||||
"frameRate": 29.97,
|
||||
"sampleRate": 48000,
|
||||
"channels": 2
|
||||
}
|
||||
```
|
||||
@@ -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<Genre> Create(string name);
|
||||
}
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "SF"
|
||||
}
|
||||
```
|
||||
|
||||
#### [Tag](#tag)
|
||||
|
||||
```csharp
|
||||
class Tag
|
||||
{
|
||||
ErrorOr<Tag> Create(string name);
|
||||
}
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "artificial intelligence"
|
||||
}
|
||||
```
|
||||
|
||||
#### [Rating](#rating)
|
||||
|
||||
```csharp
|
||||
class Rating
|
||||
{
|
||||
ErrorOr<Rating> Create(decimal value, decimal maxValue, Optional<RatingSource> source = default, Optional<int> voteCount = default);
|
||||
}
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"value": 9.3,
|
||||
"maxValue": 10.0,
|
||||
"source": "Imdb",
|
||||
"voteCount": 84
|
||||
}
|
||||
```
|
||||
|
||||
#### [Release Info](#release-info)
|
||||
|
||||
```csharp
|
||||
class ReleaseInfo
|
||||
{
|
||||
ErrorOr<ReleaseInfo> Create(Optional<DateOnly> originalReleaseDate, Optional<int> originalReleaseYear,
|
||||
Optional<DateOnly> reReleaseDate, Optional<int> reReleaseYear, Optional<string> releaseCountry, Optional<string> 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<LanguageInfo> Create(string languageCode, string languageName, Optional<string> nativeName);
|
||||
}
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"languageCode": "FR",
|
||||
"languageName": "French",
|
||||
"nativeName": "Française",
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Lumina.Domain.Common.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the roles of media contributors.
|
||||
/// </summary>
|
||||
public enum MediaContributorRole
|
||||
{
|
||||
Actor,
|
||||
Director,
|
||||
Singer,
|
||||
Author
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Lumina.Domain.Common.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the ratings sources.
|
||||
/// </summary>
|
||||
public enum RatingSource
|
||||
{
|
||||
User,
|
||||
Imdb,
|
||||
TheTvDb,
|
||||
TheMovieDb,
|
||||
RottenTomatoes,
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// File management error types.
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Errors;
|
||||
|
||||
/// <summary>
|
||||
/// Metadata error types.
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.Models.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Base class for all metadata-related value objects.
|
||||
/// </summary>
|
||||
public class BaseMetadata : ValueObject
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
public string Title { get; }
|
||||
public Optional<string> Description { get; }
|
||||
public Optional<DateTime> ReleaseDate { get; }
|
||||
public IReadOnlyList<string> Tags { get; }
|
||||
public IReadOnlyList<string> Genres { get; }
|
||||
public Optional<string> Language { get; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="releaseDate">The optional release date of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="description">The optional description of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="genres">The list of genres of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="tags">The list of tags of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="language">The optional language of the element to which this metadata object belongs to.</param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public BaseMetadata(string title, Optional<DateTime> releaseDate, Optional<string> description, IEnumerable<string>? genres, IEnumerable<string>? tags, Optional<string> language)
|
||||
{
|
||||
Title = title ?? throw new ArgumentNullException(nameof(title));
|
||||
ReleaseDate = releaseDate;
|
||||
Description = description;
|
||||
Genres = genres?.ToList().AsReadOnly() ?? new List<string>().AsReadOnly();
|
||||
Tags = tags?.ToList().AsReadOnly() ?? new List<string>().AsReadOnly();
|
||||
Language = language;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<object> 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
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for a contributor of a media element.
|
||||
/// </summary>
|
||||
public sealed class MediaContributor : ValueObject
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
public PersonId PersonId { get; }
|
||||
public Optional<MediaContributorRole> Role { get; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </summary>
|
||||
/// <param name="personId">The id of the person represented by this object.</param>
|
||||
/// <param name="role">The role of the person represented by this object.</param>
|
||||
private MediaContributor(PersonId personId, Optional<MediaContributorRole> role)
|
||||
{
|
||||
Role = role;
|
||||
PersonId = personId;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="MediaContributor"/>.
|
||||
/// </summary>
|
||||
/// <param name="personId">The id of the person represented by this object.</param>
|
||||
/// <param name="role">The role of the person represented by this object.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="MediaContributor"/> or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<MediaContributor> Create(PersonId personId, Optional<MediaContributorRole> role)
|
||||
{
|
||||
return new MediaContributor(personId, role);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return PersonId;
|
||||
yield return Role;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.ValueObjects.Media;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for the Id of a person.
|
||||
/// </summary>
|
||||
public sealed class PersonId : ValueObject
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
public Guid Value { get; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </summary>
|
||||
/// <param name="value">The value representing this object.</param>
|
||||
private PersonId(Guid value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="PersonId"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="PersonId"/> instance.</returns>
|
||||
public static PersonId CreateUnique()
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
return new PersonId(Guid.NewGuid());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="PersonId"/> from <paramref name="value"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value used to create the <see cref="PersonId"/> instance.</param>
|
||||
/// <returns>The created <see cref="PersonId"/> instance.</returns>
|
||||
public static PersonId Create(Guid value)
|
||||
{
|
||||
// TODO: enforce invariants
|
||||
return new PersonId(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return Value;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Base template for all metadata-related value objects.
|
||||
/// </summary>
|
||||
public abstract class BaseMetadata : ValueObject
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets the title of the media item.
|
||||
/// </summary>
|
||||
public string Title { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the original title of the media item.
|
||||
/// </summary>
|
||||
public Optional<string> OriginalTitle { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional description of the media item.
|
||||
/// </summary>
|
||||
public Optional<string> Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the release information of the media item.
|
||||
/// </summary>
|
||||
public ReleaseInfo ReleaseInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of tags associated with the media item.
|
||||
/// </summary>
|
||||
public IReadOnlyList<Tag> Tags { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of genres associated with the media item.
|
||||
/// </summary>
|
||||
public IReadOnlyList<Genre> Genres { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional language of the media item.
|
||||
/// </summary>
|
||||
public Optional<LanguageInfo> Language { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional original language of the media item.
|
||||
/// </summary>
|
||||
public Optional<LanguageInfo> OriginalLanguage { get; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="originalTitle">The optional original title of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="releaseInfo">The optional release information of the media item.</param>
|
||||
/// <param name="description">The optional description of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="genres">The list of genres of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="tags">The list of tags of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="language">The optional language of the element to which this metadata object belongs to.</param>
|
||||
/// <param name="originalLanguage">The optional original language of the element to which this metadata object belongs to.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown when the <see cref="title"/> value is <see langword="null"/></exception>
|
||||
protected BaseMetadata(string title, Optional<string> originalTitle, ReleaseInfo releaseInfo, Optional<string> description,
|
||||
IEnumerable<Genre>? genres, IEnumerable<Tag>? tags, Optional<LanguageInfo> language, Optional<LanguageInfo> originalLanguage)
|
||||
{
|
||||
Title = title ?? throw new ArgumentNullException(nameof(title));
|
||||
OriginalTitle = originalTitle;
|
||||
ReleaseInfo = releaseInfo;
|
||||
Description = description;
|
||||
Genres = genres?.ToList().AsReadOnly() ?? new List<Genre>().AsReadOnly();
|
||||
Tags = tags?.ToList().AsReadOnly() ?? new List<Tag>().AsReadOnly();
|
||||
Language = language;
|
||||
OriginalLanguage = originalLanguage;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<object> 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
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for the genres of a media element.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Name}")]
|
||||
public class Genre : ValueObject
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets the name of the genre element of the media item.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </summary>
|
||||
/// <param name="name">The value representing this object.</param>
|
||||
private Genre(string name)
|
||||
{
|
||||
Name = name.Trim();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="Genre"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">The value of the genre.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Genre"/> or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Genre> Create(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Errors.Errors.Metadata.GenreCannotBeEmpty;
|
||||
return new Genre(name);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Customized ToString() method.
|
||||
/// </summary>
|
||||
/// <returns>Custom string value showing relevant data for current class.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for the language used in a media element.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{LanguageCode}")]
|
||||
public class LanguageInfo : ValueObject
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets the ISO 639-1 two-letter language code.
|
||||
/// </summary>
|
||||
public string LanguageCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full name of the language in English.
|
||||
/// </summary>
|
||||
public string LanguageName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets an optional native name of the language.
|
||||
/// </summary>
|
||||
public Optional<string> NativeName { get; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </summary>
|
||||
/// <param name="languageCode">The ISO 639-1 two-letter language code.</param>
|
||||
/// <param name="languageName">The full name of the language in English.</param>
|
||||
/// <param name="nativeName">The optional native name of the language.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown if languageCode or languageName is null.</exception>
|
||||
/// <exception cref="ArgumentException">Thrown if languageCode is not a valid ISO 639-1 code.</exception>
|
||||
private LanguageInfo(string languageCode, string languageName, Optional<string> nativeName)
|
||||
{
|
||||
LanguageCode = languageCode.ToLowerInvariant();
|
||||
LanguageName = languageName;
|
||||
NativeName = nativeName;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="LanguageInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="languageCode">The ISO 639-1 two-letter language code.</param>
|
||||
/// <param name="languageName">The full name of the language in English.</param>
|
||||
/// <param name="nativeName">The optional native name of the language.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="LanguageInfo"/> or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<LanguageInfo> Create(string languageCode, string languageName, Optional<string> nativeName)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return LanguageCode;
|
||||
yield return LanguageName;
|
||||
yield return NativeName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Customized ToString() method.
|
||||
/// </summary>
|
||||
/// <returns>Custom string value showing relevant data for current class.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{LanguageCode} - {LanguageName}";
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for the rating of a media element.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Value}/{MaxValue}")]
|
||||
public class Rating : ValueObject
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets the numeric value of the rating.
|
||||
/// </summary>
|
||||
public decimal Value { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum possible rating value.
|
||||
/// </summary>
|
||||
public decimal MaxValue { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional source of the rating (e.g., "IMDB", "Rotten Tomatoes").
|
||||
/// </summary>
|
||||
public Optional<RatingSource> Source { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional number of votes or reviews this rating is based on.
|
||||
/// </summary>
|
||||
public Optional<int> VoteCount { get; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </summary>
|
||||
/// <param name="value">The numeric value of the rating.</param>
|
||||
/// <param name="maxValue">The maximum possible rating value.</param>
|
||||
/// <param name="source">The optional source of the rating.</param>
|
||||
/// <param name="voteCount">The optional number of votes or reviews.</param>
|
||||
private Rating(decimal value, decimal maxValue, Optional<RatingSource> source = default, Optional<int> voteCount = default)
|
||||
{
|
||||
Value = value;
|
||||
MaxValue = maxValue;
|
||||
Source = source;
|
||||
VoteCount = voteCount;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="Rating"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The numeric value of the rating.</param>
|
||||
/// <param name="maxValue">The maximum possible rating value.</param>
|
||||
/// <param name="source">The optional source of the rating.</param>
|
||||
/// <param name="voteCount">The optional number of votes or reviews.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Rating"/> or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Rating> Create(decimal value, decimal maxValue, Optional<RatingSource> source = default, Optional<int> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the rating as a percentage.
|
||||
/// </summary>
|
||||
/// <returns>The rating value as a percentage of the maximum value.</returns>
|
||||
public decimal AsPercentage()
|
||||
{
|
||||
return (Value / MaxValue) * 100;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return Value;
|
||||
yield return MaxValue;
|
||||
yield return Source;
|
||||
yield return VoteCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Customized ToString() method.
|
||||
/// </summary>
|
||||
/// <returns>Custom string value showing relevant data for current class.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
string baseString = $"{Value}/{MaxValue}";
|
||||
if (Source.HasValue)
|
||||
baseString += $" ({Source.Value})";
|
||||
if (VoteCount.HasValue)
|
||||
baseString += $" [{VoteCount.Value} votes]";
|
||||
return baseString;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for the release info of a media element.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{ReleaseYear}")]
|
||||
public class ReleaseInfo : ValueObject
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets the optional original release date of the media item.
|
||||
/// </summary>
|
||||
public Optional<DateOnly> OriginalReleaseDate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional original release year of the media item.
|
||||
/// This is useful when only the year of original release is known.
|
||||
/// </summary>
|
||||
public Optional<int> OriginalReleaseYear { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional re-release or reissue date of the media item.
|
||||
/// </summary>
|
||||
public Optional<DateOnly> ReReleaseDate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional re-release or reissue year of the media item.
|
||||
/// </summary>
|
||||
public Optional<int> ReReleaseYear { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional country or region of release.
|
||||
/// </summary>
|
||||
public Optional<string> ReleaseCountry { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the optional release version or edition. (e.g. "Original", "Director's Cut", "2.0")
|
||||
/// </summary>
|
||||
public Optional<string> ReleaseVersion { get; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </summary>
|
||||
/// <param name="originalReleaseDate">The optional original release date of the media item.</param>
|
||||
/// <param name="originalReleaseYear">The optional original release year of the media item.</param>
|
||||
/// <param name="reReleaseDate">The optional re-release date of the media item.</param>
|
||||
/// <param name="reReleaseYear">The optional re-release year of the media item.</param>
|
||||
/// <param name="releaseCountry">The optional country or region of release.</param>
|
||||
/// <param name="releaseVersion">The optional release version or edition.</param>
|
||||
private ReleaseInfo(Optional<DateOnly> originalReleaseDate, Optional<int> originalReleaseYear,
|
||||
Optional<DateOnly> reReleaseDate, Optional<int> reReleaseYear, Optional<string> releaseCountry, Optional<string> releaseVersion)
|
||||
{
|
||||
OriginalReleaseDate = originalReleaseDate;
|
||||
OriginalReleaseYear = originalReleaseYear;
|
||||
ReReleaseDate = reReleaseDate;
|
||||
ReReleaseYear = reReleaseYear;
|
||||
ReleaseCountry = releaseCountry;
|
||||
ReleaseVersion = releaseVersion;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="ReleaseInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="originalReleaseDate">The optional original release date of the media item.</param>
|
||||
/// <param name="originalReleaseYear">The optional original release year of the media item.</param>
|
||||
/// <param name="reReleaseDate">The optional re-release date of the media item.</param>
|
||||
/// <param name="reReleaseYear">The optional re-release year of the media item.</param>
|
||||
/// <param name="releaseCountry">The optional country or region of release.</param>
|
||||
/// <param name="releaseVersion">The optional release version or edition.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="ReleaseInfo"/> or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<ReleaseInfo> Create(Optional<DateOnly> originalReleaseDate, Optional<int> originalReleaseYear,
|
||||
Optional<DateOnly> reReleaseDate, Optional<int> reReleaseYear, Optional<string> releaseCountry, Optional<string> 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);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return OriginalReleaseDate;
|
||||
yield return OriginalReleaseYear;
|
||||
yield return ReReleaseDate;
|
||||
yield return ReReleaseYear;
|
||||
yield return ReleaseCountry;
|
||||
yield return ReleaseVersion;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for the tags of a media element.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Name}")]
|
||||
public class Tag : ValueObject
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets the name of the tag element of the media item.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </summary>
|
||||
/// <param name="name">The value representing this object.</param>
|
||||
private Tag(string name)
|
||||
{
|
||||
Name = name.Trim();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="Tag"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">The value of the tag.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{T}"/> containing either a successfully created <see cref="Tag"/> or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<Tag> Create(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Errors.Errors.Metadata.TagCannotBeEmpty;
|
||||
return new Tag(name);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Customized ToString() method.
|
||||
/// </summary>
|
||||
/// <returns>Custom string value showing relevant data for current class.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Value Object for the rating of a media element.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("{Value}/{MaxValue}")]
|
||||
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; }
|
||||
|
||||
/// <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; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of actors starring in this video.
|
||||
/// </summary>
|
||||
public IReadOnlyList<MediaContributor> Contributors { get; }
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </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>
|
||||
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,
|
||||
IEnumerable<Genre>? genres = null, IEnumerable<Tag>? tags = null, IEnumerable<MediaContributor>? 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<MediaContributor>().AsReadOnly();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="VideoMetadata"/>.
|
||||
/// </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,
|
||||
IEnumerable<Genre>? genres = null, IEnumerable<Tag>? tags = null, IEnumerable<MediaContributor>? contributors = null)
|
||||
{
|
||||
return new VideoMetadata(title, originalTitle, durationInSeconds, resolution, release, description,
|
||||
language, originalLanguage, frameRate, videoCodec, audioCodec, genres, tags, contributors);
|
||||
}
|
||||
|
||||
/// <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;
|
||||
foreach (var contributor in Contributors)
|
||||
yield return contributor;
|
||||
}
|
||||
#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.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>
|
||||
/// Overload C-tor.
|
||||
/// </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 <see cref="FileInfo"/>.
|
||||
/// </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,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;
|
||||
|
||||
/// <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>
|
||||
/// Overload C-tor.
|
||||
/// </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 = default, Optional<float> frameRate = default, Optional<int> sampleRate = default, Optional<int> channels = default)
|
||||
{
|
||||
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 <see cref="StreamInfo"/>.
|
||||
/// </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 = default, Optional<float> frameRate = default, Optional<int> sampleRate = default, Optional<int> 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);
|
||||
}
|
||||
|
||||
/// <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
|
||||
}
|
||||
@@ -7,4 +7,8 @@
|
||||
<BaseOutputPath>..\..\bin\</BaseOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ErrorOr" Version="2.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in new issue
Block a user