Refactors the album slice across the stack

This commit is contained in:
BinaryAlley committed 2026-09-25 13:18:50 -07:00
1 parent b51013a9e9
commit e842c7baaf
20 files changed
+241 -206

No files matched your search

@@ -24,9 +24,6 @@
- [Get Album Tracks Lite](#get-album-tracks-lite)
- [Get Album Tracks Lite Request](#get-album-tracks-lite-request)
- [Get Album Tracks Lite Response](#get-album-tracks-lite-response)
- [Add Track](#add-track)
- [Add Track Request](#add-track-request)
- [Add Track Response](#add-track-response)
## Album
@@ -828,7 +825,89 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
200 Ok
```
The response carries the full details of the updated album, using the same shape as the [Get Album Response](#get-album-response).
```json
{
"id": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f",
"artistId": "d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a",
"libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
"metadata": {
"title": "A Night at the Opera",
"originalTitle": "A Night at the Opera",
"description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.",
"releaseType": "Album",
"releaseStatus": "Official",
"totalDiscs": 1,
"totalTracks": 12,
"releaseInfo": {
"originalReleaseDate": "1975-11-21",
"originalReleaseYear": 1975,
"reReleaseDate": null,
"reReleaseYear": null,
"releaseCountry": "GB",
"releaseVersion": "Remastered"
},
"language": {
"languageCode": "en",
"languageName": "English",
"nativeName": "English"
},
"originalLanguage": {
"languageCode": "en",
"languageName": "English",
"nativeName": "English"
},
"genres": [
{
"name": "Rock"
},
{
"name": "Progressive Rock"
}
],
"tags": [
{
"name": "classic"
},
{
"name": "vinyl"
}
]
},
"mediaFormat": "CD",
"barcode": "0042282778329",
"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": [
{
"value": 4.5,
"maxValue": 5,
"source": "MusicBrainz",
"voteCount": 2345
},
{
"value": 4.8,
"maxValue": 5,
"source": "LastFm",
"voteCount": 1234
}
],
"tracks": []
}
```
### Delete Album
@@ -841,7 +920,7 @@ DELETE api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f
200 Ok
```
Deletes the album identified by the path, together with its tracks. An artist must always keep at least one album.
Deletes the album identified by the route, together with its tracks. An artist must always keep at least one album.
### Get Album Tracks
@@ -892,6 +971,19 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
"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",
@@ -915,19 +1007,6 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
"source": "LastFm",
"voteCount": 1234
}
],
"moods": [
{
"name": "dramatic"
},
{
"name": "anxious"
}
],
"isrcs": [
{
"value": "GBUM71029604"
}
]
}
]
@@ -971,96 +1050,5 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
```
### Add Track
#### Add Track Request
```js
POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks
```
```json
{
"path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
"metadata": {
"title": "Bohemian Rhapsody",
"originalTitle": "Bohemian Rhapsody",
"description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
"durationInSeconds": 354,
"sampleRate": 44100,
"channels": 2,
"bitDepth": 16,
"audioCodec": "FLAC",
"bitrate": 980,
"releaseInfo": {
"originalReleaseDate": "1975-10-31",
"originalReleaseYear": 1975,
"reReleaseDate": null,
"reReleaseYear": null,
"releaseCountry": "GB",
"releaseVersion": "Original"
},
"language": {
"languageCode": "en",
"languageName": "English",
"nativeName": "English"
},
"originalLanguage": {
"languageCode": "en",
"languageName": "English",
"nativeName": "English"
},
"genres": [
{ "name": "Rock" },
{ "name": "Progressive Rock" }
],
"tags": [
{ "name": "classic" },
{ "name": "epic" }
]
},
"trackNumber": 1,
"discNumber": 1,
"script": "Latn",
"key": "CMajor",
"bpm": 72,
"work": "Bohemian Rhapsody",
"musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a",
"musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b",
"musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c",
"contributors": [
{ "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", "role": "Vocals" },
{ "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", "role": "Guitar" }
],
"ratings": [
{
"value": 4.5,
"maxValue": 5,
"source": "MusicBrainz",
"voteCount": 2345
},
{
"value": 4.8,
"maxValue": 5,
"source": "LastFm",
"voteCount": 1234
}
],
"moods": [
{ "name": "dramatic" },
{ "name": "anxious" }
],
"isrcs": [
{ "value": "GBUM71029604" }
]
}
```
#### Add Track Response
```js
201 Created
```
The response carries the full details of the newly created track, using the same shape as the [Get Track Response](Api.Tracks.md#get-track-response).
@@ -60,28 +60,13 @@ public static class AddAlbumCommandMapping
Optional<MusicBrainzId> musicBrainzReleaseId = Optional<MusicBrainzId>.None();
if (command.MusicBrainzReleaseId is not null)
{
Result<MusicBrainzId> musicBrainzReleaseIdResult = MusicBrainzId.Create(command.MusicBrainzReleaseId.Value);
if (musicBrainzReleaseIdResult.IsFailure)
return musicBrainzReleaseIdResult.Errors;
musicBrainzReleaseId = musicBrainzReleaseIdResult.Value;
}
musicBrainzReleaseId = MusicBrainzId.Create(command.MusicBrainzReleaseId.Value);
Optional<MusicBrainzId> musicBrainzReleaseGroupId = Optional<MusicBrainzId>.None();
if (command.MusicBrainzReleaseGroupId is not null)
{
Result<MusicBrainzId> musicBrainzReleaseGroupIdResult = MusicBrainzId.Create(command.MusicBrainzReleaseGroupId.Value);
if (musicBrainzReleaseGroupIdResult.IsFailure)
return musicBrainzReleaseGroupIdResult.Errors;
musicBrainzReleaseGroupId = musicBrainzReleaseGroupIdResult.Value;
}
musicBrainzReleaseGroupId = MusicBrainzId.Create(command.MusicBrainzReleaseGroupId.Value);
Optional<MusicBrainzId> musicBrainzReleaseArtistId = Optional<MusicBrainzId>.None();
if (command.MusicBrainzReleaseArtistId is not null)
{
Result<MusicBrainzId> musicBrainzReleaseArtistIdResult = MusicBrainzId.Create(command.MusicBrainzReleaseArtistId.Value);
if (musicBrainzReleaseArtistIdResult.IsFailure)
return musicBrainzReleaseArtistIdResult.Errors;
musicBrainzReleaseArtistId = musicBrainzReleaseArtistIdResult.Value;
}
musicBrainzReleaseArtistId = MusicBrainzId.Create(command.MusicBrainzReleaseArtistId.Value);
List<MusicMediaContributor> contributors = [.. domainContributorsResult.Select(contributorResult => contributorResult.Value)];
List<AudioRating> ratings = [.. domainRatingsResult.Select(ratingResult => ratingResult.Value)];
@@ -99,28 +99,13 @@ public static class AlbumEntityMapping
Optional<MusicBrainzId> musicBrainzReleaseId = Optional<MusicBrainzId>.None();
if (repositoryEntity.MusicBrainzReleaseId is not null)
{
Result<MusicBrainzId> musicBrainzReleaseIdResult = MusicBrainzId.Create(repositoryEntity.MusicBrainzReleaseId.Value);
if (musicBrainzReleaseIdResult.IsFailure)
return musicBrainzReleaseIdResult.Errors;
musicBrainzReleaseId = musicBrainzReleaseIdResult.Value;
}
musicBrainzReleaseId = MusicBrainzId.Create(repositoryEntity.MusicBrainzReleaseId.Value);
Optional<MusicBrainzId> musicBrainzReleaseGroupId = Optional<MusicBrainzId>.None();
if (repositoryEntity.MusicBrainzReleaseGroupId is not null)
{
Result<MusicBrainzId> musicBrainzReleaseGroupIdResult = MusicBrainzId.Create(repositoryEntity.MusicBrainzReleaseGroupId.Value);
if (musicBrainzReleaseGroupIdResult.IsFailure)
return musicBrainzReleaseGroupIdResult.Errors;
musicBrainzReleaseGroupId = musicBrainzReleaseGroupIdResult.Value;
}
musicBrainzReleaseGroupId = MusicBrainzId.Create(repositoryEntity.MusicBrainzReleaseGroupId.Value);
Optional<MusicBrainzId> musicBrainzReleaseArtistId = Optional<MusicBrainzId>.None();
if (repositoryEntity.MusicBrainzReleaseArtistId is not null)
{
Result<MusicBrainzId> musicBrainzReleaseArtistIdResult = MusicBrainzId.Create(repositoryEntity.MusicBrainzReleaseArtistId.Value);
if (musicBrainzReleaseArtistIdResult.IsFailure)
return musicBrainzReleaseArtistIdResult.Errors;
musicBrainzReleaseArtistId = musicBrainzReleaseArtistIdResult.Value;
}
musicBrainzReleaseArtistId = MusicBrainzId.Create(repositoryEntity.MusicBrainzReleaseArtistId.Value);
List<AudioRating> domainRatings = [];
foreach (Result<AudioRating> ratingResult in repositoryEntity.Ratings.ToDomainEntities())
@@ -5,11 +5,13 @@ using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Comm
using Lumina.Domain.Common.Primitives;
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;
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
#endregion
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
@@ -54,31 +56,21 @@ public static class UpdateAlbumCommandMapping
Optional<MusicBrainzId> musicBrainzReleaseId = Optional<MusicBrainzId>.None();
if (command.MusicBrainzReleaseId is not null)
{
Result<MusicBrainzId> musicBrainzReleaseIdResult = MusicBrainzId.Create(command.MusicBrainzReleaseId.Value);
if (musicBrainzReleaseIdResult.IsFailure)
return musicBrainzReleaseIdResult.Errors;
musicBrainzReleaseId = musicBrainzReleaseIdResult.Value;
}
musicBrainzReleaseId = MusicBrainzId.Create(command.MusicBrainzReleaseId.Value);
Optional<MusicBrainzId> musicBrainzReleaseGroupId = Optional<MusicBrainzId>.None();
if (command.MusicBrainzReleaseGroupId is not null)
{
Result<MusicBrainzId> musicBrainzReleaseGroupIdResult = MusicBrainzId.Create(command.MusicBrainzReleaseGroupId.Value);
if (musicBrainzReleaseGroupIdResult.IsFailure)
return musicBrainzReleaseGroupIdResult.Errors;
musicBrainzReleaseGroupId = musicBrainzReleaseGroupIdResult.Value;
}
musicBrainzReleaseGroupId = MusicBrainzId.Create(command.MusicBrainzReleaseGroupId.Value);
Optional<MusicBrainzId> musicBrainzReleaseArtistId = Optional<MusicBrainzId>.None();
if (command.MusicBrainzReleaseArtistId is not null)
{
Result<MusicBrainzId> musicBrainzReleaseArtistIdResult = MusicBrainzId.Create(command.MusicBrainzReleaseArtistId.Value);
if (musicBrainzReleaseArtistIdResult.IsFailure)
return musicBrainzReleaseArtistIdResult.Errors;
musicBrainzReleaseArtistId = musicBrainzReleaseArtistIdResult.Value;
}
musicBrainzReleaseArtistId = MusicBrainzId.Create(command.MusicBrainzReleaseArtistId.Value);
// The album is an entity inside the artist aggregate, so it is referenced by object, not by id; the aggregate member is located here and passed through.
Album? album = artist.Albums.FirstOrDefault(album => album.Id.Value == Guid.Parse(command.AlbumId!));
if (album is null)
return DomainErrors.Music.AlbumNotFound;
Result<Updated> updateResult = artist.UpdateAlbum(
AlbumId.Create(Guid.Parse(command.AlbumId!)),
album,
metadataResult.Value,
Optional<MusicMediaFormat>.FromNullable(command.MediaFormat),
barcode,
@@ -429,7 +429,27 @@ public class AddAlbumCommandValidator : AbstractValidator<AddAlbumCommand>
.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)
@@ -79,13 +79,10 @@ public class DeleteAlbumCommandHandler : ICommandHandler<DeleteAlbumCommand, Res
return DomainErrors.Music.ArtistNotFound;
ArtistEntity existingArtist = getArtistResult.Value;
// Resource scoping: the album must belong to an artist of the library named by the route, so that an album can never be deleted
// through another library's or artist's route; the mismatch is reported as not found, without disclosing that the album exists elsewhere.
// Resource scoping: the album must belong to an artist of the library named by the route, so that an album can never be deleted through
// another library's route; the mismatch is reported as not found, without disclosing that the artist exists in another library.
if (existingArtist.LibraryId != libraryId)
return DomainErrors.Music.AlbumNotFound;
AlbumEntity? existingAlbum = existingArtist.Albums.FirstOrDefault(album => album.Id == albumId);
if (existingAlbum is null)
return DomainErrors.Music.AlbumNotFound;
return DomainErrors.Music.ArtistNotFound;
// Admins can delete the albums of all libraries; for everyone else, only the albums of the libraries they own.
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
@@ -93,6 +90,10 @@ public class DeleteAlbumCommandHandler : ICommandHandler<DeleteAlbumCommand, Res
if (!canAccessLibrary)
return ApplicationErrors.Authorization.NotAuthorized;
AlbumEntity? existingAlbum = existingArtist.Albums.FirstOrDefault(album => album.Id == albumId);
if (existingAlbum is null)
return DomainErrors.Music.AlbumNotFound;
// An album can only belong to a library that exists, so a client can never delete an album of a library of the host that is not there.
Result<LibraryEntity?> getLibraryResult = await _unitOfWork.LibraryRepository
.GetByIdAsync(libraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
@@ -106,6 +107,7 @@ public class DeleteAlbumCommandHandler : ICommandHandler<DeleteAlbumCommand, Res
Result<Artist> artistResult = existingArtist.ToDomainEntity();
if (artistResult.IsFailure)
return artistResult.Errors;
// The album is an entity inside the artist aggregate, so it is referenced by object, not by id; the aggregate member is located here and passed through.
Album? domainAlbum = artistResult.Value.Albums.FirstOrDefault(album => album.Id.Value == albumId);
if (domainAlbum is null)
return DomainErrors.Music.AlbumNotFound;
@@ -92,14 +92,14 @@ public class UpdateAlbumCommandHandler : ICommandHandler<UpdateAlbumCommand, Res
if (getArtistResult.IsFailure)
return getArtistResult.Errors;
// Resource scoping: the album must belong to the library and the artist named by the route, so that an album can never be edited
// through another library's or artist's route; the mismatch is reported as not found, without disclosing that the album exists elsewhere.
if (getArtistResult.Value is null || getArtistResult.Value.LibraryId != libraryId)
return Errors.Music.AlbumNotFound;
if (getArtistResult.Value is null)
return Errors.Music.ArtistNotFound;
ArtistEntity existingArtist = getArtistResult.Value;
AlbumEntity? existingAlbum = existingArtist.Albums.FirstOrDefault(album => album.Id == albumId);
if (existingAlbum is null)
return Errors.Music.AlbumNotFound;
// Resource scoping: the album must belong to an artist of the library named by the route, so that an album can never be edited through
// another library's route; the mismatch is reported as not found, without disclosing that the artist exists in another library.
if (existingArtist.LibraryId != libraryId)
return Errors.Music.ArtistNotFound;
// Admins can update the albums of all libraries; for everyone else, only the albums of the libraries they own.
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
@@ -107,6 +107,10 @@ public class UpdateAlbumCommandHandler : ICommandHandler<UpdateAlbumCommand, Res
if (!canAccessLibrary)
return ApplicationErrors.Authorization.NotAuthorized;
AlbumEntity? existingAlbum = existingArtist.Albums.FirstOrDefault(album => album.Id == albumId);
if (existingAlbum is null)
return Errors.Music.AlbumNotFound;
// An album can only belong to a library that exists, so a client can never update an album of a library of the host that is not there.
Result<LibraryEntity?> getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(libraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsFailure)
@@ -119,8 +123,8 @@ public class UpdateAlbumCommandHandler : ICommandHandler<UpdateAlbumCommand, Res
if (getContributorsResult.IsFailure)
return getContributorsResult.Errors;
// The write path goes through the aggregate root: an album is a child entity of the artist aggregate, unlike Book and Artist,
// which are aggregate roots and are reconstituted directly with their own Create method. This difference is intentional.
// The write path goes through the aggregate root: an album is a child entity of the artist aggregate, so it is mutated through its owning
// artist. Book is itself an aggregate root, so its update flow reconstitutes it directly with its own Create method instead.
Result<Artist> artistResult = existingArtist.ToDomainEntity();
if (artistResult.IsFailure)
return artistResult.Errors;
@@ -24,14 +24,17 @@ namespace Lumina.DataAccess.Core.Repositories.MusicLibrary;
internal sealed class AlbumRepository : IAlbumRepository
{
private readonly LuminaDbContext _luminaDbContext;
private readonly ITrackRepository _trackRepository;
/// <summary>
/// Initializes a new instance of the <see cref="AlbumRepository"/> class.
/// </summary>
/// <param name="luminaDbContext">Injected Entity Framework DbContext.</param>
public AlbumRepository(LuminaDbContext luminaDbContext)
/// <param name="trackRepository">Injected repository for tracks.</param>
public AlbumRepository(LuminaDbContext luminaDbContext, ITrackRepository trackRepository)
{
_luminaDbContext = luminaDbContext;
_trackRepository = trackRepository;
}
/// <summary>
@@ -46,6 +49,12 @@ internal sealed class AlbumRepository : IAlbumRepository
if (doesAlbumExist)
return Errors.Music.AlbumAlreadyExists;
// 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 album, because the insert of the album inserts its tracks as well.
Result<Success> checkTrackPathsResult = await CheckTrackPathsAsync(album, 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 = [.. album.Tags.Select(tag => tag.Name!)
.Concat(album.Tracks.SelectMany(track => track.Tags.Select(tag => tag.Name!)))
@@ -75,6 +84,30 @@ internal sealed class AlbumRepository : IAlbumRepository
return Result.Created;
}
/// <summary>
/// Checks whether the tracks carried by <paramref name="album"/> reference a file system path that is already used by a track of the same library.
/// </summary>
/// <param name="album">The album whose track paths are checked.</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(AlbumEntity album, CancellationToken cancellationToken)
{
List<string> trackPaths = [.. album.Tracks.Select(track => track.Path!)];
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(album.LibraryId, trackPaths, cancellationToken).ConfigureAwait(false);
if (getExistingPathsResult.IsFailure)
return getExistingPathsResult.Errors;
if (getExistingPathsResult.Value.Count > 0)
return Errors.Music.TrackAlreadyExists;
return Result.Success;
}
/// <summary>
/// Updates an existing album, replacing only the editable data that actually changed, while preserving its identity, the identity of its children, and its audit columns.
/// </summary>
@@ -115,7 +115,7 @@ public sealed class Album : Entity<AlbumId>
_ratings = ratings;
_tracks = tracks;
CreatedOnUtc = createdOnUtc;
UpdatedOnUtc = updatedOnUtc.HasValue ? updatedOnUtc.Value : null;
UpdatedOnUtc = updatedOnUtc;
}
/// <summary>
@@ -287,7 +287,7 @@ public sealed class Album : Entity<AlbumId>
MusicBrainzReleaseId = musicBrainzReleaseId;
MusicBrainzReleaseGroupId = musicBrainzReleaseGroupId;
MusicBrainzReleaseArtistId = musicBrainzReleaseArtistId;
UpdatedOnUtc = DateTime.UtcNow;
UpdatedOnUtc = Optional<DateTime>.Some(DateTime.UtcNow);
return Result.Updated;
}
}
@@ -18,6 +18,5 @@ public static partial class ApiRoutes
public const string DELETE_ALBUM = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}";
public const string GET_ALBUM_TRACKS = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks";
public const string GET_ALBUM_TRACKS_LITE = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite";
public const string ADD_TRACK = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks";
}
}
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.AddAlbum;
/// <summary>
/// API endpoint for the <c>/{libraryId}/artists/{artistId}/albums</c> route.
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums</c> route.
/// </summary>
public class AddAlbumEndpoint : BaseEndpoint<AddAlbumRequest, IResult>
{
@@ -19,7 +19,7 @@ public class DeleteAlbumEndpointSummary : Summary<DeleteAlbumEndpoint, EmptyRequ
public DeleteAlbumEndpointSummary()
{
Summary = "Deletes an existing album.";
Description = "Deletes the album identified by the path, together with its tracks. An artist must always keep at least one album. The album is deleted by an Admin, who can delete the albums of all libraries, or by the owner of the library of the album.";
Description = "Deletes the album identified by the route, together with its tracks. An artist must always keep at least one album. The album is deleted by an Admin, who can delete the albums of all libraries, or by the owner of the library of the album.";
Response(200, "The album was successfully deleted.");
@@ -14,7 +14,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetAlbum;
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums/{albumId}</c> route.
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums/{albumId}</c> route.
/// </summary>
public class GetAlbumEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
{
@@ -149,7 +149,7 @@ public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, 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()}/albums/{Guid.NewGuid()}"
},
new
@@ -157,7 +157,7 @@ public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, 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()}/albums/{Guid.NewGuid()}"
},
new
@@ -208,6 +208,8 @@ public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, EmptyRequest>
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"ArtistIdCannotBeEmpty",
"AlbumIdCannotBeEmpty"
}
}
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetAlbumTracks;
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums/{albumId}/tracks</c> route.
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks</c> route.
/// </summary>
public class GetAlbumTracksEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
{
@@ -47,6 +47,8 @@ public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, Emp
ResponseParam<TrackResponse>(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
ResponseParam<TrackResponse>(r => r.CreatedOnUtc, "The date and time when the track was created.");
ResponseParam<TrackResponse>(r => r.UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
ResponseParam<TrackResponse>(r => r.Moods, "The list of moods of the track.");
ResponseParam<TrackResponse>(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
ResponseParam<TrackResponse>(r => r.Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
ResponseParam<TrackResponse>(r => r.Ratings, "The list of ratings for this track.");
ResponseParam<TrackResponse>(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
@@ -69,8 +71,6 @@ public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, Emp
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Genres, "The list of genres associated with the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track.");
ResponseParam<TrackResponse>(r => r.Moods, "The list of moods of the track.");
ResponseParam<TrackResponse>(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
Response(200, "The list of tracks of the album is returned.",
example: new TrackResponse[]
@@ -256,7 +256,7 @@ public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, Emp
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/{Guid.NewGuid()}/tracks"
},
new
@@ -264,7 +264,7 @@ public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, Emp
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/{Guid.NewGuid()}/tracks"
},
new
@@ -315,6 +315,8 @@ public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, Emp
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"ArtistIdCannotBeEmpty",
"AlbumIdCannotBeEmpty"
}
}
@@ -17,7 +17,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetAlbumTracksLite;
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums/{albumId}/tracks/lite</c> route.
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite</c> route.
/// </summary>
public class GetAlbumTracksLiteEndpoint : BaseEndpoint<GetAlbumTracksLiteRequest, IResult>
{
@@ -70,7 +70,7 @@ public class GetAlbumTracksLiteEndpointSummary : Summary<GetAlbumTracksLiteEndpo
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/{Guid.NewGuid()}/tracks/lite"
},
new
@@ -78,7 +78,7 @@ public class GetAlbumTracksLiteEndpointSummary : Summary<GetAlbumTracksLiteEndpo
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/{Guid.NewGuid()}/tracks/lite"
},
new
@@ -129,6 +129,8 @@ public class GetAlbumTracksLiteEndpointSummary : Summary<GetAlbumTracksLiteEndpo
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"ArtistIdCannotBeEmpty",
"AlbumIdCannotBeEmpty"
}
}
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.UpdateAlbum;
/// <summary>
/// API endpoint for the <c>/{libraryId}/artists/{artistId}/albums/{albumId}</c> route.
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums/{albumId}</c> route.
/// </summary>
public class UpdateAlbumEndpoint : BaseEndpoint<UpdateAlbumRequest, IResult>
{
@@ -28,13 +28,13 @@ public class UpdateAlbumEndpointSummary : Summary<UpdateAlbumEndpoint, UpdateAlb
public UpdateAlbumEndpointSummary()
{
Summary = "Updates an existing album.";
Description = "Updates the details of the album identified by the request, returning the full details of the updated album. The album is updated by an Admin, who can update the albums of all libraries, or by the owner of the library of the album.";
Description = "Updates the details of the album identified by the route, returning the full details of the updated album. The album is updated by an Admin, who can update the albums of all libraries, or by the owner of the library of the album.";
RequestParam(r => r.Metadata, "The album metadata of the album. Required.");
RequestParam(r => r.Metadata!.Title, "The title of the album. Required.");
RequestParam(r => r.Metadata!.OriginalTitle, "The original title of the album. Optional.");
RequestParam(r => r.Metadata!.Description, "The description of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Required.");
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the album. Optional.");
@@ -46,15 +46,15 @@ public class UpdateAlbumEndpointSummary : Summary<UpdateAlbumEndpoint, UpdateAlb
RequestParam(r => r.Metadata!.TotalDiscs, "The number of discs of the release. Optional.");
RequestParam(r => r.Metadata!.TotalTracks, "The number of tracks of the release. Optional.");
RequestParam(r => r.Metadata!.Language, "The language of the album. Optional.");
RequestParam(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the album. Optional.");
RequestParam(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the album in English. Optional.");
RequestParam(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the album. Required.");
RequestParam(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the album in English. Required.");
RequestParam(r => r.Metadata!.Language!.NativeName, "The native name of the language of the album. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage, "The original language of the album, if it has been translated. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the album. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the album in English. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the album. Required.");
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the album in English. Required.");
RequestParam(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the album. Optional.");
RequestParam(r => r.Metadata!.Genres, "The list of genres associated with the album. Optional.");
RequestParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album. Optional.");
RequestParam(r => r.Metadata!.Genres, "The list of genres associated with the album. Required.");
RequestParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album. Required.");
RequestParam(r => r.MediaFormat, "The physical or digital medium of the album. Optional.");
RequestParam(r => r.Barcode, "The barcode of the album. Optional.");
RequestParam(r => r.CatalogNumber, "The catalog number of the album. Optional.");
@@ -290,9 +290,18 @@ public class UpdateAlbumEndpointSummary : Summary<UpdateAlbumEndpoint, UpdateAlb
}
);
Response(404, "The request failed because the requested album, its media library, or one of the referenced media contributors does not exist.", "application/problem+json",
Response(404, "The request failed because the requested artist or album, its media library, or one of the referenced media contributors does not exist.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ArtistNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
@@ -323,6 +332,18 @@ public class UpdateAlbumEndpointSummary : Summary<UpdateAlbumEndpoint, UpdateAlb
}
);
Response(409, "The request failed 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()}/albums/{Guid.NewGuid()}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(422, "The request did not pass validation checks.", "application/problem+json",
example: new
{