mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13: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
+25
-3
@@ -83,6 +83,28 @@ public static class AddAlbumCommandMapping
|
||||
musicBrainzReleaseArtistId = musicBrainzReleaseArtistIdResult.Value;
|
||||
}
|
||||
|
||||
List<MusicMediaContributor> contributors = [.. domainContributorsResult.Select(contributorResult => contributorResult.Value)];
|
||||
List<AudioRating> ratings = [.. domainRatingsResult.Select(ratingResult => ratingResult.Value)];
|
||||
List<Track> tracks = [.. domainTracksResult.Select(trackResult => trackResult.Value)];
|
||||
|
||||
// An album carries an Id only when it already exists; otherwise a new one is minted. The repository preserves the stored
|
||||
// creation audit when it merges an existing album, so a transient value is used here.
|
||||
if (command.AlbumId.HasValue)
|
||||
return Album.Create(
|
||||
AlbumId.Create(command.AlbumId.Value),
|
||||
metadataResult.Value,
|
||||
Optional<MusicMediaFormat>.FromNullable(command.MediaFormat),
|
||||
barcode,
|
||||
Optional<string>.FromNullable(command.CatalogNumber),
|
||||
musicBrainzReleaseId,
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
contributors,
|
||||
ratings,
|
||||
tracks,
|
||||
DateTime.UtcNow,
|
||||
Optional<DateTime>.None());
|
||||
|
||||
return Album.Create(
|
||||
metadataResult.Value,
|
||||
Optional<MusicMediaFormat>.FromNullable(command.MediaFormat),
|
||||
@@ -91,9 +113,9 @@ public static class AddAlbumCommandMapping
|
||||
musicBrainzReleaseId,
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
[.. domainContributorsResult.Select(contributorResult => contributorResult.Value)],
|
||||
[.. domainRatingsResult.Select(ratingResult => ratingResult.Value)],
|
||||
[.. domainTracksResult.Select(trackResult => trackResult.Value)]);
|
||||
contributors,
|
||||
ratings,
|
||||
tracks);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+3
-2
@@ -72,8 +72,9 @@ public static class AlbumMapping
|
||||
Tracks = [.. domainEntity.Tracks.Select(track => track.ToRepositoryEntity(domainEntity.Id.Value, libraryId))],
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc : null,
|
||||
UpdatedBy = domainEntity.UpdatedOnUtc.HasValue ? Guid.NewGuid() : null
|
||||
// The audit columns are owned by the auditing interceptor, which stamps only the rows that actually changed, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
};
|
||||
}
|
||||
}
|
||||
+15
-15
@@ -1,11 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.UpdateAlbum;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
@@ -21,25 +20,25 @@ namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibra
|
||||
public static class UpdateAlbumCommandMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="command"/> to a domain <see cref="Album"/>, preserving the identity and creation metadata of the stored album identified by <paramref name="existingAlbum"/>.
|
||||
/// Applies the editable data of <paramref name="command"/> to the album of <paramref name="artist"/> identified by the command, through the aggregate root.
|
||||
/// </summary>
|
||||
/// <param name="command">The command whose data is used to create the album.</param>
|
||||
/// <param name="existingAlbum">The stored album whose identity and creation metadata are preserved.</param>
|
||||
/// <param name="command">The command whose data is applied to the album.</param>
|
||||
/// <param name="artist">The artist aggregate that owns the album.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Album"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either the successfully updated <see cref="Artist"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Album> ToDomainEntity(this UpdateAlbumCommand command, AlbumEntity existingAlbum)
|
||||
public static Result<Artist> ToDomainEntity(this UpdateAlbumCommand command, Artist artist)
|
||||
{
|
||||
Result<AlbumMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainEntities();
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
@@ -78,8 +77,8 @@ public static class UpdateAlbumCommandMapping
|
||||
musicBrainzReleaseArtistId = musicBrainzReleaseArtistIdResult.Value;
|
||||
}
|
||||
|
||||
return Album.Create(
|
||||
AlbumId.Create(existingAlbum.Id),
|
||||
Result<Updated> updateResult = artist.UpdateAlbum(
|
||||
AlbumId.Create(Guid.Parse(command.AlbumId!)),
|
||||
metadataResult.Value,
|
||||
Optional<MusicMediaFormat>.FromNullable(command.MediaFormat),
|
||||
barcode,
|
||||
@@ -88,9 +87,10 @@ public static class UpdateAlbumCommandMapping
|
||||
musicBrainzReleaseGroupId,
|
||||
musicBrainzReleaseArtistId,
|
||||
[.. domainContributorsResult.Select(contributorResult => contributorResult.Value)],
|
||||
[.. domainRatingsResult.Select(ratingResult => ratingResult.Value)],
|
||||
[],
|
||||
existingAlbum.CreatedOnUtc,
|
||||
Optional<DateTime>.FromNullable(existingAlbum.UpdatedOnUtc));
|
||||
[.. domainRatingsResult.Select(ratingResult => ratingResult.Value)]);
|
||||
if (updateResult.IsFailure)
|
||||
return updateResult.Errors;
|
||||
|
||||
return artist;
|
||||
}
|
||||
}
|
||||
+29
-4
@@ -77,22 +77,47 @@ public static class AddTrackCommandMapping
|
||||
musicBrainzWorkId = musicBrainzWorkIdResult.Value;
|
||||
}
|
||||
|
||||
List<Isrc> isrcs = [.. domainIsrcsResult.Select(isrcResult => isrcResult.Value)];
|
||||
List<Mood> moods = [.. domainMoodsResult.Select(moodResult => moodResult.Value)];
|
||||
List<MusicMediaContributor> contributors = [.. domainContributorsResult.Select(contributorResult => contributorResult.Value)];
|
||||
List<AudioRating> ratings = [.. domainRatingsResult.Select(ratingResult => ratingResult.Value)];
|
||||
|
||||
// A track carries an Id only when it already exists; otherwise a new one is minted.
|
||||
if (command.TrackId.HasValue)
|
||||
return Track.Create(
|
||||
TrackId.Create(command.TrackId.Value),
|
||||
command.Path!,
|
||||
metadataResult.Value,
|
||||
command.TrackNumber ?? 1,
|
||||
Optional<int>.FromNullable(command.DiscNumber),
|
||||
isrcs,
|
||||
Optional<string>.FromNullable(command.Script),
|
||||
Optional<MusicKey>.FromNullable(command.Key),
|
||||
Optional<int>.FromNullable(command.Bpm),
|
||||
moods,
|
||||
Optional<string>.FromNullable(command.Work),
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
contributors,
|
||||
ratings);
|
||||
|
||||
return Track.Create(
|
||||
command.Path!,
|
||||
metadataResult.Value,
|
||||
command.TrackNumber ?? 1,
|
||||
Optional<int>.FromNullable(command.DiscNumber),
|
||||
[.. domainIsrcsResult.Select(isrcResult => isrcResult.Value)],
|
||||
isrcs,
|
||||
Optional<string>.FromNullable(command.Script),
|
||||
Optional<MusicKey>.FromNullable(command.Key),
|
||||
Optional<int>.FromNullable(command.Bpm),
|
||||
[.. domainMoodsResult.Select(moodResult => moodResult.Value)],
|
||||
moods,
|
||||
Optional<string>.FromNullable(command.Work),
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
[.. domainContributorsResult.Select(contributorResult => contributorResult.Value)],
|
||||
[.. domainRatingsResult.Select(ratingResult => ratingResult.Value)]);
|
||||
contributors,
|
||||
ratings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+29
-13
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.UpdateTrack;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
@@ -6,11 +7,13 @@ using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
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.MusicLibraryAggregate;
|
||||
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.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
@@ -21,21 +24,29 @@ namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibra
|
||||
public static class UpdateTrackCommandMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="command"/> to a domain <see cref="Track"/>, preserving the provided <paramref name="id"/>.
|
||||
/// Applies the editable data of <paramref name="command"/> to the track of <paramref name="artist"/> identified by the command, through the aggregate root.
|
||||
/// </summary>
|
||||
/// <param name="command">The command whose data is used to create the track.</param>
|
||||
/// <param name="id">The unique identifier of the track.</param>
|
||||
/// <param name="libraryId">The Id of the media library the track belongs to.</param>
|
||||
/// <param name="ratings">The list of ratings of the track.</param>
|
||||
/// <param name="command">The command whose data is applied to the track.</param>
|
||||
/// <param name="artist">The artist aggregate that owns the track.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Track"/>, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either the successfully updated <see cref="Artist"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Track> ToDomainEntity(this UpdateTrackCommand command, TrackId id, Guid libraryId, List<AudioRating> ratings)
|
||||
public static Result<Artist> ToDomainEntity(this UpdateTrackCommand command, Artist artist)
|
||||
{
|
||||
Result<AudioMetadata> metadataResult = command.Metadata!.ToDomainEntity();
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzRecordingId is not null)
|
||||
{
|
||||
@@ -79,22 +90,27 @@ public static class UpdateTrackCommandMapping
|
||||
domainMoods.Add(moodResult.Value);
|
||||
}
|
||||
|
||||
return Track.Create(
|
||||
id,
|
||||
Result<Updated> updateResult = artist.UpdateTrackInAlbum(
|
||||
AlbumId.Create(Guid.Parse(command.AlbumId!)),
|
||||
TrackId.Create(Guid.Parse(command.TrackId!)),
|
||||
command.Path!,
|
||||
metadataResult.Value,
|
||||
command.TrackNumber ?? 1,
|
||||
Optional<int>.FromNullable(command.DiscNumber),
|
||||
domainIsrcs,
|
||||
Optional<string>.FromNullable(command.Script),
|
||||
Optional<MusicKey>.FromNullable(command.Key),
|
||||
Optional<int>.FromNullable(command.Bpm),
|
||||
domainMoods,
|
||||
Optional<string>.FromNullable(command.Work),
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
[],
|
||||
ratings);
|
||||
[.. domainContributorsResult.Select(contributorResult => contributorResult.Value)],
|
||||
[.. domainRatingsResult.Select(ratingResult => ratingResult.Value)],
|
||||
domainMoods,
|
||||
domainIsrcs);
|
||||
if (updateResult.IsFailure)
|
||||
return updateResult.Errors;
|
||||
|
||||
return artist;
|
||||
}
|
||||
}
|
||||
+1
@@ -37,6 +37,7 @@ public static class UpdateTrackRequestMapping
|
||||
request.MusicBrainzRecordingId,
|
||||
request.MusicBrainzTrackId,
|
||||
request.MusicBrainzWorkId,
|
||||
request.Contributors,
|
||||
request.Ratings,
|
||||
request.Moods,
|
||||
request.Isrcs);
|
||||
|
||||
Reference in new issue
Block a user