mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Refactors the artist slice across the stack
This commit is contained in:
1 parent
b398f26bfe
commit
b51013a9e9
24 files changed
+404
-222
No files matched your search
+33
-13
@@ -465,7 +465,27 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
.When(m => m!.OriginalLanguage is not null);
|
||||
});
|
||||
|
||||
// Validates the MusicBrainz identifiers of the track.
|
||||
track.RuleFor(t => t!.MusicBrainzRecordingId)
|
||||
.Must(musicBrainzRecordingId => musicBrainzRecordingId != Guid.Empty)
|
||||
.When(t => t!.MusicBrainzRecordingId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
track.RuleFor(t => t!.MusicBrainzTrackId)
|
||||
.Must(musicBrainzTrackId => musicBrainzTrackId != Guid.Empty)
|
||||
.When(t => t!.MusicBrainzTrackId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
track.RuleFor(t => t!.MusicBrainzWorkId)
|
||||
.Must(musicBrainzWorkId => musicBrainzWorkId != Guid.Empty)
|
||||
.When(t => t!.MusicBrainzWorkId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the ordering and performance characteristics of the track.
|
||||
track.RuleFor(t => t!.TrackNumber)
|
||||
.NotNull()
|
||||
.WithError(Errors.Music.TrackNumberMustBeGreaterThanZero);
|
||||
|
||||
track.RuleFor(t => t!.TrackNumber)
|
||||
.GreaterThan(0)
|
||||
.When(t => t!.TrackNumber.HasValue)
|
||||
@@ -496,6 +516,19 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
.When(t => t!.Work is not null)
|
||||
.WithError(Errors.Music.WorkMustBeMaximum255CharactersLong);
|
||||
|
||||
// Validates the moods and the ISRC codes of the track.
|
||||
track.RuleForEach(t => t!.Moods)
|
||||
.ChildRules(mood =>
|
||||
mood.RuleFor(m => m.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Metadata.MoodNameCannotBeEmpty));
|
||||
|
||||
track.RuleForEach(t => t!.Isrcs)
|
||||
.ChildRules(isrc =>
|
||||
isrc.RuleFor(i => i.Value)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.IsrcValueCannotBeEmpty));
|
||||
|
||||
// Validates the media contributors that performed on the track.
|
||||
track.RuleFor(t => t!.Contributors)
|
||||
.NotNull()
|
||||
@@ -515,19 +548,6 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
.WithError(Errors.MediaContributor.UnknownMediaContributorRole);
|
||||
});
|
||||
|
||||
// Validates the moods and the ISRC codes of the track.
|
||||
track.RuleForEach(t => t!.Moods)
|
||||
.ChildRules(mood =>
|
||||
mood.RuleFor(m => m.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Metadata.MoodNameCannotBeEmpty));
|
||||
|
||||
track.RuleForEach(t => t!.Isrcs)
|
||||
.ChildRules(isrc =>
|
||||
isrc.RuleFor(i => i.Value)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.IsrcValueCannotBeEmpty));
|
||||
|
||||
// Validates the ratings of the track.
|
||||
track.RuleFor(t => t!.Ratings)
|
||||
.NotNull()
|
||||
|
||||
+8
-4
@@ -79,8 +79,8 @@ public class UpdateArtistCommandHandler : ICommandHandler<UpdateArtistCommand, R
|
||||
Guid libraryId = Guid.Parse(command.LibraryId!);
|
||||
Guid artistId = Guid.Parse(command.ArtistId!);
|
||||
|
||||
// Get the existing artist, only for its identity and creation metadata; the repository reloads and tracks the whole aggregate when it applies the update.
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: false, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
// An artist is an aggregate root, so the whole aggregate is loaded and the artist is edited within it.
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getArtistResult.IsFailure)
|
||||
return getArtistResult.Errors;
|
||||
if (getArtistResult.Value is null)
|
||||
@@ -115,8 +115,12 @@ public class UpdateArtistCommandHandler : ICommandHandler<UpdateArtistCommand, R
|
||||
if (getContributorsResult.IsFailure)
|
||||
return getContributorsResult.Errors;
|
||||
|
||||
// Convert the command to a domain aggregate to enforce invariants, preserving the identity and creation metadata of the stored artist.
|
||||
Result<Artist> updateArtistResult = command.ToDomainEntity(existingArtist);
|
||||
// The write path goes through the aggregate root, which is mutated in place, preserving its identity and the identity of its children.
|
||||
Result<Artist> artistResult = existingArtist.ToDomainEntity();
|
||||
if (artistResult.IsFailure)
|
||||
return artistResult.Errors;
|
||||
|
||||
Result<Artist> updateArtistResult = command.ToDomainEntity(artistResult.Value);
|
||||
if (updateArtistResult.IsFailure)
|
||||
return updateArtistResult.Errors;
|
||||
|
||||
|
||||
+33
-13
@@ -487,7 +487,27 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.When(m => m!.OriginalLanguage is not null);
|
||||
});
|
||||
|
||||
// Validates the MusicBrainz identifiers of the track.
|
||||
track.RuleFor(t => t!.MusicBrainzRecordingId)
|
||||
.Must(musicBrainzRecordingId => musicBrainzRecordingId != Guid.Empty)
|
||||
.When(t => t!.MusicBrainzRecordingId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
track.RuleFor(t => t!.MusicBrainzTrackId)
|
||||
.Must(musicBrainzTrackId => musicBrainzTrackId != Guid.Empty)
|
||||
.When(t => t!.MusicBrainzTrackId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
track.RuleFor(t => t!.MusicBrainzWorkId)
|
||||
.Must(musicBrainzWorkId => musicBrainzWorkId != Guid.Empty)
|
||||
.When(t => t!.MusicBrainzWorkId.HasValue)
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the ordering and performance characteristics of the track.
|
||||
track.RuleFor(t => t!.TrackNumber)
|
||||
.NotNull()
|
||||
.WithError(Errors.Music.TrackNumberMustBeGreaterThanZero);
|
||||
|
||||
track.RuleFor(t => t!.TrackNumber)
|
||||
.GreaterThan(0)
|
||||
.When(t => t!.TrackNumber.HasValue)
|
||||
@@ -518,6 +538,19 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.When(t => t!.Work is not null)
|
||||
.WithError(Errors.Music.WorkMustBeMaximum255CharactersLong);
|
||||
|
||||
// Validates the moods and the ISRC codes of the track.
|
||||
track.RuleForEach(t => t!.Moods)
|
||||
.ChildRules(mood =>
|
||||
mood.RuleFor(m => m.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Metadata.MoodNameCannotBeEmpty));
|
||||
|
||||
track.RuleForEach(t => t!.Isrcs)
|
||||
.ChildRules(isrc =>
|
||||
isrc.RuleFor(i => i.Value)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.IsrcValueCannotBeEmpty));
|
||||
|
||||
// Validates the media contributors that performed on the track.
|
||||
track.RuleFor(t => t!.Contributors)
|
||||
.NotNull()
|
||||
@@ -537,19 +570,6 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.WithError(Errors.MediaContributor.UnknownMediaContributorRole);
|
||||
});
|
||||
|
||||
// Validates the moods and the ISRC codes of the track.
|
||||
track.RuleForEach(t => t!.Moods)
|
||||
.ChildRules(mood =>
|
||||
mood.RuleFor(m => m.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Metadata.MoodNameCannotBeEmpty));
|
||||
|
||||
track.RuleForEach(t => t!.Isrcs)
|
||||
.ChildRules(isrc =>
|
||||
isrc.RuleFor(i => i.Value)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.IsrcValueCannotBeEmpty));
|
||||
|
||||
// Validates the ratings of the track.
|
||||
track.RuleFor(t => t!.Ratings)
|
||||
.NotNull()
|
||||
|
||||
Reference in new issue
Block a user