mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11:10 +00:00
Refactors the add and update album and track slices across the stack
This commit is contained in:
1 parent
ea6eb9f796
commit
54cae054c1
30 files changed
+846
-325
No files matched your search
+140
@@ -2,12 +2,16 @@
|
||||
using Lumina.Domain.Common.Errors;
|
||||
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.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
@@ -230,4 +234,140 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
UpdatedOnUtc = DateTime.UtcNow;
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an album of the artist, together with its media contributors and ratings, without touching its tracks.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An album is a child entity of the artist aggregate, not an aggregate root, so it is mutated through its owning artist,
|
||||
/// which is the consistency boundary. Book and Artist are themselves aggregate roots, so their update flows reconstitute them
|
||||
/// directly with their own Create method instead. This difference is intentional.
|
||||
/// </remarks>
|
||||
/// <param name="albumId">The Id of the album to update.</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="contributors">The media contributors of the album.</param>
|
||||
/// <param name="ratings">The ratings of the album.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Updated> UpdateAlbum(
|
||||
AlbumId albumId,
|
||||
AlbumMetadata metadata,
|
||||
Optional<MusicMediaFormat> mediaFormat,
|
||||
Optional<Barcode> barcode,
|
||||
Optional<string> catalogNumber,
|
||||
Optional<MusicBrainzId> musicBrainzReleaseId,
|
||||
Optional<MusicBrainzId> musicBrainzReleaseGroupId,
|
||||
Optional<MusicBrainzId> musicBrainzReleaseArtistId,
|
||||
IReadOnlyCollection<MusicMediaContributor> contributors,
|
||||
IReadOnlyCollection<AudioRating> ratings)
|
||||
{
|
||||
Album? album = _albums.FirstOrDefault(album => album.Id == albumId);
|
||||
if (album is null)
|
||||
return Errors.Music.AlbumNotFound;
|
||||
|
||||
album.UpdateDetails(metadata, mediaFormat, barcode, catalogNumber, musicBrainzReleaseId, musicBrainzReleaseGroupId, musicBrainzReleaseArtistId);
|
||||
album.UpdateContributors(contributors);
|
||||
album.UpdateRatings(ratings);
|
||||
UpdatedOnUtc = DateTime.UtcNow;
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a track of an album of the artist, together with its media contributors, ratings, moods and ISRCs.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A track is a child entity of the artist aggregate, not an aggregate root, so it is mutated through its owning artist,
|
||||
/// which is the consistency boundary. Book and Artist are themselves aggregate roots, so their update flows reconstitute them
|
||||
/// directly with their own Create method instead. This difference is intentional.
|
||||
/// </remarks>
|
||||
/// <param name="albumId">The Id of the album the track belongs to.</param>
|
||||
/// <param name="trackId">The Id of the track to update.</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="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>
|
||||
/// <param name="contributors">The media contributors of the track.</param>
|
||||
/// <param name="ratings">The ratings of the track.</param>
|
||||
/// <param name="moods">The moods of the track.</param>
|
||||
/// <param name="isrcs">The ISRCs of the track.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Updated> UpdateTrackInAlbum(
|
||||
AlbumId albumId,
|
||||
TrackId trackId,
|
||||
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,
|
||||
IReadOnlyCollection<MusicMediaContributor> contributors,
|
||||
IReadOnlyCollection<AudioRating> ratings,
|
||||
IReadOnlyCollection<Mood> moods,
|
||||
IReadOnlyCollection<Isrc> isrcs)
|
||||
{
|
||||
Album? album = _albums.FirstOrDefault(album => album.Id == albumId);
|
||||
Track? track = album?.Tracks.FirstOrDefault(track => track.Id == trackId);
|
||||
if (track is null)
|
||||
return Errors.Music.TrackNotFound;
|
||||
|
||||
track.UpdateDetails(
|
||||
path,
|
||||
metadata,
|
||||
trackNumber,
|
||||
discNumber,
|
||||
script,
|
||||
key,
|
||||
bpm,
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId);
|
||||
track.UpdateContributors(contributors);
|
||||
track.UpdateRatings(ratings);
|
||||
track.UpdateMoods(moods);
|
||||
track.UpdateIsrcs(isrcs);
|
||||
UpdatedOnUtc = DateTime.UtcNow;
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a track to an album of the artist.
|
||||
/// </summary>
|
||||
/// <param name="albumId">The Id of the album the track is added to.</param>
|
||||
/// <param name="track">The track to be added.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
/// <remarks>
|
||||
/// A track is a child entity of the artist aggregate, not an aggregate root, so it is added through its owning artist,
|
||||
/// which is the consistency boundary. Book and Artist are themselves aggregate roots, so they are created directly instead.
|
||||
/// This difference is intentional.
|
||||
/// </remarks>
|
||||
public Result<Created> AddTrackToAlbum(AlbumId albumId, Track track)
|
||||
{
|
||||
Album? album = _albums.FirstOrDefault(album => album.Id == albumId);
|
||||
if (album is null)
|
||||
return Errors.Music.AlbumNotFound;
|
||||
|
||||
Result<Created> addResult = album.AddTrack(track);
|
||||
if (addResult.IsFailure)
|
||||
return addResult.Errors;
|
||||
|
||||
return Result.Created;
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -217,7 +217,7 @@ public sealed class Album : Entity<AlbumId>
|
||||
/// </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)
|
||||
internal Result<Created> AddTrack(Track track)
|
||||
{
|
||||
if (_tracks.Contains(track))
|
||||
return Errors.Music.TheTrackIsAlreadyInTheAlbum;
|
||||
@@ -230,7 +230,7 @@ public sealed class Album : Entity<AlbumId>
|
||||
/// </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)
|
||||
internal Result<Deleted> RemoveTrack(Track track)
|
||||
{
|
||||
if (!_tracks.Contains(track))
|
||||
return Errors.Music.TheTrackIsNotInTheAlbum;
|
||||
@@ -242,7 +242,7 @@ public sealed class Album : Entity<AlbumId>
|
||||
/// Replaces the media contributors of the album with the provided <paramref name="contributors"/>.
|
||||
/// </summary>
|
||||
/// <param name="contributors">The media contributors of the album.</param>
|
||||
public void UpdateContributors(IReadOnlyCollection<MusicMediaContributor> contributors)
|
||||
internal void UpdateContributors(IReadOnlyCollection<MusicMediaContributor> contributors)
|
||||
{
|
||||
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
|
||||
_contributors.Clear();
|
||||
@@ -253,7 +253,7 @@ public sealed class Album : Entity<AlbumId>
|
||||
/// 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)
|
||||
internal void UpdateRatings(IReadOnlyCollection<AudioRating> ratings)
|
||||
{
|
||||
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
|
||||
_ratings.Clear();
|
||||
@@ -271,7 +271,7 @@ public sealed class Album : Entity<AlbumId>
|
||||
/// <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(
|
||||
internal Result<Updated> UpdateDetails(
|
||||
AlbumMetadata metadata,
|
||||
Optional<MusicMediaFormat> mediaFormat,
|
||||
Optional<Barcode> barcode,
|
||||
|
||||
+25
-3
@@ -274,7 +274,7 @@ public sealed class Track : Entity<TrackId>
|
||||
/// Replaces the media contributors of the track with the provided <paramref name="contributors"/>.
|
||||
/// </summary>
|
||||
/// <param name="contributors">The media contributors of the track.</param>
|
||||
public void UpdateContributors(IReadOnlyCollection<MusicMediaContributor> contributors)
|
||||
internal void UpdateContributors(IReadOnlyCollection<MusicMediaContributor> contributors)
|
||||
{
|
||||
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
|
||||
_contributors.Clear();
|
||||
@@ -285,13 +285,35 @@ public sealed class Track : Entity<TrackId>
|
||||
/// 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)
|
||||
internal 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>
|
||||
/// Replaces the moods of the track with the provided <paramref name="moods"/>.
|
||||
/// </summary>
|
||||
/// <param name="moods">The moods of the track.</param>
|
||||
internal void UpdateMoods(IReadOnlyCollection<Mood> moods)
|
||||
{
|
||||
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
|
||||
_moods.Clear();
|
||||
_moods.AddRange(moods);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the ISRCs of the track with the provided <paramref name="isrcs"/>.
|
||||
/// </summary>
|
||||
/// <param name="isrcs">The ISRCs of the track.</param>
|
||||
internal void UpdateIsrcs(IReadOnlyCollection<Isrc> isrcs)
|
||||
{
|
||||
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
|
||||
_isrcs.Clear();
|
||||
_isrcs.AddRange(isrcs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the details of the track, without touching the moods, the ISRCs, the media contributors, and the ratings.
|
||||
/// </summary>
|
||||
@@ -307,7 +329,7 @@ public sealed class Track : Entity<TrackId>
|
||||
/// <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(
|
||||
internal Result<Updated> UpdateDetails(
|
||||
string path,
|
||||
AudioMetadata metadata,
|
||||
int trackNumber,
|
||||
|
||||
Reference in new issue
Block a user