Refactors the book, artist, and album slices across the stack

This commit is contained in:
BinaryAlley committed 2026-09-17 13:30:48 -07:00
1 parent 8aaf9fe64e
commit ea6eb9f796
439 files changed
+28235 -3156

No files matched your search

@@ -19,6 +19,7 @@ public static partial class Errors
public static Error RoleNameMustBeMaximum50CharactersLong => Error.Validation(description: nameof(RoleNameMustBeMaximum50CharactersLong));
public static Error RoleCategoryCannotBeEmpty => Error.Validation(description: nameof(RoleCategoryCannotBeEmpty));
public static Error ContributorRoleCannotBeNull => Error.Validation(description: nameof(ContributorRoleCannotBeNull));
public static Error ContributorsListCannotBeNull => Error.Validation(description: nameof(ContributorsListCannotBeNull));
public static Error MediaContributorIdCannotBeEmpty => Error.Validation(description: nameof(MediaContributorIdCannotBeEmpty));
public static Error MediaContributorNotFound => Error.NotFound(description: nameof(MediaContributorNotFound));
public static Error UnknownMediaContributorRole => Error.Validation(description: nameof(UnknownMediaContributorRole));
@@ -2,7 +2,7 @@
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.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
using System;
@@ -16,16 +16,21 @@ namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLib
/// 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.
/// 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 contributors.
/// </remarks>
[DebuggerDisplay("Id: {Id} Name: {Name}")]
public sealed class Artist : AggregateRoot<ArtistId>
{
private readonly List<MediaContributorCredit> _credits;
private readonly HashSet<MusicMediaContributor> _contributors;
private readonly List<Album> _albums;
/// <summary>
/// Gets the Id of the media library this artist belongs to.
/// </summary>
public LibraryId LibraryId { get; private set; }
/// <summary>
/// Gets the name of the artist.
/// </summary>
@@ -42,14 +47,9 @@ public sealed class Artist : AggregateRoot<ArtistId>
public Optional<MusicBrainzId> MusicBrainzArtistId { get; private set; }
/// <summary>
/// Gets the Id of the media contributor the artist corresponds to, if applicable.
/// Gets the list of the media contributors that make up the artist.
/// </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();
public IReadOnlyCollection<MusicMediaContributor> Contributors => _contributors.AsReadOnly();
/// <summary>
/// Gets the list of albums of the artist.
@@ -60,31 +60,31 @@ public sealed class Artist : AggregateRoot<ArtistId>
/// 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="libraryId">The Id of the media library this artist belongs to.</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="contributors">The list 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,
LibraryId libraryId,
string name,
Optional<string> website,
Optional<MusicBrainzId> musicBrainzArtistId,
Optional<MediaContributorId> mediaContributorId,
List<MediaContributorCredit> credits,
List<MusicMediaContributor> contributors,
List<Album> albums,
DateTime createdOnUtc,
Optional<DateTime> updatedOnUtc) : base(id)
{
Id = id;
LibraryId = libraryId;
Name = name;
Website = website;
MusicBrainzArtistId = musicBrainzArtistId;
MediaContributorId = mediaContributorId;
_credits = credits;
_contributors = [.. contributors];
_albums = albums;
CreatedOnUtc = createdOnUtc;
UpdatedOnUtc = updatedOnUtc.HasValue ? updatedOnUtc.Value : null;
@@ -93,35 +93,37 @@ public sealed class Artist : AggregateRoot<ArtistId>
/// <summary>
/// Creates a new instance of the <see cref="Artist"/> class.
/// </summary>
/// <param name="libraryId">The Id of the media library this artist belongs to.</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="contributors">The list 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(
LibraryId libraryId,
string name,
Optional<string> website,
Optional<MusicBrainzId> musicBrainzArtistId,
Optional<MediaContributorId> mediaContributorId,
List<MediaContributorCredit> credits,
List<MusicMediaContributor> contributors,
List<Album> albums)
{
if (string.IsNullOrWhiteSpace(name))
return Errors.Music.ArtistNameCannotBeEmpty;
if (albums.Count is 0)
return Errors.Music.ArtistMustHaveAtLeastOneAlbum;
return new Artist(
ArtistId.CreateUnique(),
libraryId,
name,
website,
musicBrainzArtistId,
mediaContributorId,
credits,
contributors,
albums,
DateTime.UtcNow,
DateTime.UtcNow, // TODO: should be IDateTimeProvider
Optional<DateTime>.None());
}
@@ -129,11 +131,11 @@ public sealed class Artist : AggregateRoot<ArtistId>
/// 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="libraryId">The Id of the media library this artist belongs to.</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="contributors">The list 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>
@@ -142,25 +144,27 @@ public sealed class Artist : AggregateRoot<ArtistId>
/// </returns>
public static Result<Artist> Create(
ArtistId id,
LibraryId libraryId,
string name,
Optional<string> website,
Optional<MusicBrainzId> musicBrainzArtistId,
Optional<MediaContributorId> mediaContributorId,
List<MediaContributorCredit> credits,
List<MusicMediaContributor> contributors,
List<Album> albums,
DateTime createdOnUtc,
Optional<DateTime> updatedOnUtc)
{
if (string.IsNullOrWhiteSpace(name))
return Errors.Music.ArtistNameCannotBeEmpty;
if (albums.Count is 0)
return Errors.Music.ArtistMustHaveAtLeastOneAlbum;
return new Artist(
id,
libraryId,
name,
website,
musicBrainzArtistId,
mediaContributorId,
credits,
contributors,
albums,
createdOnUtc,
updatedOnUtc);
@@ -188,18 +192,42 @@ public sealed class Artist : AggregateRoot<ArtistId>
{
if (!_albums.Contains(album))
return Errors.Music.TheArtistDoesNotHaveTheAlbum;
if (_albums.Count is 1)
return Errors.Music.ArtistMustHaveAtLeastOneAlbum;
_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"/>.
/// Replaces the media contributors that make up the artist with the provided <paramref name="contributors"/>.
/// </summary>
/// <param name="credits">The credits of the media contributors that make up the artist.</param>
public void UpdateCredits(IReadOnlyCollection<MediaContributorCredit> credits)
/// <param name="contributors">The media contributors that make up the artist.</param>
public void UpdateContributors(IReadOnlyCollection<MusicMediaContributor> contributors)
{
// replace the contents of the collection in place, preserving the readonly reference invariants of the aggregate
_credits.Clear();
_credits.AddRange(credits);
_contributors.Clear();
_contributors.UnionWith(contributors);
}
/// <summary>
/// Updates the details of the artist, without touching the albums and the media contributors.
/// </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>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public Result<Updated> UpdateDetails(
string name,
Optional<string> website,
Optional<MusicBrainzId> musicBrainzArtistId)
{
if (string.IsNullOrWhiteSpace(name))
return Errors.Music.ArtistNameCannotBeEmpty;
Name = name;
Website = website;
MusicBrainzArtistId = musicBrainzArtistId;
UpdatedOnUtc = DateTime.UtcNow;
return Result.Updated;
}
}
@@ -5,6 +5,7 @@ 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;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -17,7 +18,7 @@ namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLib
[DebuggerDisplay("{Id}: {Metadata.Title}")]
public sealed class Album : Entity<AlbumId>
{
private readonly List<MediaContributorCredit> _credits;
private readonly List<MusicMediaContributor> _contributors;
private readonly List<AudioRating> _ratings;
private readonly List<Track> _tracks;
@@ -57,9 +58,9 @@ public sealed class Album : Entity<AlbumId>
public Optional<MusicBrainzId> MusicBrainzReleaseArtistId { get; private set; }
/// <summary>
/// Gets the list of the credits of the media contributors of the album.
/// Gets the list of the media contributors of the album.
/// </summary>
public IReadOnlyCollection<MediaContributorCredit> Credits => _credits.AsReadOnly();
public IReadOnlyCollection<MusicMediaContributor> Contributors => _contributors.AsReadOnly();
/// <summary>
/// Gets the list of ratings for this album.
@@ -82,9 +83,11 @@ public sealed class Album : Entity<AlbumId>
/// <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="contributors">The list 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>
/// <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 Album(
AlbumId id,
AlbumMetadata metadata,
@@ -94,9 +97,11 @@ public sealed class Album : Entity<AlbumId>
Optional<MusicBrainzId> musicBrainzReleaseId,
Optional<MusicBrainzId> musicBrainzReleaseGroupId,
Optional<MusicBrainzId> musicBrainzReleaseArtistId,
List<MediaContributorCredit> credits,
List<MusicMediaContributor> contributors,
List<AudioRating> ratings,
List<Track> tracks) : base(id)
List<Track> tracks,
DateTime createdOnUtc,
Optional<DateTime> updatedOnUtc) : base(id)
{
Id = id;
Metadata = metadata;
@@ -106,9 +111,11 @@ public sealed class Album : Entity<AlbumId>
MusicBrainzReleaseId = musicBrainzReleaseId;
MusicBrainzReleaseGroupId = musicBrainzReleaseGroupId;
MusicBrainzReleaseArtistId = musicBrainzReleaseArtistId;
_credits = credits;
_contributors = contributors;
_ratings = ratings;
_tracks = tracks;
CreatedOnUtc = createdOnUtc;
UpdatedOnUtc = updatedOnUtc.HasValue ? updatedOnUtc.Value : null;
}
/// <summary>
@@ -121,7 +128,7 @@ public sealed class Album : Entity<AlbumId>
/// <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="contributors">The list 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>
@@ -135,7 +142,7 @@ public sealed class Album : Entity<AlbumId>
Optional<MusicBrainzId> musicBrainzReleaseId,
Optional<MusicBrainzId> musicBrainzReleaseGroupId,
Optional<MusicBrainzId> musicBrainzReleaseArtistId,
List<MediaContributorCredit> credits,
List<MusicMediaContributor> contributors,
List<AudioRating> ratings,
List<Track> tracks)
{
@@ -148,9 +155,11 @@ public sealed class Album : Entity<AlbumId>
musicBrainzReleaseId,
musicBrainzReleaseGroupId,
musicBrainzReleaseArtistId,
credits,
contributors,
ratings,
tracks);
tracks,
DateTime.UtcNow, // TODO: should be IDateTimeProvider
Optional<DateTime>.None());
}
/// <summary>
@@ -164,9 +173,11 @@ public sealed class Album : Entity<AlbumId>
/// <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="contributors">The list 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>
/// <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="Album"/>, or an error message.
/// </returns>
@@ -179,9 +190,11 @@ public sealed class Album : Entity<AlbumId>
Optional<MusicBrainzId> musicBrainzReleaseId,
Optional<MusicBrainzId> musicBrainzReleaseGroupId,
Optional<MusicBrainzId> musicBrainzReleaseArtistId,
List<MediaContributorCredit> credits,
List<MusicMediaContributor> contributors,
List<AudioRating> ratings,
List<Track> tracks)
List<Track> tracks,
DateTime createdOnUtc,
Optional<DateTime> updatedOnUtc)
{
return new Album(
id,
@@ -192,9 +205,11 @@ public sealed class Album : Entity<AlbumId>
musicBrainzReleaseId,
musicBrainzReleaseGroupId,
musicBrainzReleaseArtistId,
credits,
contributors,
ratings,
tracks);
tracks,
createdOnUtc,
updatedOnUtc);
}
/// <summary>
@@ -224,13 +239,55 @@ public sealed class Album : Entity<AlbumId>
}
/// <summary>
/// Replaces the credits of the media contributors of the album with the provided <paramref name="credits"/>.
/// Replaces the media contributors of the album with the provided <paramref name="contributors"/>.
/// </summary>
/// <param name="credits">The credits of the media contributors of the album.</param>
public void UpdateCredits(IReadOnlyCollection<MediaContributorCredit> credits)
/// <param name="contributors">The media contributors of the album.</param>
public void UpdateContributors(IReadOnlyCollection<MusicMediaContributor> contributors)
{
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
_credits.Clear();
_credits.AddRange(credits);
_contributors.Clear();
_contributors.AddRange(contributors);
}
/// <summary>
/// Replaces the ratings of the album with the provided <paramref name="ratings"/>.
/// </summary>
/// <param name="ratings">The ratings of the album.</param>
public void UpdateRatings(IReadOnlyCollection<AudioRating> ratings)
{
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
_ratings.Clear();
_ratings.AddRange(ratings);
}
/// <summary>
/// Updates the details of the album, without touching the ratings, the media contributors, and the tracks.
/// </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>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public Result<Updated> UpdateDetails(
AlbumMetadata metadata,
Optional<MusicMediaFormat> mediaFormat,
Optional<Barcode> barcode,
Optional<string> catalogNumber,
Optional<MusicBrainzId> musicBrainzReleaseId,
Optional<MusicBrainzId> musicBrainzReleaseGroupId,
Optional<MusicBrainzId> musicBrainzReleaseArtistId)
{
Metadata = metadata;
MediaFormat = mediaFormat;
Barcode = barcode;
CatalogNumber = catalogNumber;
MusicBrainzReleaseId = musicBrainzReleaseId;
MusicBrainzReleaseGroupId = musicBrainzReleaseGroupId;
MusicBrainzReleaseArtistId = musicBrainzReleaseArtistId;
UpdatedOnUtc = DateTime.UtcNow;
return Result.Updated;
}
}
@@ -6,6 +6,7 @@ using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.Value
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;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
@@ -20,14 +21,9 @@ public sealed class Track : Entity<TrackId>
{
private readonly List<Isrc> _isrcs;
private readonly List<Mood> _moods;
private readonly List<MediaContributorCredit> _credits;
private readonly List<MusicMediaContributor> _contributors;
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>
@@ -94,9 +90,9 @@ public sealed class Track : Entity<TrackId>
public IReadOnlyCollection<Isrc> Isrcs => _isrcs.AsReadOnly();
/// <summary>
/// Gets the list of the credits of the media contributors of the track.
/// Gets the list of the media contributors of the track.
/// </summary>
public IReadOnlyCollection<MediaContributorCredit> Credits => _credits.AsReadOnly();
public IReadOnlyCollection<MusicMediaContributor> Contributors => _contributors.AsReadOnly();
/// <summary>
/// Gets the list of ratings for this track.
@@ -107,7 +103,6 @@ public sealed class Track : Entity<TrackId>
/// 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>
@@ -121,11 +116,10 @@ public sealed class Track : Entity<TrackId>
/// <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="contributors">The list 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,
@@ -139,11 +133,10 @@ public sealed class Track : Entity<TrackId>
Optional<MusicBrainzId> musicBrainzRecordingId,
Optional<MusicBrainzId> musicBrainzTrackId,
Optional<MusicBrainzId> musicBrainzWorkId,
List<MediaContributorCredit> credits,
List<MusicMediaContributor> contributors,
List<AudioRating> ratings) : base(id)
{
Id = id;
LibraryId = libraryId;
Path = path;
Metadata = metadata;
TrackNumber = trackNumber;
@@ -157,14 +150,13 @@ public sealed class Track : Entity<TrackId>
MusicBrainzRecordingId = musicBrainzRecordingId;
MusicBrainzTrackId = musicBrainzTrackId;
MusicBrainzWorkId = musicBrainzWorkId;
_credits = credits;
_contributors = contributors;
_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>
@@ -178,13 +170,12 @@ public sealed class Track : Entity<TrackId>
/// <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="contributors">The list 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,
@@ -198,12 +189,11 @@ public sealed class Track : Entity<TrackId>
Optional<MusicBrainzId> musicBrainzRecordingId,
Optional<MusicBrainzId> musicBrainzTrackId,
Optional<MusicBrainzId> musicBrainzWorkId,
List<MediaContributorCredit> credits,
List<MusicMediaContributor> contributors,
List<AudioRating> ratings)
{
return new Track(
TrackId.CreateUnique(),
libraryId,
path,
metadata,
trackNumber,
@@ -217,7 +207,7 @@ public sealed class Track : Entity<TrackId>
musicBrainzRecordingId,
musicBrainzTrackId,
musicBrainzWorkId,
credits,
contributors,
ratings);
}
@@ -225,7 +215,6 @@ public sealed class Track : Entity<TrackId>
/// 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>
@@ -239,14 +228,13 @@ public sealed class Track : Entity<TrackId>
/// <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="contributors">The list 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,
@@ -260,12 +248,11 @@ public sealed class Track : Entity<TrackId>
Optional<MusicBrainzId> musicBrainzRecordingId,
Optional<MusicBrainzId> musicBrainzTrackId,
Optional<MusicBrainzId> musicBrainzWorkId,
List<MediaContributorCredit> credits,
List<MusicMediaContributor> contributors,
List<AudioRating> ratings)
{
return new Track(
id,
libraryId,
path,
metadata,
trackNumber,
@@ -279,18 +266,72 @@ public sealed class Track : Entity<TrackId>
musicBrainzRecordingId,
musicBrainzTrackId,
musicBrainzWorkId,
credits,
contributors,
ratings);
}
/// <summary>
/// Replaces the credits of the media contributors of the track with the provided <paramref name="credits"/>.
/// Replaces the media contributors of the track with the provided <paramref name="contributors"/>.
/// </summary>
/// <param name="credits">The credits of the media contributors of the track.</param>
public void UpdateCredits(IReadOnlyCollection<MediaContributorCredit> credits)
/// <param name="contributors">The media contributors of the track.</param>
public void UpdateContributors(IReadOnlyCollection<MusicMediaContributor> contributors)
{
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
_credits.Clear();
_credits.AddRange(credits);
_contributors.Clear();
_contributors.AddRange(contributors);
}
/// <summary>
/// Replaces the ratings of the track with the provided <paramref name="ratings"/>.
/// </summary>
/// <param name="ratings">The ratings of the track.</param>
public void UpdateRatings(IReadOnlyCollection<AudioRating> ratings)
{
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
_ratings.Clear();
_ratings.AddRange(ratings);
}
/// <summary>
/// Updates the details of the track, without touching the moods, the ISRCs, the media contributors, and the ratings.
/// </summary>
/// <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="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="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>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public Result<Updated> UpdateDetails(
string path,
AudioMetadata metadata,
int trackNumber,
Optional<int> discNumber,
Optional<string> script,
Optional<MusicKey> key,
Optional<int> bpm,
Optional<string> work,
Optional<MusicBrainzId> musicBrainzRecordingId,
Optional<MusicBrainzId> musicBrainzTrackId,
Optional<MusicBrainzId> musicBrainzWorkId)
{
Path = path;
Metadata = metadata;
TrackNumber = trackNumber;
DiscNumber = discNumber;
Script = script;
Key = key;
Bpm = bpm;
Work = work;
MusicBrainzRecordingId = musicBrainzRecordingId;
MusicBrainzTrackId = musicBrainzTrackId;
MusicBrainzWorkId = musicBrainzWorkId;
UpdatedOnUtc = DateTime.UtcNow;
return Result.Updated;
}
}
@@ -36,6 +36,9 @@ public sealed class MusicBrainzId : ValueObject
/// <returns>The created <see cref="MusicBrainzId"/> instance.</returns>
public static Result<MusicBrainzId> Create(Guid value)
{
if (value == Guid.Empty)
return Errors.Music.MusicBrainzIdInvalidFormat;
return new MusicBrainzId(value);
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
@@ -19,7 +18,7 @@ namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext
[DebuggerDisplay("Id: {Id} Title: {Title}")]
public sealed class Book : AggregateRoot<BookId>
{
private readonly List<MediaContributorId> _contributors;
private readonly HashSet<BookMediaContributor> _contributors;
private readonly List<BookRating> _ratings;
private readonly List<Isbn> _isbns;
@@ -109,12 +108,10 @@ public sealed class Book : AggregateRoot<BookId>
public IReadOnlyCollection<Isbn> ISBNs => _isbns.AsReadOnly();
/// <summary>
/// Gets the list of objects representing the unique identifiers of the media contributors (actors, directors, etc) starring in this book.
/// Gets the list of media contributors that contributed to this book, each carrying the role
/// the contributor played, used as the key of its localized display string.
/// </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.
public IReadOnlyCollection<BookMediaContributor> Contributors => _contributors.AsReadOnly();
/// <summary>
/// Gets the list of ratings for this book.
@@ -144,7 +141,7 @@ public sealed class Book : AggregateRoot<BookId>
/// <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>
/// <param name="isbns">The list of ISBNs of the book.</param>
/// <param name="contributors">The list of objects representing the unique identifiers of the media contributors of the book.</param>
/// <param name="contributors">The list of media contributors of the book, each carrying the role the contributor played.</param>
/// <param name="ratings">The list of ratings for the book.</param>
private Book(
BookId id,
@@ -167,7 +164,7 @@ public sealed class Book : AggregateRoot<BookId>
DateTime createdOnUtc,
Optional<DateTime> updatedOnUtc,
List<Isbn> isbns,
List<MediaContributorId> contributors,
IEnumerable<BookMediaContributor> contributors,
List<BookRating> ratings) : base(id)
{
Id = id;
@@ -190,7 +187,7 @@ public sealed class Book : AggregateRoot<BookId>
CreatedOnUtc = createdOnUtc;
UpdatedOnUtc = updatedOnUtc.HasValue ? updatedOnUtc.Value : null;
_isbns = isbns;
_contributors = contributors;
_contributors = [.. contributors];
_ratings = ratings;
}
@@ -214,7 +211,7 @@ public sealed class Book : AggregateRoot<BookId>
/// <param name="barnesAndNobleId">The optional Barnes & Noble ID of the book.</param>
/// <param name="appleBooksId">The optional Apple Books ID of the book.</param>
/// <param name="isbns">The list of ISBNs of the book.</param>
/// <param name="contributors">The list of objects representing the unique identifiers of the media contributors of the book.</param>
/// <param name="contributors">The list of media contributors of the book, each carrying the role the contributor played.</param>
/// <param name="ratings">The list of ratings for the book.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Book"/>, or an error message.
@@ -237,7 +234,7 @@ public sealed class Book : AggregateRoot<BookId>
Optional<string> barnesAndNobleId,
Optional<string> appleBooksId,
List<Isbn> isbns,
List<MediaContributorId> contributors,
IEnumerable<BookMediaContributor> contributors,
List<BookRating> ratings)
{
// TODO: enforce invariants
@@ -290,7 +287,7 @@ public sealed class Book : AggregateRoot<BookId>
/// <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>
/// <param name="isbns">The list of ISBNs of the book.</param>
/// <param name="contributors">The list of objects representing the unique identifiers of the media contributors of the book.</param>
/// <param name="contributors">The list of media contributors of the book, each carrying the role the contributor played.</param>
/// <param name="ratings">The list of ratings for the book.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Book"/>, or an error message.
@@ -316,7 +313,7 @@ public sealed class Book : AggregateRoot<BookId>
DateTime createdOnUtc,
Optional<DateTime> updatedOnUtc,
List<Isbn> isbns,
List<MediaContributorId> contributors,
IEnumerable<BookMediaContributor> contributors,
List<BookRating> ratings)
{
// TODO: enforce invariants
@@ -347,14 +344,15 @@ public sealed class Book : AggregateRoot<BookId>
}
/// <summary>
/// Replaces the media contributors of the book with the provided <paramref name="contributors"/>, identified by their unique identifiers.
/// Replaces the media contributors of the book with the provided <paramref name="contributors"/>, each carrying
/// the media contributor and the role the contributor played in the book.
/// </summary>
/// <param name="contributors">The unique identifiers of the media contributors of the book.</param>
public void UpdateContributors(IReadOnlyCollection<MediaContributorId> contributors)
/// <param name="contributors">The media contributors of the book.</param>
public void UpdateContributors(IReadOnlyCollection<BookMediaContributor> contributors)
{
// replace the contents of the collection in place, preserving the readonly reference invariants of the aggregate
_contributors.Clear();
_contributors.AddRange(contributors);
_contributors.UnionWith(contributors);
}
/// <summary>
@@ -1,17 +0,0 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services;
/// <summary>
/// Service for managing book libraries.
/// </summary>
public sealed class BookLibraryService : IBookLibraryService
{
/// <summary>
/// Gets the collection of books in the library.
/// </summary>
public ICollection<Book> Books => throw new NotImplementedException();
}
@@ -1,25 +0,0 @@
#region ========================================================================= USING =====================================================================================
using System.Collections.Generic;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services;
/// <summary>
/// Interface for the service for managing book libraries.
/// </summary>
public interface IBookLibraryService
{
/// <summary>
/// Gets the collection of books in the library.
/// </summary>
ICollection<Book> Books { get; }
// ICollection<BookSeries> Series { get; }
// void AddBook(Book book);
// void RemoveBook(Guid bookId);
// void AddSeries(BookSeries series);
// void RemoveSeries(Guid seriesId);
// Book GetBook(Guid bookId);
// BookSeries GetSeries(Guid seriesId);
}
@@ -1,54 +0,0 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.Models.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics;
#endregion
namespace Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Value Object for the Id of a book library.
/// </summary>
[DebuggerDisplay("{Value}")]
public sealed class BookLibraryId : EntityId<Guid> // TODO: to be removed
{
/// <summary>
/// Initializes a new instance of the <see cref="BookLibraryId"/> class.
/// </summary>
/// <param name="value">The value representing this object.</param>
private BookLibraryId(Guid value) : base(value)
{
}
/// <summary>
/// Creates a new instance of the <see cref="BookLibraryId"/> class.
/// </summary>
/// <returns>The created <see cref="BookLibraryId"/> instance.</returns>
public static Result<BookLibraryId> CreateUnique()
{
// TODO: enforce invariants
return new BookLibraryId(Guid.NewGuid());
}
/// <summary>
/// Creates a new instance of the <see cref="BookLibraryId"/> class, from a pre-existing <paramref name="value"/>.
/// </summary>
/// <param name="value">The value used to create the <see cref="BookLibraryId"/> instance.</param>
/// <returns>The created <see cref="BookLibraryId"/> instance.</returns>
public static Result<BookLibraryId> Create(Guid value)
{
// TODO: enforce invariants
return new BookLibraryId(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;
}
}