Adds domain Music aggregate

This commit is contained in:
BinaryAlley committed 2026-09-07 09:41:57 -07:00
1 parent bde08c7440
commit 3a720af29f
100 files changed
+13077 -558

No files matched your search

@@ -1,12 +1,11 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.AudioLibraryAggregate.ValueObjects;
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
/// <summary>
/// Value Object for the audio metadata of a media element.
@@ -15,7 +14,7 @@ namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.AudioLib
public class AudioMetadata : BaseMetadata
{
/// <summary>
/// Gets the duration of the video in seconds.
/// Gets the duration of the audio in seconds.
/// </summary>
public int DurationInSeconds { get; }
@@ -48,19 +47,20 @@ public class AudioMetadata : BaseMetadata
/// Initializes a new instance of the <see cref="AudioMetadata"/> class.
/// </summary>
/// <param name="title">The title of the audio.</param>
/// <param name="originalTitle">The optional original title of the video.</param>
/// <param name="originalTitle">The optional original title of the audio.</param>
/// <param name="durationInSeconds">The duration of the audio, in seconds.</param>
/// <param name="sampleRate">The sample rate of the audio, in Hz.</param>
/// <param name="channels">The number of audio channels.</param>
/// <param name="releaseInfo">The release information of the audio.</param>
/// <param name="description">The description of the audio.</param>
/// <param name="language">The language of the audio.</param>
/// <param name="originalLanguage">The optional original language of the video.</param>
/// <param name="originalLanguage">The optional original language of the audio.</param>
/// <param name="bitDepth">The bit depth of the audio.</param>
/// <param name="audioCodec">The audio codec used.</param>
/// <param name="genres">The genres of the audio.</param>
/// <param name="tags">The tags associated with the audio.</param>
public AudioMetadata(
/// <param name="bitrate">The bitrate of the audio in kbps.</param>
private AudioMetadata(
string title,
Optional<string> originalTitle,
int durationInSeconds,
@@ -89,18 +89,19 @@ public class AudioMetadata : BaseMetadata
/// Creates a new instance of the <see cref="AudioMetadata"/> class.
/// </summary>
/// <param name="title">The title of the audio.</param>
/// <param name="originalTitle">The optional original title of the video.</param>
/// <param name="originalTitle">The optional original title of the audio.</param>
/// <param name="durationInSeconds">The duration of the audio, in seconds.</param>
/// <param name="sampleRate">The sample rate of the audio, in Hz.</param>
/// <param name="channels">The number of audio channels.</param>
/// <param name="release">The release information of the audio.</param>
/// <param name="releaseInfo">The release information of the audio.</param>
/// <param name="description">The description of the audio.</param>
/// <param name="language">The language of the audio.</param>
/// <param name="originalLanguage">The optional original language of the video.</param>
/// <param name="originalLanguage">The optional original language of the audio.</param>
/// <param name="bitDepth">The bit depth of the audio.</param>
/// <param name="audioCodec">The audio codec used.</param>
/// <param name="genres">The genres of the audio.</param>
/// <param name="tags">The tags associated with the audio.</param>
/// <param name="bitrate">The bitrate of the audio in kbps.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="AudioMetadata"/>, or an error message.
/// </returns>
@@ -110,9 +111,8 @@ public class AudioMetadata : BaseMetadata
int durationInSeconds,
int sampleRate,
int channels,
ReleaseInfo release,
Optional<string>
description,
ReleaseInfo releaseInfo,
Optional<string> description,
List<Genre> genres,
List<Tag> tags,
Optional<LanguageInfo> language,
@@ -127,7 +127,7 @@ public class AudioMetadata : BaseMetadata
durationInSeconds,
sampleRate,
channels,
release,
releaseInfo,
description,
genres,
tags,
@@ -0,0 +1,79 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
/// <summary>
/// Value Object for the rating of an audio media element.
/// </summary>
[DebuggerDisplay("{Value}/{MaxValue}")]
public class AudioRating : Rating
{
/// <summary>
/// Gets the optional source of the rating (e.g., "MusicBrainz", "Last.fm").
/// </summary>
public Optional<AudioRatingSource> Source { get; }
/// <summary>
/// Initializes a new instance of the <see cref="AudioRating"/> class.
/// </summary>
/// <param name="value">The numeric value of the rating.</param>
/// <param name="maxValue">The maximum possible rating value.</param>
/// <param name="source">The optional source of the rating.</param>
/// <param name="voteCount">The optional number of votes or reviews.</param>
private AudioRating(decimal value, decimal maxValue, Optional<AudioRatingSource> source, Optional<int> voteCount)
: base(value, maxValue, voteCount)
{
Source = source;
}
/// <summary>
/// Creates a new instance of the <see cref="AudioRating"/> class.
/// </summary>
/// <param name="value">The numeric value of the rating.</param>
/// <param name="maxValue">The maximum possible rating value.</param>
/// <param name="source">The optional source of the rating.</param>
/// <param name="voteCount">The optional number of votes or reviews.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="AudioRating"/>, or an error message.
/// </returns>
public static Result<AudioRating> Create(decimal value, decimal maxValue, Optional<AudioRatingSource> source, Optional<int> voteCount)
{
if (value > maxValue)
return Errors.Metadata.RatingValueCannotBeGreaterThanMaxValue;
return new AudioRating(value, maxValue, source, voteCount);
}
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
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;
}
}
@@ -0,0 +1,51 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
/// <summary>
/// Value Object for the Id of a media library, duplicated from the LibraryManagement bounded context to keep the cross bounded context references decoupled.
/// </summary>
[DebuggerDisplay("{Value}")]
public sealed class LibraryId : EntityId<Guid>
{
/// <summary>
/// Initializes a new instance of the <see cref="LibraryId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private LibraryId(Guid value) : base(value)
{
}
/// <summary>
/// Creates a new instance of the <see cref="LibraryId"/> class.
/// </summary>
/// <returns>The created <see cref="LibraryId"/> instance.</returns>
public static LibraryId CreateUnique()
{
return new LibraryId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="LibraryId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="LibraryId"/> instance.</param>
/// <returns>The created <see cref="LibraryId"/> instance.</returns>
public static LibraryId Create(Guid value)
{
return new LibraryId(value);
}
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
}
@@ -0,0 +1,51 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.MediaContributorBoundedContext.MediaContributorAggregate;
/// <summary>
/// Value Object for the Id of a media contributor, duplicated from the MediaContributor bounded context to keep the cross bounded context references decoupled.
/// </summary>
[DebuggerDisplay("{Value}")]
public sealed class MediaContributorId : EntityId<Guid>
{
/// <summary>
/// Initializes a new instance of the <see cref="MediaContributorId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private MediaContributorId(Guid value) : base(value)
{
}
/// <summary>
/// Creates a new instance of the <see cref="MediaContributorId"/> class.
/// </summary>
/// <returns>The created <see cref="MediaContributorId"/> instance.</returns>
public static MediaContributorId CreateUnique()
{
return new MediaContributorId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="MediaContributorId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="MediaContributorId"/> instance.</param>
/// <returns>The created <see cref="MediaContributorId"/> instance.</returns>
public static MediaContributorId Create(Guid value)
{
return new MediaContributorId(value);
}
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
}
@@ -0,0 +1,205 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.MediaContributorBoundedContext.MediaContributorAggregate;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
/// <summary>
/// Aggregate root for an artist.
/// </summary>
/// <remarks>
/// An artist is the entity that produced a musical work, whatever or whoever that might be. An artist is a single person, like Freddie Mercury, a group of people,
/// like Queen, or a collaboration between artists, like Queen and David Bowie. The media contributors that make up the artist, together with the roles they play,
/// are tracked as credits, and the artist can also reference the single media contributor it corresponds to, so that an artist and the person behind it are never duplicated.
/// </remarks>
[DebuggerDisplay("Id: {Id} Name: {Name}")]
public sealed class Artist : AggregateRoot<ArtistId>
{
private readonly List<MediaContributorCredit> _credits;
private readonly List<Album> _albums;
/// <summary>
/// Gets the name of the artist.
/// </summary>
public string Name { get; private set; }
/// <summary>
/// Gets the website of the artist, if applicable.
/// </summary>
public Optional<string> Website { get; private set; }
/// <summary>
/// Gets the MusicBrainz identifier of the artist, if applicable.
/// </summary>
public Optional<MusicBrainzId> MusicBrainzArtistId { get; private set; }
/// <summary>
/// Gets the Id of the media contributor the artist corresponds to, if applicable.
/// </summary>
public Optional<MediaContributorId> MediaContributorId { get; private set; }
/// <summary>
/// Gets the list of the credits of the media contributors that make up the artist.
/// </summary>
public IReadOnlyCollection<MediaContributorCredit> Credits => _credits.AsReadOnly();
/// <summary>
/// Gets the list of albums of the artist.
/// </summary>
public IReadOnlyCollection<Album> Albums => _albums.AsReadOnly();
/// <summary>
/// Initializes a new instance of the <see cref="Artist"/> class.
/// </summary>
/// <param name="id">The object representing the unique identifier of the artist.</param>
/// <param name="name">The name of the artist.</param>
/// <param name="website">The optional website of the artist.</param>
/// <param name="musicBrainzArtistId">The optional MusicBrainz identifier of the artist.</param>
/// <param name="mediaContributorId">The optional Id of the media contributor the artist corresponds to.</param>
/// <param name="credits">The list of the credits of the media contributors that make up the artist.</param>
/// <param name="albums">The list of albums of the artist.</param>
/// <param name="createdOnUtc">The date and time when the entity was created.</param>
/// <param name="updatedOnUtc">The date and time when the entity was last updated.</param>
private Artist(
ArtistId id,
string name,
Optional<string> website,
Optional<MusicBrainzId> musicBrainzArtistId,
Optional<MediaContributorId> mediaContributorId,
List<MediaContributorCredit> credits,
List<Album> albums,
DateTime createdOnUtc,
Optional<DateTime> updatedOnUtc) : base(id)
{
Id = id;
Name = name;
Website = website;
MusicBrainzArtistId = musicBrainzArtistId;
MediaContributorId = mediaContributorId;
_credits = credits;
_albums = albums;
CreatedOnUtc = createdOnUtc;
UpdatedOnUtc = updatedOnUtc.HasValue ? updatedOnUtc.Value : null;
}
/// <summary>
/// Creates a new instance of the <see cref="Artist"/> class.
/// </summary>
/// <param name="name">The name of the artist.</param>
/// <param name="website">The optional website of the artist.</param>
/// <param name="musicBrainzArtistId">The optional MusicBrainz identifier of the artist.</param>
/// <param name="mediaContributorId">The optional Id of the media contributor the artist corresponds to.</param>
/// <param name="credits">The list of the credits of the media contributors that make up the artist.</param>
/// <param name="albums">The list of albums of the artist.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Artist"/>, or an error message.
/// </returns>
public static Result<Artist> Create(
string name,
Optional<string> website,
Optional<MusicBrainzId> musicBrainzArtistId,
Optional<MediaContributorId> mediaContributorId,
List<MediaContributorCredit> credits,
List<Album> albums)
{
if (string.IsNullOrWhiteSpace(name))
return Errors.Music.ArtistNameCannotBeEmpty;
return new Artist(
ArtistId.CreateUnique(),
name,
website,
musicBrainzArtistId,
mediaContributorId,
credits,
albums,
DateTime.UtcNow,
Optional<DateTime>.None());
}
/// <summary>
/// Creates a new instance of the <see cref="Artist"/> class, with a pre-existing <paramref name="id"/>.
/// </summary>
/// <param name="id">The object representing the unique identifier of the artist.</param>
/// <param name="name">The name of the artist.</param>
/// <param name="website">The optional website of the artist.</param>
/// <param name="musicBrainzArtistId">The optional MusicBrainz identifier of the artist.</param>
/// <param name="mediaContributorId">The optional Id of the media contributor the artist corresponds to.</param>
/// <param name="credits">The list of the credits of the media contributors that make up the artist.</param>
/// <param name="albums">The list of albums of the artist.</param>
/// <param name="createdOnUtc">The date and time when the entity was created.</param>
/// <param name="updatedOnUtc">The date and time when the entity was last updated.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Artist"/>, or an error message.
/// </returns>
public static Result<Artist> Create(
ArtistId id,
string name,
Optional<string> website,
Optional<MusicBrainzId> musicBrainzArtistId,
Optional<MediaContributorId> mediaContributorId,
List<MediaContributorCredit> credits,
List<Album> albums,
DateTime createdOnUtc,
Optional<DateTime> updatedOnUtc)
{
if (string.IsNullOrWhiteSpace(name))
return Errors.Music.ArtistNameCannotBeEmpty;
return new Artist(
id,
name,
website,
musicBrainzArtistId,
mediaContributorId,
credits,
albums,
createdOnUtc,
updatedOnUtc);
}
/// <summary>
/// Adds an album to the artist.
/// </summary>
/// <param name="album">The album to be added.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public Result<Created> AddAlbum(Album album)
{
if (_albums.Contains(album))
return Errors.Music.TheArtistAlreadyHasTheAlbum;
_albums.Add(album);
return Result.Created;
}
/// <summary>
/// Removes an album from the artist.
/// </summary>
/// <param name="album">The album to be removed.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public Result<Deleted> RemoveAlbum(Album album)
{
if (!_albums.Contains(album))
return Errors.Music.TheArtistDoesNotHaveTheAlbum;
_albums.Remove(album);
return Result.Deleted;
}
/// <summary>
/// Replaces the credits of the media contributors that make up the artist with the provided <paramref name="credits"/>.
/// </summary>
/// <param name="credits">The credits of the media contributors that make up the artist.</param>
public void UpdateCredits(IReadOnlyCollection<MediaContributorCredit> credits)
{
// replace the contents of the collection in place, preserving the readonly reference invariants of the aggregate
_credits.Clear();
_credits.AddRange(credits);
}
}
@@ -0,0 +1,236 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
/// <summary>
/// Entity for an album, a release of an artist.
/// </summary>
[DebuggerDisplay("{Id}: {Metadata.Title}")]
public sealed class Album : Entity<AlbumId>
{
private readonly List<MediaContributorCredit> _credits;
private readonly List<AudioRating> _ratings;
private readonly List<Track> _tracks;
/// <summary>
/// Gets the album metadata of the album.
/// </summary>
public AlbumMetadata Metadata { get; private set; }
/// <summary>
/// Gets the physical or digital medium of the album, if applicable.
/// </summary>
public Optional<MusicMediaFormat> MediaFormat { get; private set; }
/// <summary>
/// Gets the barcode of the album, if applicable.
/// </summary>
public Optional<Barcode> Barcode { get; private set; }
/// <summary>
/// Gets the catalog number of the album, if applicable.
/// </summary>
public Optional<string> CatalogNumber { get; private set; }
/// <summary>
/// Gets the MusicBrainz identifier of the release, if applicable.
/// </summary>
public Optional<MusicBrainzId> MusicBrainzReleaseId { get; private set; }
/// <summary>
/// Gets the MusicBrainz identifier of the release group, if applicable.
/// </summary>
public Optional<MusicBrainzId> MusicBrainzReleaseGroupId { get; private set; }
/// <summary>
/// Gets the MusicBrainz identifier of the release artist, if applicable.
/// </summary>
public Optional<MusicBrainzId> MusicBrainzReleaseArtistId { get; private set; }
/// <summary>
/// Gets the list of the credits of the media contributors of the album.
/// </summary>
public IReadOnlyCollection<MediaContributorCredit> Credits => _credits.AsReadOnly();
/// <summary>
/// Gets the list of ratings for this album.
/// </summary>
public IReadOnlyCollection<AudioRating> Ratings => _ratings.AsReadOnly();
/// <summary>
/// Gets the list of tracks of the album.
/// </summary>
public IReadOnlyCollection<Track> Tracks => _tracks.AsReadOnly();
/// <summary>
/// Initializes a new instance of the <see cref="Album"/> class.
/// </summary>
/// <param name="id">The object representing the unique identifier of the album.</param>
/// <param name="metadata">The album metadata of the album.</param>
/// <param name="mediaFormat">The optional physical or digital medium of the album.</param>
/// <param name="barcode">The optional barcode of the album.</param>
/// <param name="catalogNumber">The optional catalog number of the album.</param>
/// <param name="musicBrainzReleaseId">The optional MusicBrainz identifier of the release.</param>
/// <param name="musicBrainzReleaseGroupId">The optional MusicBrainz identifier of the release group.</param>
/// <param name="musicBrainzReleaseArtistId">The optional MusicBrainz identifier of the release artist.</param>
/// <param name="credits">The list of the credits of the media contributors of the album.</param>
/// <param name="ratings">The list of ratings for the album.</param>
/// <param name="tracks">The list of tracks of the album.</param>
private Album(
AlbumId id,
AlbumMetadata metadata,
Optional<MusicMediaFormat> mediaFormat,
Optional<Barcode> barcode,
Optional<string> catalogNumber,
Optional<MusicBrainzId> musicBrainzReleaseId,
Optional<MusicBrainzId> musicBrainzReleaseGroupId,
Optional<MusicBrainzId> musicBrainzReleaseArtistId,
List<MediaContributorCredit> credits,
List<AudioRating> ratings,
List<Track> tracks) : base(id)
{
Id = id;
Metadata = metadata;
MediaFormat = mediaFormat;
Barcode = barcode;
CatalogNumber = catalogNumber;
MusicBrainzReleaseId = musicBrainzReleaseId;
MusicBrainzReleaseGroupId = musicBrainzReleaseGroupId;
MusicBrainzReleaseArtistId = musicBrainzReleaseArtistId;
_credits = credits;
_ratings = ratings;
_tracks = tracks;
}
/// <summary>
/// Creates a new instance of the <see cref="Album"/> class.
/// </summary>
/// <param name="metadata">The album metadata of the album.</param>
/// <param name="mediaFormat">The optional physical or digital medium of the album.</param>
/// <param name="barcode">The optional barcode of the album.</param>
/// <param name="catalogNumber">The optional catalog number of the album.</param>
/// <param name="musicBrainzReleaseId">The optional MusicBrainz identifier of the release.</param>
/// <param name="musicBrainzReleaseGroupId">The optional MusicBrainz identifier of the release group.</param>
/// <param name="musicBrainzReleaseArtistId">The optional MusicBrainz identifier of the release artist.</param>
/// <param name="credits">The list of the credits of the media contributors of the album.</param>
/// <param name="ratings">The list of ratings for the album.</param>
/// <param name="tracks">The list of tracks of the album.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Album"/>, or an error message.
/// </returns>
public static Result<Album> Create(
AlbumMetadata metadata,
Optional<MusicMediaFormat> mediaFormat,
Optional<Barcode> barcode,
Optional<string> catalogNumber,
Optional<MusicBrainzId> musicBrainzReleaseId,
Optional<MusicBrainzId> musicBrainzReleaseGroupId,
Optional<MusicBrainzId> musicBrainzReleaseArtistId,
List<MediaContributorCredit> credits,
List<AudioRating> ratings,
List<Track> tracks)
{
return new Album(
AlbumId.CreateUnique(),
metadata,
mediaFormat,
barcode,
catalogNumber,
musicBrainzReleaseId,
musicBrainzReleaseGroupId,
musicBrainzReleaseArtistId,
credits,
ratings,
tracks);
}
/// <summary>
/// Creates a new instance of the <see cref="Album"/> class, with a pre-existing <paramref name="id"/>.
/// </summary>
/// <param name="id">The object representing the unique identifier of the album.</param>
/// <param name="metadata">The album metadata of the album.</param>
/// <param name="mediaFormat">The optional physical or digital medium of the album.</param>
/// <param name="barcode">The optional barcode of the album.</param>
/// <param name="catalogNumber">The optional catalog number of the album.</param>
/// <param name="musicBrainzReleaseId">The optional MusicBrainz identifier of the release.</param>
/// <param name="musicBrainzReleaseGroupId">The optional MusicBrainz identifier of the release group.</param>
/// <param name="musicBrainzReleaseArtistId">The optional MusicBrainz identifier of the release artist.</param>
/// <param name="credits">The list of the credits of the media contributors of the album.</param>
/// <param name="ratings">The list of ratings for the album.</param>
/// <param name="tracks">The list of tracks of the album.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Album"/>, or an error message.
/// </returns>
public static Result<Album> Create(
AlbumId id,
AlbumMetadata metadata,
Optional<MusicMediaFormat> mediaFormat,
Optional<Barcode> barcode,
Optional<string> catalogNumber,
Optional<MusicBrainzId> musicBrainzReleaseId,
Optional<MusicBrainzId> musicBrainzReleaseGroupId,
Optional<MusicBrainzId> musicBrainzReleaseArtistId,
List<MediaContributorCredit> credits,
List<AudioRating> ratings,
List<Track> tracks)
{
return new Album(
id,
metadata,
mediaFormat,
barcode,
catalogNumber,
musicBrainzReleaseId,
musicBrainzReleaseGroupId,
musicBrainzReleaseArtistId,
credits,
ratings,
tracks);
}
/// <summary>
/// Adds a track to the album.
/// </summary>
/// <param name="track">The track to be added.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public Result<Created> AddTrack(Track track)
{
if (_tracks.Contains(track))
return Errors.Music.TheTrackIsAlreadyInTheAlbum;
_tracks.Add(track);
return Result.Created;
}
/// <summary>
/// Removes a track from the album.
/// </summary>
/// <param name="track">The track to be removed.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public Result<Deleted> RemoveTrack(Track track)
{
if (!_tracks.Contains(track))
return Errors.Music.TheTrackIsNotInTheAlbum;
_tracks.Remove(track);
return Result.Deleted;
}
/// <summary>
/// Replaces the credits of the media contributors of the album with the provided <paramref name="credits"/>.
/// </summary>
/// <param name="credits">The credits of the media contributors of the album.</param>
public void UpdateCredits(IReadOnlyCollection<MediaContributorCredit> credits)
{
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
_credits.Clear();
_credits.AddRange(credits);
}
}
@@ -0,0 +1,296 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
/// <summary>
/// Entity for a track, the individual song of an album.
/// </summary>
[DebuggerDisplay("{Id}: {Metadata.Title}")]
public sealed class Track : Entity<TrackId>
{
private readonly List<Isrc> _isrcs;
private readonly List<Mood> _moods;
private readonly List<MediaContributorCredit> _credits;
private readonly List<AudioRating> _ratings;
/// <summary>
/// Gets the Id of the media library this track belongs to.
/// </summary>
public LibraryId LibraryId { get; private set; }
/// <summary>
/// Gets the file system path of the track.
/// </summary>
public string Path { get; private set; }
/// <summary>
/// Gets the audio metadata of the track.
/// </summary>
public AudioMetadata Metadata { get; private set; }
/// <summary>
/// Gets the number of the track on its disc.
/// </summary>
public int TrackNumber { get; private set; }
/// <summary>
/// Gets the number of the disc the track belongs to, if applicable.
/// </summary>
public Optional<int> DiscNumber { get; private set; }
/// <summary>
/// Gets the script used by the language of the track, if applicable.
/// </summary>
public Optional<string> Script { get; private set; }
/// <summary>
/// Gets the musical key of the track, if applicable.
/// </summary>
public Optional<MusicKey> Key { get; private set; }
/// <summary>
/// Gets the tempo of the track in beats per minute, if applicable.
/// </summary>
public Optional<int> Bpm { get; private set; }
/// <summary>
/// Gets the title of the work the track is a recording of, if applicable.
/// </summary>
public Optional<string> Work { get; private set; }
/// <summary>
/// Gets the MusicBrainz identifier of the recording, if applicable.
/// </summary>
public Optional<MusicBrainzId> MusicBrainzRecordingId { get; private set; }
/// <summary>
/// Gets the MusicBrainz identifier of the track, if applicable.
/// </summary>
public Optional<MusicBrainzId> MusicBrainzTrackId { get; private set; }
/// <summary>
/// Gets the MusicBrainz identifier of the work, if applicable.
/// </summary>
public Optional<MusicBrainzId> MusicBrainzWorkId { get; private set; }
/// <summary>
/// Gets the list of moods of the track.
/// </summary>
public IReadOnlyCollection<Mood> Moods => _moods.AsReadOnly();
/// <summary>
/// Gets the list of ISRC (International Standard Recording Code) of the track.
/// </summary>
public IReadOnlyCollection<Isrc> Isrcs => _isrcs.AsReadOnly();
/// <summary>
/// Gets the list of the credits of the media contributors of the track.
/// </summary>
public IReadOnlyCollection<MediaContributorCredit> Credits => _credits.AsReadOnly();
/// <summary>
/// Gets the list of ratings for this track.
/// </summary>
public IReadOnlyCollection<AudioRating> Ratings => _ratings.AsReadOnly();
/// <summary>
/// Initializes a new instance of the <see cref="Track"/> class.
/// </summary>
/// <param name="id">The object representing the unique identifier of the track.</param>
/// <param name="libraryId">The Id of the media library this track belongs to.</param>
/// <param name="path">The file system path of the track.</param>
/// <param name="metadata">The audio metadata of the track.</param>
/// <param name="trackNumber">The number of the track on its disc.</param>
/// <param name="discNumber">The optional number of the disc the track belongs to.</param>
/// <param name="isrcs">The list of ISRC of the track.</param>
/// <param name="script">The optional script used by the language of the track.</param>
/// <param name="key">The optional musical key of the track.</param>
/// <param name="bpm">The optional tempo of the track in beats per minute.</param>
/// <param name="moods">The list of moods of the track.</param>
/// <param name="work">The optional title of the work the track is a recording of.</param>
/// <param name="musicBrainzRecordingId">The optional MusicBrainz identifier of the recording.</param>
/// <param name="musicBrainzTrackId">The optional MusicBrainz identifier of the track.</param>
/// <param name="musicBrainzWorkId">The optional MusicBrainz identifier of the work.</param>
/// <param name="credits">The list of the credits of the media contributors of the track.</param>
/// <param name="ratings">The list of ratings for the track.</param>
private Track(
TrackId id,
LibraryId libraryId,
string path,
AudioMetadata metadata,
int trackNumber,
Optional<int> discNumber,
List<Isrc> isrcs,
Optional<string> script,
Optional<MusicKey> key,
Optional<int> bpm,
List<Mood> moods,
Optional<string> work,
Optional<MusicBrainzId> musicBrainzRecordingId,
Optional<MusicBrainzId> musicBrainzTrackId,
Optional<MusicBrainzId> musicBrainzWorkId,
List<MediaContributorCredit> credits,
List<AudioRating> ratings) : base(id)
{
Id = id;
LibraryId = libraryId;
Path = path;
Metadata = metadata;
TrackNumber = trackNumber;
DiscNumber = discNumber;
_isrcs = isrcs;
_moods = moods;
Script = script;
Key = key;
Bpm = bpm;
Work = work;
MusicBrainzRecordingId = musicBrainzRecordingId;
MusicBrainzTrackId = musicBrainzTrackId;
MusicBrainzWorkId = musicBrainzWorkId;
_credits = credits;
_ratings = ratings;
}
/// <summary>
/// Creates a new instance of the <see cref="Track"/> class.
/// </summary>
/// <param name="libraryId">The Id of the media library this track belongs to.</param>
/// <param name="path">The file system path of the track.</param>
/// <param name="metadata">The audio metadata of the track.</param>
/// <param name="trackNumber">The number of the track on its disc.</param>
/// <param name="discNumber">The optional number of the disc the track belongs to.</param>
/// <param name="isrcs">The list of ISRC of the track.</param>
/// <param name="script">The optional script used by the language of the track.</param>
/// <param name="key">The optional musical key of the track.</param>
/// <param name="bpm">The optional tempo of the track in beats per minute.</param>
/// <param name="moods">The list of moods of the track.</param>
/// <param name="work">The optional title of the work the track is a recording of.</param>
/// <param name="musicBrainzRecordingId">The optional MusicBrainz identifier of the recording.</param>
/// <param name="musicBrainzTrackId">The optional MusicBrainz identifier of the track.</param>
/// <param name="musicBrainzWorkId">The optional MusicBrainz identifier of the work.</param>
/// <param name="credits">The list of the credits of the media contributors of the track.</param>
/// <param name="ratings">The list of ratings for the track.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Track"/>, or an error message.
/// </returns>
public static Result<Track> Create(
LibraryId libraryId,
string path,
AudioMetadata metadata,
int trackNumber,
Optional<int> discNumber,
List<Isrc> isrcs,
Optional<string> script,
Optional<MusicKey> key,
Optional<int> bpm,
List<Mood> moods,
Optional<string> work,
Optional<MusicBrainzId> musicBrainzRecordingId,
Optional<MusicBrainzId> musicBrainzTrackId,
Optional<MusicBrainzId> musicBrainzWorkId,
List<MediaContributorCredit> credits,
List<AudioRating> ratings)
{
return new Track(
TrackId.CreateUnique(),
libraryId,
path,
metadata,
trackNumber,
discNumber,
isrcs,
script,
key,
bpm,
moods,
work,
musicBrainzRecordingId,
musicBrainzTrackId,
musicBrainzWorkId,
credits,
ratings);
}
/// <summary>
/// Creates a new instance of the <see cref="Track"/> class, with a pre-existing <paramref name="id"/>.
/// </summary>
/// <param name="id">The object representing the unique identifier of the track.</param>
/// <param name="libraryId">The Id of the media library this track belongs to.</param>
/// <param name="path">The file system path of the track.</param>
/// <param name="metadata">The audio metadata of the track.</param>
/// <param name="trackNumber">The number of the track on its disc.</param>
/// <param name="discNumber">The optional number of the disc the track belongs to.</param>
/// <param name="isrcs">The list of ISRC of the track.</param>
/// <param name="script">The optional script used by the language of the track.</param>
/// <param name="key">The optional musical key of the track.</param>
/// <param name="bpm">The optional tempo of the track in beats per minute.</param>
/// <param name="moods">The list of moods of the track.</param>
/// <param name="work">The optional title of the work the track is a recording of.</param>
/// <param name="musicBrainzRecordingId">The optional MusicBrainz identifier of the recording.</param>
/// <param name="musicBrainzTrackId">The optional MusicBrainz identifier of the track.</param>
/// <param name="musicBrainzWorkId">The optional MusicBrainz identifier of the work.</param>
/// <param name="credits">The list of the credits of the media contributors of the track.</param>
/// <param name="ratings">The list of ratings for the track.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Track"/>, or an error message.
/// </returns>
public static Result<Track> Create(
TrackId id,
LibraryId libraryId,
string path,
AudioMetadata metadata,
int trackNumber,
Optional<int> discNumber,
List<Isrc> isrcs,
Optional<string> script,
Optional<MusicKey> key,
Optional<int> bpm,
List<Mood> moods,
Optional<string> work,
Optional<MusicBrainzId> musicBrainzRecordingId,
Optional<MusicBrainzId> musicBrainzTrackId,
Optional<MusicBrainzId> musicBrainzWorkId,
List<MediaContributorCredit> credits,
List<AudioRating> ratings)
{
return new Track(
id,
libraryId,
path,
metadata,
trackNumber,
discNumber,
isrcs,
script,
key,
bpm,
moods,
work,
musicBrainzRecordingId,
musicBrainzTrackId,
musicBrainzWorkId,
credits,
ratings);
}
/// <summary>
/// Replaces the credits of the media contributors of the track with the provided <paramref name="credits"/>.
/// </summary>
/// <param name="credits">The credits of the media contributors of the track.</param>
public void UpdateCredits(IReadOnlyCollection<MediaContributorCredit> credits)
{
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
_credits.Clear();
_credits.AddRange(credits);
}
}
@@ -0,0 +1,51 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the Id of an album.
/// </summary>
[DebuggerDisplay("{Value}")]
public sealed class AlbumId : EntityId<Guid>
{
/// <summary>
/// Initializes a new instance of the <see cref="AlbumId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private AlbumId(Guid value) : base(value)
{
}
/// <summary>
/// Creates a new instance of the <see cref="AlbumId"/> class.
/// </summary>
/// <returns>The created <see cref="AlbumId"/> instance.</returns>
public static AlbumId CreateUnique()
{
return new AlbumId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="AlbumId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="AlbumId"/> instance.</param>
/// <returns>The created <see cref="AlbumId"/> instance.</returns>
public static AlbumId Create(Guid value)
{
return new AlbumId(value);
}
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
}
@@ -0,0 +1,133 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the metadata of an album.
/// </summary>
[DebuggerDisplay("{Title}")]
public class AlbumMetadata : BaseMetadata
{
/// <summary>
/// Gets the type of the release, if applicable.
/// </summary>
public Optional<MusicReleaseType> ReleaseType { get; }
/// <summary>
/// Gets the status of the release, if applicable.
/// </summary>
public Optional<MusicReleaseStatus> ReleaseStatus { get; }
/// <summary>
/// Gets the number of discs of the release, if applicable.
/// </summary>
public Optional<int> TotalDiscs { get; }
/// <summary>
/// Gets the number of tracks of the release.
/// </summary>
public int TotalTracks { get; }
/// <summary>
/// Initializes a new instance of the <see cref="AlbumMetadata"/> class.
/// </summary>
/// <param name="title">The title of the album.</param>
/// <param name="originalTitle">The optional original title of the album, if applicable.</param>
/// <param name="description">The description of the album, if applicable.</param>
/// <param name="releaseInfo">The release information of the album.</param>
/// <param name="genres">The genres of the album.</param>
/// <param name="tags">The tags associated with the album.</param>
/// <param name="language">The language of the album, if applicable.</param>
/// <param name="originalLanguage">The optional original language of the album, if applicable.</param>
/// <param name="releaseType">The optional type of the release.</param>
/// <param name="releaseStatus">The optional status of the release.</param>
/// <param name="totalDiscs">The optional number of discs of the release.</param>
/// <param name="totalTracks">The number of tracks of the release.</param>
private AlbumMetadata(
string title,
Optional<string> originalTitle,
Optional<string> description,
ReleaseInfo releaseInfo,
List<Genre> genres,
List<Tag> tags,
Optional<LanguageInfo> language,
Optional<LanguageInfo> originalLanguage,
Optional<MusicReleaseType> releaseType,
Optional<MusicReleaseStatus> releaseStatus,
Optional<int> totalDiscs,
int totalTracks)
: base(title, originalTitle, description, releaseInfo, genres, tags, language, originalLanguage)
{
ReleaseType = releaseType;
ReleaseStatus = releaseStatus;
TotalDiscs = totalDiscs;
TotalTracks = totalTracks;
}
/// <summary>
/// Creates a new instance of the <see cref="AlbumMetadata"/> class.
/// </summary>
/// <param name="title">The title of the album.</param>
/// <param name="originalTitle">The optional original title of the album, if applicable.</param>
/// <param name="description">The description of the album, if applicable.</param>
/// <param name="releaseInfo">The release information of the album.</param>
/// <param name="genres">The genres of the album.</param>
/// <param name="tags">The tags associated with the album.</param>
/// <param name="language">The language of the album, if applicable.</param>
/// <param name="originalLanguage">The optional original language of the album, if applicable.</param>
/// <param name="releaseType">The optional type of the release.</param>
/// <param name="releaseStatus">The optional status of the release.</param>
/// <param name="totalDiscs">The optional number of discs of the release.</param>
/// <param name="totalTracks">The number of tracks of the release.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="AlbumMetadata"/>, or an error message.
/// </returns>
public static Result<AlbumMetadata> Create(
string title,
Optional<string> originalTitle,
Optional<string> description,
ReleaseInfo releaseInfo,
List<Genre> genres,
List<Tag> tags,
Optional<LanguageInfo> language,
Optional<LanguageInfo> originalLanguage,
Optional<MusicReleaseType> releaseType,
Optional<MusicReleaseStatus> releaseStatus,
Optional<int> totalDiscs,
int totalTracks)
{
return new AlbumMetadata(
title,
originalTitle,
description,
releaseInfo,
genres,
tags,
language,
originalLanguage,
releaseType,
releaseStatus,
totalDiscs,
totalTracks);
}
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
public override IEnumerable<object> GetEqualityComponents()
{
foreach (object component in base.GetEqualityComponents())
yield return component;
yield return ReleaseType;
yield return ReleaseStatus;
yield return TotalDiscs;
yield return TotalTracks;
}
}
@@ -0,0 +1,51 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the Id of an artist.
/// </summary>
[DebuggerDisplay("{Value}")]
public sealed class ArtistId : EntityId<Guid>
{
/// <summary>
/// Initializes a new instance of the <see cref="ArtistId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private ArtistId(Guid value) : base(value)
{
}
/// <summary>
/// Creates a new instance of the <see cref="ArtistId"/> class.
/// </summary>
/// <returns>The created <see cref="ArtistId"/> instance.</returns>
public static ArtistId CreateUnique()
{
return new ArtistId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="ArtistId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="ArtistId"/> instance.</param>
/// <returns>The created <see cref="ArtistId"/> instance.</returns>
public static ArtistId Create(Guid value)
{
return new ArtistId(value);
}
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
}
@@ -0,0 +1,61 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the barcode of an album.
/// </summary>
[DebuggerDisplay("{Value}")]
public sealed class Barcode : ValueObject
{
private static readonly Regex s_barcodeRegex = new(@"^\d{12,13}$", RegexOptions.Compiled);
/// <summary>
/// Gets the value of the barcode.
/// </summary>
public string Value { get; }
/// <summary>
/// Initializes a new instance of the <see cref="Barcode"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private Barcode(string value)
{
Value = value;
}
/// <summary>
/// Creates a new instance of the <see cref="Barcode"/> class.
/// </summary>
/// <param name="value">The value of the barcode.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Barcode"/>, or an error message.
/// </returns>
public static Result<Barcode> Create(string? value)
{
if (string.IsNullOrWhiteSpace(value))
return Errors.Music.BarcodeValueCannotBeEmpty;
string cleanedValue = value.Trim();
if (!s_barcodeRegex.IsMatch(cleanedValue))
return Errors.Music.InvalidFormatForBarcode;
return new Barcode(cleanedValue);
}
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
}
@@ -0,0 +1,61 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the ISRC (International Standard Recording Code) of a track.
/// </summary>
[DebuggerDisplay("{Value}")]
public sealed class Isrc : ValueObject
{
private static readonly Regex s_isrcRegex = new(@"^[A-Z]{2}[A-Z0-9]{3}[0-9]{7}$", RegexOptions.Compiled);
/// <summary>
/// Gets the value of the ISRC.
/// </summary>
public string Value { get; }
/// <summary>
/// Initializes a new instance of the <see cref="Isrc"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private Isrc(string value)
{
Value = value;
}
/// <summary>
/// Creates a new instance of the <see cref="Isrc"/> class.
/// </summary>
/// <param name="value">The value of the ISRC.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Isrc"/>, or an error message.
/// </returns>
public static Result<Isrc> Create(string? value)
{
if (string.IsNullOrWhiteSpace(value))
return Errors.Music.IsrcValueCannotBeEmpty;
string cleanedValue = value.Trim().ToUpperInvariant();
if (!s_isrcRegex.IsMatch(cleanedValue))
return Errors.Music.IsrcInvalidFormat;
return new Isrc(cleanedValue);
}
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
}
@@ -0,0 +1,76 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.MediaContributorBoundedContext.MediaContributorAggregate;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the credit of a media contributor in a music media element, carrying the role the contributor played.
/// The role carries both a free-form display name, as returned by the metadata providers, and the canonical category
/// the display name normalizes to, so that roles describing the same kind of contribution are never treated as distinct.
/// </summary>
[DebuggerDisplay("{RoleDisplayName}")]
public sealed class MediaContributorCredit : ValueObject
{
/// <summary>
/// Gets the unique identifier of the credited media contributor.
/// </summary>
public MediaContributorId ContributorId { get; }
/// <summary>
/// Gets the display name of the role the contributor played.
/// </summary>
public string RoleDisplayName { get; }
/// <summary>
/// Gets the canonical category of the role the contributor played.
/// </summary>
public MediaContributorRoleCategory RoleCategory { get; }
/// <summary>
/// Initializes a new instance of the <see cref="MediaContributorCredit"/> class.
/// </summary>
/// <param name="contributorId">The unique identifier of the credited media contributor.</param>
/// <param name="roleDisplayName">The display name of the role the contributor played.</param>
/// <param name="roleCategory">The canonical category of the role the contributor played.</param>
private MediaContributorCredit(MediaContributorId contributorId, string roleDisplayName, MediaContributorRoleCategory roleCategory)
{
ContributorId = contributorId;
RoleDisplayName = roleDisplayName;
RoleCategory = roleCategory;
}
/// <summary>
/// Creates a new instance of the <see cref="MediaContributorCredit"/> class.
/// </summary>
/// <param name="contributorId">The unique identifier of the credited media contributor.</param>
/// <param name="roleDisplayName">The display name of the role the contributor played.</param>
/// <param name="roleCategory">The canonical category of the role the contributor played.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="MediaContributorCredit"/>, or an error message.
/// </returns>
public static Result<MediaContributorCredit> Create(MediaContributorId contributorId, string roleDisplayName, MediaContributorRoleCategory roleCategory)
{
if (string.IsNullOrWhiteSpace(roleDisplayName))
return Errors.Music.CreditRoleDisplayNameCannotBeEmpty;
return new MediaContributorCredit(contributorId, roleDisplayName, roleCategory);
}
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
public override IEnumerable<object> GetEqualityComponents()
{
yield return ContributorId;
yield return RoleDisplayName;
yield return RoleCategory;
}
}
@@ -0,0 +1,67 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for a MusicBrainz identifier.
/// </summary>
[DebuggerDisplay("{Value}")]
public sealed class MusicBrainzId : ValueObject
{
/// <summary>
/// Gets the unique identifier assigned by MusicBrainz.
/// </summary>
public Guid Value { get; }
/// <summary>
/// Initializes a new instance of the <see cref="MusicBrainzId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private MusicBrainzId(Guid value)
{
Value = value;
}
/// <summary>
/// Creates a new instance of the <see cref="MusicBrainzId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="MusicBrainzId"/> instance.</param>
/// <returns>The created <see cref="MusicBrainzId"/> instance.</returns>
public static Result<MusicBrainzId> Create(Guid value)
{
return new MusicBrainzId(value);
}
/// <summary>
/// Creates a new instance of the <see cref="MusicBrainzId"/> class, from a <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="MusicBrainzId"/> instance.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="MusicBrainzId"/>, or an error message.
/// </returns>
public static Result<MusicBrainzId> Create(string? value)
{
if (string.IsNullOrWhiteSpace(value))
return Errors.Music.MusicBrainzIdInvalidFormat;
if (!Guid.TryParse(value, out Guid parsedValue))
return Errors.Music.MusicBrainzIdInvalidFormat;
return new MusicBrainzId(parsedValue);
}
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
}
@@ -0,0 +1,51 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the Id of a track.
/// </summary>
[DebuggerDisplay("{Value}")]
public sealed class TrackId : EntityId<Guid>
{
/// <summary>
/// Initializes a new instance of the <see cref="TrackId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private TrackId(Guid value) : base(value)
{
}
/// <summary>
/// Creates a new instance of the <see cref="TrackId"/> class.
/// </summary>
/// <returns>The created <see cref="TrackId"/> instance.</returns>
public static TrackId CreateUnique()
{
return new TrackId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="TrackId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="TrackId"/> instance.</param>
/// <returns>The created <see cref="TrackId"/> instance.</returns>
public static TrackId Create(Guid value)
{
return new TrackId(value);
}
/// <summary>
/// Gets the list of items that define equality of the object.
/// </summary>
/// <returns>A list of items defining the equality.</returns>
public override IEnumerable<object> GetEqualityComponents()
{
yield return Value;
}
}
@@ -2,6 +2,7 @@
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Diagnostics;
#endregion
@@ -9,14 +10,20 @@ using System.Diagnostics;
namespace Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate;
/// <summary>
/// Aggregate root for a media contributor, the person that contributed to a media item.
/// A media contributor is a person, unique by name, agnostic of the kind of media it contributed to, and of
/// the roles it played in the media items. The roles a contributor plays are tracked per media item, so that a
/// single contributor that is both an actor and a writer is never duplicated.
/// Aggregate root for a media contributor.
/// </summary>
/// <remarks>
/// A media contributor can be a single person or a group of people, like a band, and is unique by name, agnostic of the kind of media it contributed to, and of the roles
/// it played in the media items. The roles a contributor plays are tracked per media item, so that a single contributor that is both an actor and a writer is never duplicated.
/// </remarks>
[DebuggerDisplay("{Id}: {Name}")]
public class MediaContributor : AggregateRoot<MediaContributorId>
{
/// <summary>
/// Gets the type of the contributor, whether it is a person, a group, or an organization.
/// </summary>
public MediaContributorType Type { get; private set; }
/// <summary>
/// Gets the name of the contributor.
/// </summary>
@@ -41,18 +48,21 @@ public class MediaContributor : AggregateRoot<MediaContributorId>
/// Initializes a new instance of the <see cref="MediaContributor"/> class.
/// </summary>
/// <param name="id">The unique identifier of the contributor.</param>
/// <param name="type">The type of the contributor.</param>
/// <param name="name">The name of the contributor.</param>
/// <param name="biography">The optional biography of the contributor.</param>
/// <param name="dateOfBirth">The optional date of birth of the contributor.</param>
/// <param name="dateOfDeath">The optional date of death of the contributor.</param>
private MediaContributor(
MediaContributorId id,
MediaContributorType type,
MediaContributorName name,
Optional<string> biography,
Optional<DateOnly> dateOfBirth,
Optional<DateOnly> dateOfDeath) : base(id)
{
Id = id;
Type = type;
Name = name;
Biography = biography;
DateOfBirth = dateOfBirth;
@@ -62,12 +72,14 @@ public class MediaContributor : AggregateRoot<MediaContributorId>
/// <summary>
/// Creates a new instance of the <see cref="MediaContributor"/> class.
/// </summary>
/// <param name="type">The type of the contributor.</param>
/// <param name="name">The name of the contributor.</param>
/// <returns>The created <see cref="MediaContributor"/> instance.</returns>
public static Result<MediaContributor> Create(MediaContributorName name)
public static Result<MediaContributor> Create(MediaContributorType type, MediaContributorName name)
{
return new MediaContributor(
MediaContributorId.CreateUnique(),
type,
name,
Optional<string>.None(),
Optional<DateOnly>.None(),
@@ -78,6 +90,7 @@ public class MediaContributor : AggregateRoot<MediaContributorId>
/// Creates a new instance of the <see cref="MediaContributor"/> class, from a pre-existing <paramref name="id"/>.
/// </summary>
/// <param name="id">The unique identifier of the contributor.</param>
/// <param name="type">The type of the contributor.</param>
/// <param name="name">The name of the contributor.</param>
/// <param name="biography">The optional biography of the contributor.</param>
/// <param name="dateOfBirth">The optional date of birth of the contributor.</param>
@@ -85,11 +98,12 @@ public class MediaContributor : AggregateRoot<MediaContributorId>
/// <returns>The created <see cref="MediaContributor"/> instance.</returns>
public static Result<MediaContributor> Create(
MediaContributorId id,
MediaContributorType type,
MediaContributorName name,
Optional<string> biography,
Optional<DateOnly> dateOfBirth,
Optional<DateOnly> dateOfDeath)
{
return new MediaContributor(id, name, biography, dateOfBirth, dateOfDeath);
return new MediaContributor(id, type, name, biography, dateOfBirth, dateOfDeath);
}
}
@@ -1,16 +0,0 @@
#region ========================================================================= USING =====================================================================================
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.Services;
/// <summary>
/// Interface for the service for managing movie libraries.
/// </summary>
public interface IMovieLibraryService
{
/// <summary>
/// Gets the collection of movies in the library.
/// </summary>
public ICollection<Movie> Movies { get; }
}
@@ -1,17 +0,0 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.Services;
/// <summary>
/// Service for managing movie libraries.
/// </summary>
public sealed class MovieLibraryService : IMovieLibraryService
{
/// <summary>
/// Gets the collection of movies in the library.
/// </summary>
public ICollection<Movie> Movies => throw new NotImplementedException();
}
@@ -1,22 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.Services;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.Services;
/// <summary>
/// Interface for the service for managing video content.
/// </summary>
public interface IVideoLibraryService
{
/// <summary>
/// Gets the service for managing a movie library.
/// </summary>
public IMovieLibraryService MovieLibraryService { get; }
/// <summary>
/// Gets the service for managing a TV shows library.
/// </summary>
public ITvShowLibraryService TvShowLibraryService { get; }
}
@@ -1,33 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.Services;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.Services;
/// <summary>
/// Service for managing video content.
/// </summary>
public class VideoLibraryService : IVideoLibraryService
{
/// <summary>
/// Gets the service for managing a movie library.
/// </summary>
public IMovieLibraryService MovieLibraryService { get; private set; }
/// <summary>
/// Gets the service for managing a TV shows library.
/// </summary>
public ITvShowLibraryService TvShowLibraryService { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="VideoLibraryService"/> class.
/// </summary>
/// <param name="movieLibraryService">Injected movie library service.</param>
/// <param name="tvShowLibraryService">Injected TV show library service.</param>
public VideoLibraryService(IMovieLibraryService movieLibraryService, ITvShowLibraryService tvShowLibraryService)
{
MovieLibraryService = movieLibraryService;
TvShowLibraryService = tvShowLibraryService;
}
}
@@ -1,16 +0,0 @@
#region ========================================================================= USING =====================================================================================
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.Services;
/// <summary>
/// Interface for the service for managing TV show libraries.
/// </summary>
public interface ITvShowLibraryService
{
/// <summary>
/// Gets the collection of TV shows in the library.
/// </summary>
public ICollection<TvShow> TvShows { get; }
}
@@ -1,17 +0,0 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.Services;
/// <summary>
/// Service for managing TV show libraries.
/// </summary>
public class TvShowLibraryService : ITvShowLibraryService
{
/// <summary>
/// Gets the collection of TV shows in the library.
/// </summary>
public ICollection<TvShow> TvShows => throw new NotImplementedException();
}
@@ -112,6 +112,9 @@ public sealed class Book : AggregateRoot<BookId>
/// Gets the list of objects representing the unique identifiers of the media contributors (actors, directors, etc) starring in this book.
/// </summary>
public IReadOnlyCollection<MediaContributorId> Contributors => _contributors.AsReadOnly();
// TODO: the roles of the media contributors currently live only in the persistence layer (BookContributorEntity), and are lost
// at the domain level. To keep consistency with the Music aggregate, which models its credits as a MediaContributorCredit value
// object carrying both the contributor and the role, the roles should be moved into the Book aggregate as well.
/// <summary>
/// Gets the list of ratings for this book.
@@ -1,16 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.Services;
/// <summary>
/// Interface for the service for managing written content.
/// </summary>
public interface IWrittenContentLibraryService
{
/// <summary>
/// Gets the service for managing book libraries.
/// </summary>
public IBookLibraryService BookLibraryService { get; }
}
@@ -1,25 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.Services;
/// <summary>
/// Service for managing written content.
/// </summary>
public class WrittenContentLibraryService : IWrittenContentLibraryService
{
/// <summary>
/// Gets the service for managing book libraries.
/// </summary>
public IBookLibraryService BookLibraryService { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="WrittenContentLibraryService"/> class.
/// </summary>
/// <param name="bookLibraryService">Injected book library service.</param>
public WrittenContentLibraryService(IBookLibraryService bookLibraryService)
{
BookLibraryService = bookLibraryService;
}
}