mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +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
@@ -324,20 +324,20 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists
|
||||
"catalogNumber": "EMC 4008",
|
||||
"musicBrainzReleaseId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
|
||||
"musicBrainzReleaseGroupId": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
|
||||
"musicBrainzReleaseArtistId": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f",
|
||||
"createdOnUtc": "2025-01-01T12:00:00.0000000Z",
|
||||
"updatedOnUtc": null,
|
||||
"contributors": [
|
||||
{
|
||||
"contributorId": "0e7b4a6c-5f8d-6b9e-ca0b-3c4d5e6f7a8b",
|
||||
"role": "Producer"
|
||||
},
|
||||
{
|
||||
"contributorId": "1a8c5b7d-6a9e-7c0f-db1c-4d5e6f7a8b9c",
|
||||
"role": "Engineer"
|
||||
}
|
||||
],
|
||||
"ratings": [
|
||||
"musicBrainzReleaseArtistId": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f",
|
||||
"createdOnUtc": "2025-01-01T12:00:00.0000000Z",
|
||||
"updatedOnUtc": null,
|
||||
"contributors": [
|
||||
{
|
||||
"contributorId": "0e7b4a6c-5f8d-6b9e-ca0b-3c4d5e6f7a8b",
|
||||
"role": "Producer"
|
||||
},
|
||||
{
|
||||
"contributorId": "1a8c5b7d-6a9e-7c0f-db1c-4d5e6f7a8b9c",
|
||||
"role": "Engineer"
|
||||
}
|
||||
],
|
||||
"ratings": [
|
||||
{
|
||||
"value": 4.5,
|
||||
"maxValue": 5,
|
||||
@@ -384,6 +384,13 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists
|
||||
"musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c",
|
||||
"createdOnUtc": "2025-01-01T12:00:00.0000000Z",
|
||||
"updatedOnUtc": null,
|
||||
"moods": [
|
||||
{ "name": "dramatic" },
|
||||
{ "name": "anxious" }
|
||||
],
|
||||
"isrcs": [
|
||||
{ "value": "GBUM71029604" }
|
||||
],
|
||||
"contributors": [
|
||||
{
|
||||
"contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d",
|
||||
@@ -407,13 +414,6 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists
|
||||
"source": "LastFm",
|
||||
"voteCount": 1234
|
||||
}
|
||||
],
|
||||
"moods": [
|
||||
{ "name": "dramatic" },
|
||||
{ "name": "anxious" }
|
||||
],
|
||||
"isrcs": [
|
||||
{ "value": "GBUM71029604" }
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -448,6 +448,13 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists
|
||||
"musicBrainzWorkId": "2b3c4d5e-6f7a-4b8c-9d0e-1f2a3b4c5d6e",
|
||||
"createdOnUtc": "2025-01-01T12:00:00.0000000Z",
|
||||
"updatedOnUtc": null,
|
||||
"moods": [
|
||||
{ "name": "happy" },
|
||||
{ "name": "warm" }
|
||||
],
|
||||
"isrcs": [
|
||||
{ "value": "GBUM71029609" }
|
||||
],
|
||||
"contributors": [
|
||||
{
|
||||
"contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d",
|
||||
@@ -471,13 +478,6 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists
|
||||
"source": "LastFm",
|
||||
"voteCount": 567
|
||||
}
|
||||
],
|
||||
"moods": [
|
||||
{ "name": "happy" },
|
||||
{ "name": "warm" }
|
||||
],
|
||||
"isrcs": [
|
||||
{ "value": "GBUM71029609" }
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -906,20 +906,20 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}
|
||||
"catalogNumber": "EMC 4008",
|
||||
"musicBrainzReleaseId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
|
||||
"musicBrainzReleaseGroupId": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
|
||||
"musicBrainzReleaseArtistId": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f",
|
||||
"createdOnUtc": "2025-01-01T12:00:00.0000000Z",
|
||||
"updatedOnUtc": null,
|
||||
"contributors": [
|
||||
{
|
||||
"contributorId": "0e7b4a6c-5f8d-6b9e-ca0b-3c4d5e6f7a8b",
|
||||
"role": "Producer"
|
||||
},
|
||||
{
|
||||
"contributorId": "1a8c5b7d-6a9e-7c0f-db1c-4d5e6f7a8b9c",
|
||||
"role": "Engineer"
|
||||
}
|
||||
],
|
||||
"ratings": [
|
||||
"musicBrainzReleaseArtistId": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f",
|
||||
"createdOnUtc": "2025-01-01T12:00:00.0000000Z",
|
||||
"updatedOnUtc": null,
|
||||
"contributors": [
|
||||
{
|
||||
"contributorId": "0e7b4a6c-5f8d-6b9e-ca0b-3c4d5e6f7a8b",
|
||||
"role": "Producer"
|
||||
},
|
||||
{
|
||||
"contributorId": "1a8c5b7d-6a9e-7c0f-db1c-4d5e6f7a8b9c",
|
||||
"role": "Engineer"
|
||||
}
|
||||
],
|
||||
"ratings": [
|
||||
{
|
||||
"value": 4.5,
|
||||
"maxValue": 5,
|
||||
@@ -966,6 +966,13 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}
|
||||
"musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c",
|
||||
"createdOnUtc": "2025-01-01T12:00:00.0000000Z",
|
||||
"updatedOnUtc": null,
|
||||
"moods": [
|
||||
{ "name": "dramatic" },
|
||||
{ "name": "anxious" }
|
||||
],
|
||||
"isrcs": [
|
||||
{ "value": "GBUM71029604" }
|
||||
],
|
||||
"contributors": [
|
||||
{
|
||||
"contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d",
|
||||
@@ -989,13 +996,6 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}
|
||||
"source": "LastFm",
|
||||
"voteCount": 1234
|
||||
}
|
||||
],
|
||||
"moods": [
|
||||
{ "name": "dramatic" },
|
||||
{ "name": "anxious" }
|
||||
],
|
||||
"isrcs": [
|
||||
{ "value": "GBUM71029604" }
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1030,6 +1030,13 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}
|
||||
"musicBrainzWorkId": "2b3c4d5e-6f7a-4b8c-9d0e-1f2a3b4c5d6e",
|
||||
"createdOnUtc": "2025-01-01T12:00:00.0000000Z",
|
||||
"updatedOnUtc": null,
|
||||
"moods": [
|
||||
{ "name": "happy" },
|
||||
{ "name": "warm" }
|
||||
],
|
||||
"isrcs": [
|
||||
{ "value": "GBUM71029609" }
|
||||
],
|
||||
"contributors": [
|
||||
{
|
||||
"contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d",
|
||||
@@ -1053,13 +1060,6 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}
|
||||
"source": "LastFm",
|
||||
"voteCount": 567
|
||||
}
|
||||
],
|
||||
"moods": [
|
||||
{ "name": "happy" },
|
||||
{ "name": "warm" }
|
||||
],
|
||||
"isrcs": [
|
||||
{ "value": "GBUM71029609" }
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -1081,5 +1081,5 @@ DELETE api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}
|
||||
200 Ok
|
||||
```
|
||||
|
||||
Deletes the artist identified by the path, together with its albums and tracks.
|
||||
Deletes the artist identified by the route, together with its albums and tracks.
|
||||
|
||||
+1
-6
@@ -44,12 +44,7 @@ public static class AddArtistCommandMapping
|
||||
Optional<string> website = Optional<string>.FromNullable(command.Website);
|
||||
Optional<MusicBrainzId> musicBrainzArtistId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzArtistId is not null)
|
||||
{
|
||||
Result<MusicBrainzId> musicBrainzArtistIdResult = MusicBrainzId.Create(command.MusicBrainzArtistId.Value);
|
||||
if (musicBrainzArtistIdResult.IsFailure)
|
||||
return musicBrainzArtistIdResult.Errors;
|
||||
musicBrainzArtistId = musicBrainzArtistIdResult.Value;
|
||||
}
|
||||
musicBrainzArtistId = MusicBrainzId.Create(command.MusicBrainzArtistId.Value);
|
||||
|
||||
return Artist.Create(
|
||||
LibraryId.Create(libraryId),
|
||||
|
||||
+1
-6
@@ -34,12 +34,7 @@ public static class ArtistEntityMapping
|
||||
{
|
||||
Optional<MusicBrainzId> musicBrainzArtistId = Optional<MusicBrainzId>.None();
|
||||
if (repositoryEntity.MusicBrainzArtistId is not null)
|
||||
{
|
||||
Result<MusicBrainzId> musicBrainzArtistIdResult = MusicBrainzId.Create(repositoryEntity.MusicBrainzArtistId.Value);
|
||||
if (musicBrainzArtistIdResult.IsFailure)
|
||||
return musicBrainzArtistIdResult.Errors;
|
||||
musicBrainzArtistId = musicBrainzArtistIdResult.Value;
|
||||
}
|
||||
musicBrainzArtistId = MusicBrainzId.Create(repositoryEntity.MusicBrainzArtistId.Value);
|
||||
|
||||
List<MusicMediaContributor> domainContributors = [];
|
||||
foreach (ArtistContributorEntity contributorEntity in repositoryEntity.Contributors)
|
||||
|
||||
+90
-21
@@ -1,10 +1,8 @@
|
||||
#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.Albums;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.UpdateArtist;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
@@ -21,14 +19,14 @@ namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibra
|
||||
public static class UpdateArtistCommandMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="command"/> to <see cref="Artist"/>, preserving the identity and creation metadata of the stored artist identified by <paramref name="existingArtist"/>.
|
||||
/// Applies the editable data of <paramref name="command"/> to <paramref name="artist"/>, through the aggregate root.
|
||||
/// </summary>
|
||||
/// <param name="command">The command to be converted.</param>
|
||||
/// <param name="existingArtist">The stored artist whose identity and creation metadata are preserved.</param>
|
||||
/// <param name="command">The command whose data is applied to the artist.</param>
|
||||
/// <param name="artist">The artist aggregate to be updated.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="Artist"/>, 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<Artist> ToDomainEntity(this UpdateArtistCommand command, ArtistEntity existingArtist)
|
||||
public static Result<Artist> ToDomainEntity(this UpdateArtistCommand command, Artist artist)
|
||||
{
|
||||
// Map the media contributors that make up the artist to their domain counterparts.
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
@@ -45,22 +43,93 @@ public static class UpdateArtistCommandMapping
|
||||
Optional<string> website = Optional<string>.FromNullable(command.Website);
|
||||
Optional<MusicBrainzId> musicBrainzArtistId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzArtistId is not null)
|
||||
musicBrainzArtistId = MusicBrainzId.Create(command.MusicBrainzArtistId.Value);
|
||||
|
||||
// The details and the media contributors of the artist are replaced in place, preserving its identity and creation metadata.
|
||||
Result<Updated> updateDetailsResult = artist.UpdateDetails(command.Name!, website, musicBrainzArtistId);
|
||||
if (updateDetailsResult.IsFailure)
|
||||
return updateDetailsResult.Errors;
|
||||
artist.UpdateContributors([.. domainContributorsResult.Select(contributorResult => contributorResult.Value)]);
|
||||
|
||||
List<Album> domainAlbums = [.. domainAlbumsResult.Select(albumResult => albumResult.Value)];
|
||||
|
||||
// Reconcile the albums by their Id: existing albums and their tracks are updated in place, new albums are added, and albums that
|
||||
// are no longer present are removed. New albums are added before the stale ones are removed, because an artist must always keep at least one album.
|
||||
foreach (Album domainAlbum in domainAlbums)
|
||||
{
|
||||
Result<MusicBrainzId> musicBrainzArtistIdResult = MusicBrainzId.Create(command.MusicBrainzArtistId.Value);
|
||||
if (musicBrainzArtistIdResult.IsFailure)
|
||||
return musicBrainzArtistIdResult.Errors;
|
||||
musicBrainzArtistId = musicBrainzArtistIdResult.Value;
|
||||
// The existing album is the aggregate member, referenced by object, and is updated in place rather than being replaced.
|
||||
Album? existingAlbum = artist.Albums.FirstOrDefault(album => album.Id == domainAlbum.Id);
|
||||
if (existingAlbum is null)
|
||||
{
|
||||
Result<Created> addAlbumResult = artist.AddAlbum(domainAlbum);
|
||||
if (addAlbumResult.IsFailure)
|
||||
return addAlbumResult.Errors;
|
||||
continue;
|
||||
}
|
||||
|
||||
Result<Updated> updateAlbumResult = artist.UpdateAlbum(
|
||||
existingAlbum,
|
||||
domainAlbum.Metadata,
|
||||
domainAlbum.MediaFormat,
|
||||
domainAlbum.Barcode,
|
||||
domainAlbum.CatalogNumber,
|
||||
domainAlbum.MusicBrainzReleaseId,
|
||||
domainAlbum.MusicBrainzReleaseGroupId,
|
||||
domainAlbum.MusicBrainzReleaseArtistId,
|
||||
domainAlbum.Contributors,
|
||||
domainAlbum.Ratings);
|
||||
if (updateAlbumResult.IsFailure)
|
||||
return updateAlbumResult.Errors;
|
||||
|
||||
// Reconcile the tracks by their Id: existing tracks are updated in place, new tracks are added, and tracks that are no longer present are removed.
|
||||
foreach (Track domainTrack in domainAlbum.Tracks)
|
||||
{
|
||||
Track? existingTrack = existingAlbum.Tracks.FirstOrDefault(track => track.Id == domainTrack.Id);
|
||||
if (existingTrack is null)
|
||||
{
|
||||
Result<Created> addTrackResult = artist.AddTrackToAlbum(existingAlbum, domainTrack);
|
||||
if (addTrackResult.IsFailure)
|
||||
return addTrackResult.Errors;
|
||||
continue;
|
||||
}
|
||||
|
||||
Result<Updated> updateTrackResult = artist.UpdateTrackInAlbum(
|
||||
existingAlbum,
|
||||
existingTrack,
|
||||
domainTrack.Path,
|
||||
domainTrack.Metadata,
|
||||
domainTrack.TrackNumber,
|
||||
domainTrack.DiscNumber,
|
||||
domainTrack.Script,
|
||||
domainTrack.Key,
|
||||
domainTrack.Bpm,
|
||||
domainTrack.Work,
|
||||
domainTrack.MusicBrainzRecordingId,
|
||||
domainTrack.MusicBrainzTrackId,
|
||||
domainTrack.MusicBrainzWorkId,
|
||||
domainTrack.Moods,
|
||||
domainTrack.Isrcs,
|
||||
domainTrack.Contributors,
|
||||
domainTrack.Ratings);
|
||||
if (updateTrackResult.IsFailure)
|
||||
return updateTrackResult.Errors;
|
||||
}
|
||||
|
||||
foreach (Track staleTrack in existingAlbum.Tracks.Where(existingTrack => domainAlbum.Tracks.All(domainTrack => domainTrack.Id != existingTrack.Id)).ToList())
|
||||
{
|
||||
Result<Deleted> removeTrackResult = artist.RemoveTrackFromAlbum(existingAlbum, staleTrack);
|
||||
if (removeTrackResult.IsFailure)
|
||||
return removeTrackResult.Errors;
|
||||
}
|
||||
}
|
||||
|
||||
return Artist.Create(
|
||||
ArtistId.Create(existingArtist.Id),
|
||||
LibraryId.Create(existingArtist.LibraryId),
|
||||
command.Name!,
|
||||
website,
|
||||
musicBrainzArtistId,
|
||||
[.. domainContributorsResult.Select(contributorResult => contributorResult.Value)],
|
||||
[.. domainAlbumsResult.Select(albumResult => albumResult.Value)],
|
||||
existingArtist.CreatedOnUtc,
|
||||
Optional<DateTime>.FromNullable(existingArtist.UpdatedOnUtc));
|
||||
foreach (Album staleAlbum in artist.Albums.Where(existingAlbum => domainAlbums.All(domainAlbum => domainAlbum.Id != existingAlbum.Id)).ToList())
|
||||
{
|
||||
Result<Deleted> removeAlbumResult = artist.RemoveAlbum(staleAlbum);
|
||||
if (removeAlbumResult.IsFailure)
|
||||
return removeAlbumResult.Errors;
|
||||
}
|
||||
|
||||
return artist;
|
||||
}
|
||||
}
|
||||
+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()
|
||||
|
||||
@@ -59,6 +59,13 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
if (doesArtistNameExist)
|
||||
return Errors.Music.ArtistAlreadyExists;
|
||||
|
||||
// A track is unique within its library by its file system path, so the same file can never be registered twice, neither twice in the same request,
|
||||
// nor once when it is already registered in the library. The check runs here, for the whole artist, because the insert of the artist inserts its albums and their tracks as well.
|
||||
List<string> trackPaths = [.. artist.Albums.SelectMany(album => album.Tracks).Select(track => track.Path!)];
|
||||
Result<Success> checkTrackPathsResult = await CheckTrackPathsAsync(artist.LibraryId, trackPaths, cancellationToken).ConfigureAwait(false);
|
||||
if (checkTrackPathsResult.IsFailure)
|
||||
return checkTrackPathsResult.Errors;
|
||||
|
||||
// Fetch the tags and genres referenced anywhere in the aggregate, so that the shared tables are not duplicated.
|
||||
List<string> tagNames = [.. artist.Albums
|
||||
.SelectMany(album => album.Tags.Select(tag => tag.Name!))
|
||||
@@ -124,6 +131,13 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
shouldReplace: (existingContributor, incomingContributor) => false,
|
||||
createNew: incomingContributor => incomingContributor);
|
||||
|
||||
// A track is unique within its library by its file system path, so a track that is about to be inserted during this update can never reference a file
|
||||
// that is already registered, nor a file that another track of the same update already references. The check runs before anything is written.
|
||||
List<string> newTrackPaths = [.. GetNewTrackPaths(foundArtist, data)];
|
||||
Result<Success> checkNewTrackPathsResult = await CheckTrackPathsAsync(foundArtist.LibraryId, newTrackPaths, cancellationToken).ConfigureAwait(false);
|
||||
if (checkNewTrackPathsResult.IsFailure)
|
||||
return checkNewTrackPathsResult.Errors;
|
||||
|
||||
// Reconcile the albums by their Id: albums that are no longer present are removed, new albums are inserted, and existing
|
||||
// albums and their tracks are updated in place, so that persisted entities keep their identity across an edit. An album whose data did
|
||||
// not change produces no write statement, because its own repository only applies the values that actually changed.
|
||||
@@ -154,6 +168,54 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the file system paths of the tracks that are not yet stored and will therefore be inserted when <paramref name="data"/> is applied over <paramref name="foundArtist"/>.
|
||||
/// </summary>
|
||||
/// <param name="foundArtist">The tracked artist that is being updated.</param>
|
||||
/// <param name="data">The artist carrying the desired albums and tracks.</param>
|
||||
/// <returns>The file system paths of the tracks that are about to be inserted.</returns>
|
||||
private static IEnumerable<string> GetNewTrackPaths(ArtistEntity foundArtist, ArtistEntity data)
|
||||
{
|
||||
foreach (AlbumEntity incomingAlbum in data.Albums)
|
||||
{
|
||||
AlbumEntity? existingAlbum = foundArtist.Albums.FirstOrDefault(album => album.Id == incomingAlbum.Id);
|
||||
if (existingAlbum is null)
|
||||
{
|
||||
foreach (TrackEntity incomingTrack in incomingAlbum.Tracks)
|
||||
yield return incomingTrack.Path!;
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (TrackEntity incomingTrack in incomingAlbum.Tracks)
|
||||
if (existingAlbum.Tracks.All(existingTrack => existingTrack.Id != incomingTrack.Id))
|
||||
yield return incomingTrack.Path!;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether any of <paramref name="trackPaths"/> is referenced more than once, or is already used by a track of the library identified by <paramref name="libraryId"/>.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the library whose tracks are searched.</param>
|
||||
/// <param name="trackPaths">The file system paths of the tracks that are about to be inserted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful check, or an error.</returns>
|
||||
private async Task<Result<Success>> CheckTrackPathsAsync(Guid libraryId, IReadOnlyCollection<string> trackPaths, CancellationToken cancellationToken)
|
||||
{
|
||||
if (trackPaths.Count == 0)
|
||||
return Result.Success;
|
||||
|
||||
// The same path cannot be referenced by two tracks of the request itself, not only by a track that is already stored.
|
||||
if (trackPaths.Count != trackPaths.Distinct(StringComparer.Ordinal).Count())
|
||||
return Errors.Music.TrackAlreadyExists;
|
||||
|
||||
Result<IReadOnlyCollection<string>> getExistingPathsResult = await _trackRepository.GetExistingPathsAsync(libraryId, trackPaths, cancellationToken).ConfigureAwait(false);
|
||||
if (getExistingPathsResult.IsFailure)
|
||||
return getExistingPathsResult.Errors;
|
||||
if (getExistingPathsResult.Value.Count > 0)
|
||||
return Errors.Music.TrackAlreadyExists;
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reconciles the tracks of an existing album against the provided tracks, by their Id.
|
||||
/// </summary>
|
||||
|
||||
+41
-40
@@ -23,6 +23,8 @@ namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLib
|
||||
/// 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.
|
||||
/// The albums of the artist, and the tracks of those albums, are entities inside this aggregate, not aggregate roots, so they are referenced by object, as DDD prescribes
|
||||
/// for entities within the same consistency boundary. The methods that mutate them therefore take the album, respectively the track, itself, rather than its id.
|
||||
/// </remarks>
|
||||
[DebuggerDisplay("Id: {Id} Name: {Name}")]
|
||||
public sealed class Artist : AggregateRoot<ArtistId>
|
||||
@@ -91,7 +93,7 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
_contributors = [.. contributors];
|
||||
_albums = albums;
|
||||
CreatedOnUtc = createdOnUtc;
|
||||
UpdatedOnUtc = updatedOnUtc.HasValue ? updatedOnUtc.Value : null;
|
||||
UpdatedOnUtc = updatedOnUtc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -127,7 +129,7 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
musicBrainzArtistId,
|
||||
contributors,
|
||||
albums,
|
||||
DateTime.UtcNow, // TODO: should be IDateTimeProvider
|
||||
DateTime.UtcNow, // TODO: should be IDateTimeProvider.
|
||||
Optional<DateTime>.None());
|
||||
}
|
||||
|
||||
@@ -208,7 +210,7 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
/// <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
|
||||
// Replace the contents of the collection in place, preserving the readonly reference invariants of the aggregate.
|
||||
_contributors.Clear();
|
||||
_contributors.UnionWith(contributors);
|
||||
}
|
||||
@@ -231,7 +233,7 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
Name = name;
|
||||
Website = website;
|
||||
MusicBrainzArtistId = musicBrainzArtistId;
|
||||
UpdatedOnUtc = DateTime.UtcNow;
|
||||
UpdatedOnUtc = Optional<DateTime>.Some(DateTime.UtcNow);
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
@@ -240,10 +242,10 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
/// </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.
|
||||
/// which is the consistency boundary. Book is itself an aggregate root, so its update flow reconstitutes it directly
|
||||
/// with its own Create method instead. This difference is intentional.
|
||||
/// </remarks>
|
||||
/// <param name="albumId">The Id of the album to update.</param>
|
||||
/// <param name="album">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>
|
||||
@@ -255,7 +257,7 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
/// <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,
|
||||
Album album,
|
||||
AlbumMetadata metadata,
|
||||
Optional<MusicMediaFormat> mediaFormat,
|
||||
Optional<Barcode> barcode,
|
||||
@@ -266,14 +268,14 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
IReadOnlyCollection<MusicMediaContributor> contributors,
|
||||
IReadOnlyCollection<AudioRating> ratings)
|
||||
{
|
||||
Album? album = _albums.FirstOrDefault(album => album.Id == albumId);
|
||||
if (album is null)
|
||||
// The album is an entity inside this aggregate, referenced by object, so it must be one of the albums of the artist.
|
||||
if (!_albums.Contains(album))
|
||||
return Errors.Music.AlbumNotFound;
|
||||
|
||||
album.UpdateDetails(metadata, mediaFormat, barcode, catalogNumber, musicBrainzReleaseId, musicBrainzReleaseGroupId, musicBrainzReleaseArtistId);
|
||||
album.UpdateContributors(contributors);
|
||||
album.UpdateRatings(ratings);
|
||||
UpdatedOnUtc = DateTime.UtcNow;
|
||||
UpdatedOnUtc = Optional<DateTime>.Some(DateTime.UtcNow);
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
@@ -282,11 +284,11 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
/// </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.
|
||||
/// which is the consistency boundary. Book is itself an aggregate root, so its update flow reconstitutes it directly
|
||||
/// with its 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="album">The album the track belongs to.</param>
|
||||
/// <param name="track">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>
|
||||
@@ -298,14 +300,14 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
/// <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>
|
||||
/// <param name="contributors">The media contributors of the track.</param>
|
||||
/// <param name="ratings">The ratings 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,
|
||||
Album album,
|
||||
Track track,
|
||||
string path,
|
||||
AudioMetadata metadata,
|
||||
int trackNumber,
|
||||
@@ -317,14 +319,15 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId,
|
||||
Optional<MusicBrainzId> musicBrainzTrackId,
|
||||
Optional<MusicBrainzId> musicBrainzWorkId,
|
||||
IReadOnlyCollection<MusicMediaContributor> contributors,
|
||||
IReadOnlyCollection<AudioRating> ratings,
|
||||
IReadOnlyCollection<Mood> moods,
|
||||
IReadOnlyCollection<Isrc> isrcs)
|
||||
IReadOnlyCollection<Isrc> isrcs,
|
||||
IReadOnlyCollection<MusicMediaContributor> contributors,
|
||||
IReadOnlyCollection<AudioRating> ratings)
|
||||
{
|
||||
Album? album = _albums.FirstOrDefault(album => album.Id == albumId);
|
||||
Track? track = album?.Tracks.FirstOrDefault(track => track.Id == trackId);
|
||||
if (track is null)
|
||||
// The album and the track are entities inside this aggregate, referenced by object, so they must belong to the artist, respectively to the album.
|
||||
if (!_albums.Contains(album))
|
||||
return Errors.Music.AlbumNotFound;
|
||||
if (!album.Tracks.Contains(track))
|
||||
return Errors.Music.TrackNotFound;
|
||||
|
||||
track.UpdateDetails(
|
||||
@@ -339,18 +342,18 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId);
|
||||
track.UpdateContributors(contributors);
|
||||
track.UpdateRatings(ratings);
|
||||
track.UpdateMoods(moods);
|
||||
track.UpdateIsrcs(isrcs);
|
||||
UpdatedOnUtc = DateTime.UtcNow;
|
||||
track.UpdateContributors(contributors);
|
||||
track.UpdateRatings(ratings);
|
||||
UpdatedOnUtc = Optional<DateTime>.Some(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="album">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>
|
||||
@@ -358,10 +361,10 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
/// 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)
|
||||
public Result<Created> AddTrackToAlbum(Album album, Track track)
|
||||
{
|
||||
Album? album = _albums.FirstOrDefault(album => album.Id == albumId);
|
||||
if (album is null)
|
||||
// The album is an entity inside this aggregate, referenced by object, so it must be one of the albums of the artist.
|
||||
if (!_albums.Contains(album))
|
||||
return Errors.Music.AlbumNotFound;
|
||||
|
||||
Result<Created> addResult = album.AddTrack(track);
|
||||
@@ -374,21 +377,19 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
/// <summary>
|
||||
/// Removes a track from an album of the artist.
|
||||
/// </summary>
|
||||
/// <param name="albumId">The Id of the album the track is removed from.</param>
|
||||
/// <param name="trackId">The Id of the track to remove.</param>
|
||||
/// <param name="album">The album the track is removed from.</param>
|
||||
/// <param name="track">The track to remove.</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 removed through its owning artist,
|
||||
/// which is the consistency boundary. This difference is intentional.
|
||||
/// </remarks>
|
||||
public Result<Deleted> RemoveTrackFromAlbum(AlbumId albumId, TrackId trackId)
|
||||
public Result<Deleted> RemoveTrackFromAlbum(Album album, Track track)
|
||||
{
|
||||
Album? album = _albums.FirstOrDefault(album => album.Id == albumId);
|
||||
if (album is null)
|
||||
// The album and the track are entities inside this aggregate, referenced by object, so they must belong to the artist, respectively to the album.
|
||||
if (!_albums.Contains(album))
|
||||
return Errors.Music.AlbumNotFound;
|
||||
|
||||
Track? track = album.Tracks.FirstOrDefault(track => track.Id == trackId);
|
||||
if (track is null)
|
||||
if (!album.Tracks.Contains(track))
|
||||
return Errors.Music.TrackNotFound;
|
||||
|
||||
return album.RemoveTrack(track);
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.AddArtist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{libraryId}/artists</c> route.
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists</c> route.
|
||||
/// </summary>
|
||||
public class AddArtistEndpoint : BaseEndpoint<AddArtistRequest, IResult>
|
||||
{
|
||||
|
||||
+20
-20
@@ -458,10 +458,10 @@ public class AddArtistEndpointSummary : Summary<AddArtistEndpoint, AddArtistRequ
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].CreatedOnUtc, "The date and time when the track was created.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Ratings, "The list of ratings for the track.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Moods, "The list of moods of the track.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Ratings, "The list of ratings for the track.");
|
||||
ResponseParam<ArtistResponse>(r => r.CreatedOnUtc, "The date and time when the artist was created.");
|
||||
ResponseParam<ArtistResponse>(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable.");
|
||||
|
||||
@@ -610,6 +610,15 @@ public class AddArtistEndpointSummary : Summary<AddArtistEndpoint, AddArtistRequ
|
||||
MusicBrainzWorkId: Guid.NewGuid(),
|
||||
CreatedOnUtc: DateTime.UtcNow,
|
||||
UpdatedOnUtc: default,
|
||||
Moods:
|
||||
[
|
||||
new(Name: "dramatic"),
|
||||
new(Name: "anxious")
|
||||
],
|
||||
Isrcs:
|
||||
[
|
||||
new(Value: "GBUM71029604")
|
||||
],
|
||||
Contributors:
|
||||
[
|
||||
new(
|
||||
@@ -635,15 +644,6 @@ public class AddArtistEndpointSummary : Summary<AddArtistEndpoint, AddArtistRequ
|
||||
Source: AudioRatingSource.LastFm,
|
||||
VoteCount: 1234
|
||||
)
|
||||
],
|
||||
Moods:
|
||||
[
|
||||
new(Name: "dramatic"),
|
||||
new(Name: "anxious")
|
||||
],
|
||||
Isrcs:
|
||||
[
|
||||
new(Value: "GBUM71029604")
|
||||
]
|
||||
),
|
||||
new(
|
||||
@@ -701,6 +701,15 @@ public class AddArtistEndpointSummary : Summary<AddArtistEndpoint, AddArtistRequ
|
||||
MusicBrainzWorkId: Guid.NewGuid(),
|
||||
CreatedOnUtc: DateTime.UtcNow,
|
||||
UpdatedOnUtc: default,
|
||||
Moods:
|
||||
[
|
||||
new(Name: "happy"),
|
||||
new(Name: "warm")
|
||||
],
|
||||
Isrcs:
|
||||
[
|
||||
new(Value: "GBUM71029609")
|
||||
],
|
||||
Contributors:
|
||||
[
|
||||
new(
|
||||
@@ -726,15 +735,6 @@ public class AddArtistEndpointSummary : Summary<AddArtistEndpoint, AddArtistRequ
|
||||
Source: AudioRatingSource.LastFm,
|
||||
VoteCount: 567
|
||||
)
|
||||
],
|
||||
Moods:
|
||||
[
|
||||
new(Name: "happy"),
|
||||
new(Name: "warm")
|
||||
],
|
||||
Isrcs:
|
||||
[
|
||||
new(Value: "GBUM71029609")
|
||||
]
|
||||
)
|
||||
]
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ public class DeleteArtistEndpointSummary : Summary<DeleteArtistEndpoint, EmptyRe
|
||||
public DeleteArtistEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes an existing artist.";
|
||||
Description = "Deletes the artist identified by the request, together with its albums and tracks. The artist is deleted by an Admin, who can delete the artists of all libraries, or by the owner of the library of the artist.";
|
||||
Description = "Deletes the artist identified by the route, together with its albums and tracks. The artist is deleted by an Admin, who can delete the artists of all libraries, or by the owner of the library of the artist.";
|
||||
|
||||
Response(200, "The artist was successfully deleted.");
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetArtist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/artists/{artistId}</c> route.
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}</c> route.
|
||||
/// </summary>
|
||||
public class GetArtistEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
|
||||
+3
-2
@@ -59,7 +59,7 @@ public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, EmptyRequest>
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}"
|
||||
},
|
||||
new
|
||||
@@ -67,7 +67,7 @@ public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, EmptyRequest>
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
detail = "The token has expired",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}"
|
||||
},
|
||||
new
|
||||
@@ -118,6 +118,7 @@ public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, EmptyRequest>
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty",
|
||||
"ArtistIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetArtistAlbums;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/artists/{artistId}/albums</c> route.
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums</c> route.
|
||||
/// </summary>
|
||||
public class GetArtistAlbumsEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
|
||||
+3
-2
@@ -225,7 +225,7 @@ public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, E
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums"
|
||||
},
|
||||
new
|
||||
@@ -233,7 +233,7 @@ public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, E
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
detail = "The token has expired",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums"
|
||||
},
|
||||
new
|
||||
@@ -284,6 +284,7 @@ public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, E
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty",
|
||||
"ArtistIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetArtistAlbumsLite;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/artists/{artistId}/albums/lite</c> route.
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums/lite</c> route.
|
||||
/// </summary>
|
||||
public class GetArtistAlbumsLiteEndpoint : BaseEndpoint<GetArtistAlbumsLiteRequest, IResult>
|
||||
{
|
||||
|
||||
+3
-2
@@ -67,7 +67,7 @@ public class GetArtistAlbumsLiteEndpointSummary : Summary<GetArtistAlbumsLiteEnd
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/lite"
|
||||
},
|
||||
new
|
||||
@@ -75,7 +75,7 @@ public class GetArtistAlbumsLiteEndpointSummary : Summary<GetArtistAlbumsLiteEnd
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
detail = "The token has expired",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/lite"
|
||||
},
|
||||
new
|
||||
@@ -126,6 +126,7 @@ public class GetArtistAlbumsLiteEndpointSummary : Summary<GetArtistAlbumsLiteEnd
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty",
|
||||
"ArtistIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetArtists;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/artists</c> route.
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists</c> route.
|
||||
/// </summary>
|
||||
public class GetArtistsEndpoint : BaseEndpoint<GetArtistsRequest, IResult>
|
||||
{
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ public class GetArtistsEndpointSummary : Summary<GetArtistsEndpoint, GetArtistsR
|
||||
public GetArtistsEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the list of artists of a media library.";
|
||||
Description = "Returns the paginated list of the artists of the media library identified by the request, with the full details of each artist. The page is returned to an Admin, who can see the artists of all libraries, or to the owner of the library.";
|
||||
Description = "Returns the paginated list of the artists of the media library identified by the route, with the full details of each artist. The page is returned to an Admin, who can see the artists of all libraries, or to the owner of the library.";
|
||||
|
||||
ExampleRequest = new GetArtistsRequest(
|
||||
CurrentPage: 1,
|
||||
@@ -87,7 +87,7 @@ public class GetArtistsEndpointSummary : Summary<GetArtistsEndpoint, GetArtistsR
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists"
|
||||
},
|
||||
new
|
||||
@@ -95,7 +95,7 @@ public class GetArtistsEndpointSummary : Summary<GetArtistsEndpoint, GetArtistsR
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
detail = "The token has expired",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists"
|
||||
},
|
||||
new
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetArtistsLite;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/artists/lite</c> route.
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/lite</c> route.
|
||||
/// </summary>
|
||||
public class GetArtistsLiteEndpoint : BaseEndpoint<GetArtistsLiteRequest, IResult>
|
||||
{
|
||||
|
||||
+2
-2
@@ -66,7 +66,7 @@ public class GetArtistsLiteEndpointSummary : Summary<GetArtistsLiteEndpoint, Get
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/lite"
|
||||
},
|
||||
new
|
||||
@@ -74,7 +74,7 @@ public class GetArtistsLiteEndpointSummary : Summary<GetArtistsLiteEndpoint, Get
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
detail = "The token has expired",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/lite"
|
||||
},
|
||||
new
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.UpdateArtist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{libraryId}/artists/{artistId}</c> route.
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}</c> route.
|
||||
/// </summary>
|
||||
public class UpdateArtistEndpoint : BaseEndpoint<UpdateArtistRequest, IResult>
|
||||
{
|
||||
|
||||
+36
-23
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
@@ -30,7 +30,7 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
public UpdateArtistEndpointSummary()
|
||||
{
|
||||
Summary = "Updates an existing artist.";
|
||||
Description = "Updates the details of the artist identified by the request, together with its contributors and albums, returning the full details of the updated artist. The artist is updated by an Admin, who can update the artists of all libraries, or by the owner of the library of the artist.";
|
||||
Description = "Updates the details of the artist identified by the route, together with its contributors and albums, returning the full details of the updated artist. The artist is updated by an Admin, who can update the artists of all libraries, or by the owner of the library of the artist.";
|
||||
|
||||
RequestParam(r => r.Name, "The name of the artist. Required.");
|
||||
RequestParam(r => r.Website, "The website of the artist. Optional.");
|
||||
@@ -457,10 +457,10 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].CreatedOnUtc, "The date and time when the track was created.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Ratings, "The list of ratings for the track.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Moods, "The list of moods of the track.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Ratings, "The list of ratings for the track.");
|
||||
ResponseParam<ArtistResponse>(r => r.CreatedOnUtc, "The date and time when the artist was created.");
|
||||
ResponseParam<ArtistResponse>(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable.");
|
||||
|
||||
@@ -614,6 +614,15 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
MusicBrainzWorkId: Guid.NewGuid(),
|
||||
CreatedOnUtc: DateTime.UtcNow,
|
||||
UpdatedOnUtc: DateTime.UtcNow,
|
||||
Moods:
|
||||
[
|
||||
new MoodDto(Name: "dramatic"),
|
||||
new MoodDto(Name: "anxious")
|
||||
],
|
||||
Isrcs:
|
||||
[
|
||||
new IsrcDto(Value: "GBUM71029604")
|
||||
],
|
||||
Contributors:
|
||||
[
|
||||
new MediaContributorReferenceDto(
|
||||
@@ -639,15 +648,6 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
Source: AudioRatingSource.LastFm,
|
||||
VoteCount: 1234
|
||||
)
|
||||
],
|
||||
Moods:
|
||||
[
|
||||
new MoodDto(Name: "dramatic"),
|
||||
new MoodDto(Name: "anxious")
|
||||
],
|
||||
Isrcs:
|
||||
[
|
||||
new IsrcDto(Value: "GBUM71029604")
|
||||
]
|
||||
),
|
||||
new TrackResponse(
|
||||
@@ -705,6 +705,15 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
MusicBrainzWorkId: Guid.NewGuid(),
|
||||
CreatedOnUtc: DateTime.UtcNow,
|
||||
UpdatedOnUtc: DateTime.UtcNow,
|
||||
Moods:
|
||||
[
|
||||
new MoodDto(Name: "happy"),
|
||||
new MoodDto(Name: "warm")
|
||||
],
|
||||
Isrcs:
|
||||
[
|
||||
new IsrcDto(Value: "GBUM71029609")
|
||||
],
|
||||
Contributors:
|
||||
[
|
||||
new MediaContributorReferenceDto(
|
||||
@@ -730,15 +739,6 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
Source: AudioRatingSource.LastFm,
|
||||
VoteCount: 567
|
||||
)
|
||||
],
|
||||
Moods:
|
||||
[
|
||||
new MoodDto(Name: "happy"),
|
||||
new MoodDto(Name: "warm")
|
||||
],
|
||||
Isrcs:
|
||||
[
|
||||
new IsrcDto(Value: "GBUM71029609")
|
||||
]
|
||||
)
|
||||
]
|
||||
@@ -836,6 +836,18 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because the new artist name is already used in the library, or because a unique constraint was violated.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "UniqueConstraintViolation",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
@@ -910,7 +922,8 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
"BpmMustBeGreaterThanZero",
|
||||
"WorkMustBeMaximum255CharactersLong",
|
||||
"MoodNameCannotBeEmpty",
|
||||
"IsrcValueCannotBeEmpty"
|
||||
"IsrcValueCannotBeEmpty",
|
||||
"TrackPathMustBeWithinLibraryContentLocations"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user