diff --git a/docs/technical/api/library/audio-library/music-library/Api.Albums.md b/docs/technical/api/library/audio-library/music-library/Api.Albums.md index 8d95e6ef..f059f603 100644 --- a/docs/technical/api/library/audio-library/music-library/Api.Albums.md +++ b/docs/technical/api/library/audio-library/music-library/Api.Albums.md @@ -18,6 +18,15 @@ - [Update Album Request](#update-album-request) - [Update Album Response](#update-album-response) - [Delete Album](#delete-album) + - [Get Album Tracks](#get-album-tracks) + - [Get Album Tracks Request](#get-album-tracks-request) + - [Get Album Tracks Response](#get-album-tracks-response) + - [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 @@ -825,12 +834,233 @@ The response carries the full details of the updated album, using the same shape ### Delete Album ```js -DELETE api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f +DELETE api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/{albumId} ``` ```js 200 Ok ``` -Deletes the album identified by the path, together with its tracks. +Deletes the album identified by the path, together with its tracks. An artist must always keep at least one album. + + +### Get Album Tracks + +#### Get Album Tracks Request + +```js +GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks +``` + +#### Get Album Tracks Response + +```js +200 Ok +``` + +```json +[ + { + "id": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f", + "albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "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.", + "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" }, + "tags": [ { "name": "classic" }, { "name": "epic" } ], + "genres": [ { "name": "Rock" }, { "name": "Progressive Rock" } ], + "durationInSeconds": 354, + "sampleRate": 44100, + "channels": 2, + "bitDepth": 16, + "audioCodec": "FLAC", + "bitrate": 980 + }, + "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", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": null, + "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" + } + ] + } +] +``` + + +### Get Album Tracks Lite + +#### Get Album Tracks Lite Request + +```js +GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/lite?currentPage=1&perPage=10 +``` + +| Query Parameter | Type | Description | +| --- | --- | --- | +| `currentPage` | `int` | Optional. The page of results to retrieve. | +| `perPage` | `int` | Optional. The maximum number of tracks to retrieve per page. | + +#### Get Album Tracks Lite Response + +```js +200 Ok +``` + +```json +{ + "data": [ + { + "id": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f", + "title": "Bohemian Rhapsody", + "trackNumber": 1, + "discNumber": 1 + } + ], + "currentPage": 1, + "perPage": 10, + "count": 1, + "numberOfPages": 1 +} +``` + + +### 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). diff --git a/docs/technical/requests/library/audio-library/music-library/albums/DeleteAlbum.http b/docs/technical/requests/library/audio-library/music-library/albums/DeleteAlbum.http index 476d72c9..fcb6dc9a 100644 --- a/docs/technical/requests/library/audio-library/music-library/albums/DeleteAlbum.http +++ b/docs/technical/requests/library/audio-library/music-library/albums/DeleteAlbum.http @@ -1,2 +1,2 @@ -DELETE {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f +DELETE {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/{{$guid}} Authorization: Bearer {{ACCESS_TOKEN}} diff --git a/docs/technical/requests/library/audio-library/music-library/albums/GetAlbum.http b/docs/technical/requests/library/audio-library/music-library/albums/GetAlbum.http index 5eceaf23..c15bbe79 100644 --- a/docs/technical/requests/library/audio-library/music-library/albums/GetAlbum.http +++ b/docs/technical/requests/library/audio-library/music-library/albums/GetAlbum.http @@ -1,2 +1,2 @@ -GET {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f +GET {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/{{$guid}} Authorization: Bearer {{ACCESS_TOKEN}} diff --git a/docs/technical/requests/library/audio-library/music-library/albums/GetAlbumTracks.http b/docs/technical/requests/library/audio-library/music-library/albums/GetAlbumTracks.http index 515d9753..0ac09042 100644 --- a/docs/technical/requests/library/audio-library/music-library/albums/GetAlbumTracks.http +++ b/docs/technical/requests/library/audio-library/music-library/albums/GetAlbumTracks.http @@ -1,2 +1,2 @@ -GET {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks +GET {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/{{$guid}}/tracks Authorization: Bearer {{ACCESS_TOKEN}} diff --git a/docs/technical/requests/library/audio-library/music-library/albums/GetAlbumTracksLite.http b/docs/technical/requests/library/audio-library/music-library/albums/GetAlbumTracksLite.http index f61e8a86..51a5f3b4 100644 --- a/docs/technical/requests/library/audio-library/music-library/albums/GetAlbumTracksLite.http +++ b/docs/technical/requests/library/audio-library/music-library/albums/GetAlbumTracksLite.http @@ -1,2 +1,2 @@ -GET {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/lite?currentPage=1&perPage=10 +GET {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/{{$guid}}/tracks/lite?currentPage=1&perPage=10 Authorization: Bearer {{ACCESS_TOKEN}} diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IAlbumRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IAlbumRepository.cs index 6928b9db..5a12079b 100644 --- a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IAlbumRepository.cs +++ b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/IAlbumRepository.cs @@ -19,8 +19,7 @@ namespace Lumina.Application.Common.DataAccess.Repositories.MusicLibrary; public interface IAlbumRepository : IRepository, IInsertRepositoryAction, IUpdateRepositoryAction, - IGetByIdRepositoryAction, - IDeleteByIdRepositoryAction + IGetByIdRepositoryAction { /// /// Gets all the albums of the artist identified by . diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/DeleteAlbumRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/DeleteAlbumRequestMapping.cs deleted file mode 100644 index ed99467e..00000000 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/DeleteAlbumRequestMapping.cs +++ /dev/null @@ -1,23 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.DeleteAlbum; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; -#endregion - -namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums; - -/// -/// Extension methods for converting . -/// -public static class DeleteAlbumRequestMapping -{ - /// - /// Converts to . - /// - /// The request to be converted. - /// The converted command. - public static DeleteAlbumCommand ToCommand(this DeleteAlbumRequest request) - { - return new DeleteAlbumCommand( - request.AlbumId); - } -} diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumRequestMapping.cs deleted file mode 100644 index c2d8e3e7..00000000 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumRequestMapping.cs +++ /dev/null @@ -1,23 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Queries.GetAlbum; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; -#endregion - -namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums; - -/// -/// Extension methods for converting . -/// -public static class GetAlbumRequestMapping -{ - /// - /// Converts to . - /// - /// The request to be converted. - /// The converted query. - public static GetAlbumQuery ToQuery(this GetAlbumRequest request) - { - return new GetAlbumQuery( - request.AlbumId); - } -} diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLiteRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLiteRequestMapping.cs index 2b2e42c6..602efa84 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLiteRequestMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLiteRequestMapping.cs @@ -1,4 +1,5 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DTO.Pagination; using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Queries.GetAlbumTracksLite; using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; #endregion @@ -14,12 +15,24 @@ public static class GetAlbumTracksLiteRequestMapping /// Converts to . /// /// The request to be converted. + /// The Id of the library the album belongs to, taken from the route. + /// The Id of the artist the album belongs to, taken from the route. + /// The Id of the album whose tracks are retrieved, taken from the route. /// The converted query. - public static GetAlbumTracksLiteQuery ToQuery(this GetAlbumTracksLiteRequest request) + public static GetAlbumTracksLiteQuery ToQuery(this GetAlbumTracksLiteRequest request, string? libraryId, string? artistId, string? albumId) { + PaginationDataDto? paginationData = null; + if (request.CurrentPage is not null || request.PerPage is not null) + paginationData = new PaginationDataDto + { + CurrentPage = request.CurrentPage ?? 1, + PerPage = request.PerPage ?? 200 + }; + return new GetAlbumTracksLiteQuery( - request.AlbumId, - request.CurrentPage, - request.PerPage); + libraryId, + artistId, + albumId, + paginationData); } } diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksRequestMapping.cs deleted file mode 100644 index 0d0ada2e..00000000 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksRequestMapping.cs +++ /dev/null @@ -1,23 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Queries.GetAlbumTracks; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; -#endregion - -namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums; - -/// -/// Extension methods for converting . -/// -public static class GetAlbumTracksRequestMapping -{ - /// - /// Converts to . - /// - /// The request to be converted. - /// The converted query. - public static GetAlbumTracksQuery ToQuery(this GetAlbumTracksRequest request) - { - return new GetAlbumTracksQuery( - request.AlbumId); - } -} diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/AddAlbum/AddAlbumCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/AddAlbum/AddAlbumCommandHandler.cs index ff25b902..ad5ea530 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/AddAlbum/AddAlbumCommandHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/AddAlbum/AddAlbumCommandHandler.cs @@ -81,7 +81,7 @@ public class AddAlbumCommandHandler : ICommandHandler getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, cancellationToken: cancellationToken).ConfigureAwait(false); + Result 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) diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/DeleteAlbum/DeleteAlbumCommand.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/DeleteAlbum/DeleteAlbumCommand.cs index 87f41cd4..f15c5e70 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/DeleteAlbum/DeleteAlbumCommand.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/DeleteAlbum/DeleteAlbumCommand.cs @@ -1,6 +1,5 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.CQRS; -using System; using System.Diagnostics; #endregion @@ -9,8 +8,12 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums. /// /// Command for deleting an album by its Id. /// -/// The unique identifier of the album to delete. +/// The unique identifier of the media library this album belongs to, taken from the route. +/// The unique identifier of the artist the album belongs to, taken from the route. +/// The unique identifier of the album to delete, taken from the route. [DebuggerDisplay("AlbumId: {AlbumId}")] public record DeleteAlbumCommand( - Guid AlbumId + string? LibraryId, + string? ArtistId, + string? AlbumId ) : ICommand; diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/DeleteAlbum/DeleteAlbumCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/DeleteAlbum/DeleteAlbumCommandHandler.cs index c0bb43e5..811e17c5 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/DeleteAlbum/DeleteAlbumCommandHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/DeleteAlbum/DeleteAlbumCommandHandler.cs @@ -1,18 +1,23 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.CQRS; using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management; using Lumina.Application.Common.DataAccess.UoW; using Lumina.Application.Common.Infrastructure.Authentication; using Lumina.Application.Common.Infrastructure.Authorization; using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership; using Lumina.Application.Common.Infrastructure.Validation; -using Lumina.Domain.Common.Errors; +using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists; using Lumina.Domain.Common.Primitives; +using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate; +using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities; using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; using ApplicationErrors = Lumina.Application.Common.Errors.Errors; +using DomainErrors = Lumina.Domain.Common.Errors.Errors; #endregion namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.DeleteAlbum; @@ -60,25 +65,62 @@ public class DeleteAlbumCommandHandler : ICommandHandler getAlbumResult = await _unitOfWork.AlbumRepository.GetByIdAsync(command.AlbumId, cancellationToken: cancellationToken).ConfigureAwait(false); - if (getAlbumResult.IsFailure) - return getAlbumResult.Errors; - if (getAlbumResult.Value is null) - return Errors.Music.AlbumNotFound; + // The validator guarantees that the route identifiers are non-empty Guids before this point. + Guid libraryId = Guid.Parse(command.LibraryId!); + Guid artistId = Guid.Parse(command.ArtistId!); + Guid albumId = Guid.Parse(command.AlbumId!); + + // An album is a child of the artist aggregate, so the whole aggregate is loaded and the album is removed within it. + Result 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) + 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. + 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; // Admins can delete the albums of all libraries; for everyone else, only the albums of the libraries they own. bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync( - userId, new LibraryOwnershipPolicyContext(getAlbumResult.Value.LibraryId), cancellationToken).ConfigureAwait(false); + userId, new LibraryOwnershipPolicyContext(existingArtist.LibraryId), cancellationToken).ConfigureAwait(false); if (!canAccessLibrary) return ApplicationErrors.Authorization.NotAuthorized; - Result deleteAlbumResult = await _unitOfWork.AlbumRepository.DeleteByIdAsync(command.AlbumId, cancellationToken).ConfigureAwait(false); - if (deleteAlbumResult.IsFailure) - return deleteAlbumResult.Errors; + // 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 getLibraryResult = await _unitOfWork.LibraryRepository + .GetByIdAsync(libraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false); + if (getLibraryResult.IsFailure) + return getLibraryResult.Errors; + if (getLibraryResult.Value is null) + return DomainErrors.Library.LibraryNotFound; + + // 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 deleted directly through their own repositories. This difference is intentional. + Result artistResult = existingArtist.ToDomainEntity(); + if (artistResult.IsFailure) + return artistResult.Errors; + Album? domainAlbum = artistResult.Value.Albums.FirstOrDefault(album => album.Id.Value == albumId); + if (domainAlbum is null) + return DomainErrors.Music.AlbumNotFound; + Result removeAlbumResult = artistResult.Value.RemoveAlbum(domainAlbum); + if (removeAlbumResult.IsFailure) + return removeAlbumResult.Errors; + + Result updateResult = await _unitOfWork.ArtistRepository + .UpdateAsync(artistResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false); + if (updateResult.IsFailure) + return updateResult.Errors; Result saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false); if (saveChangesResult.IsFailure) return saveChangesResult.Errors; - return deleteAlbumResult; + return Result.Deleted; } } diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/DeleteAlbum/DeleteAlbumCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/DeleteAlbum/DeleteAlbumCommandValidator.cs index 9004db91..ed1c7c14 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/DeleteAlbum/DeleteAlbumCommandValidator.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/DeleteAlbum/DeleteAlbumCommandValidator.cs @@ -17,10 +17,34 @@ public class DeleteAlbumCommandValidator : AbstractValidator /// public DeleteAlbumCommandValidator() { + // Validates the identifier of the media library that owns the album, taken from the route. + RuleFor(command => command.LibraryId) + .NotEmpty() + .WithError(Errors.Library.LibraryIdCannotBeEmpty); + + RuleFor(command => command.LibraryId) + .Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty) + .When(command => command.LibraryId is not null && command.LibraryId.Length > 0) + .WithError(Errors.Library.LibraryIdCannotBeEmpty); + + // Validates the identifier of the artist the album belongs to, taken from the route. + RuleFor(command => command.ArtistId) + .NotEmpty() + .WithError(Errors.Music.ArtistIdCannotBeEmpty); + + RuleFor(command => command.ArtistId) + .Must(artistId => Guid.TryParse(artistId, out Guid parsedArtistId) && parsedArtistId != Guid.Empty) + .When(command => command.ArtistId is not null && command.ArtistId.Length > 0) + .WithError(Errors.Music.ArtistIdCannotBeEmpty); + + // Validates the identifier of the album to delete, taken from the route. RuleFor(command => command.AlbumId) .NotEmpty() - .WithError(Errors.Music.AlbumIdCannotBeEmpty) - .Must(albumId => albumId != Guid.Empty) + .WithError(Errors.Music.AlbumIdCannotBeEmpty); + + RuleFor(command => command.AlbumId) + .Must(albumId => Guid.TryParse(albumId, out Guid parsedAlbumId) && parsedAlbumId != Guid.Empty) + .When(command => command.AlbumId is not null && command.AlbumId.Length > 0) .WithError(Errors.Music.AlbumIdCannotBeEmpty); } } diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/UpdateAlbum/UpdateAlbumCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/UpdateAlbum/UpdateAlbumCommandHandler.cs index 21df9b32..4a50e01e 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/UpdateAlbum/UpdateAlbumCommandHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Commands/UpdateAlbum/UpdateAlbumCommandHandler.cs @@ -88,7 +88,7 @@ public class UpdateAlbumCommandHandler : ICommandHandler getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, cancellationToken: cancellationToken).ConfigureAwait(false); + Result getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false); if (getArtistResult.IsFailure) return getArtistResult.Errors; diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQuery.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQuery.cs index 4fac5407..ac2975ac 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQuery.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQuery.cs @@ -9,8 +9,12 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums. /// /// Query for getting an album by its Id. /// -/// The unique identifier of the album to get. +/// The unique identifier of the media library the album belongs to, taken from the route. +/// The unique identifier of the artist the album belongs to, taken from the route. +/// The unique identifier of the album to get, taken from the route. [DebuggerDisplay("AlbumId: {AlbumId}")] public record GetAlbumQuery( - Guid AlbumId + string? LibraryId, + string? ArtistId, + string? AlbumId ) : IQuery; diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryHandler.cs index 6f7fdf8a..e0d81c41 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryHandler.cs @@ -65,18 +65,29 @@ public class GetAlbumQueryHandler : IQueryHandler getAlbumResult = await _unitOfWork.AlbumRepository.GetByIdAsync(query.AlbumId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false); + // The validator guarantees that the route identifiers are non-empty Guids before this point. + Guid libraryId = Guid.Parse(query.LibraryId!); + Guid artistId = Guid.Parse(query.ArtistId!); + Guid albumId = Guid.Parse(query.AlbumId!); + + Result getAlbumResult = await _unitOfWork.AlbumRepository.GetByIdAsync(albumId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false); if (getAlbumResult.IsFailure) return getAlbumResult.Errors; if (getAlbumResult.Value is null) return Errors.Music.AlbumNotFound; + AlbumEntity existingAlbum = getAlbumResult.Value; + + // Resource scoping: the album must belong to the library and the artist named by the route, so that an album can never be read through + // another library's or artist's route; the mismatch is reported as not found, without disclosing that the album exists elsewhere. + if (existingAlbum.LibraryId != libraryId || existingAlbum.ArtistId != artistId) + return Errors.Music.AlbumNotFound; // Admins can see the albums of all libraries; for everyone else, only the albums of the libraries they own. bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync( - userId, new LibraryOwnershipPolicyContext(getAlbumResult.Value.LibraryId), cancellationToken).ConfigureAwait(false); + userId, new LibraryOwnershipPolicyContext(existingAlbum.LibraryId), cancellationToken).ConfigureAwait(false); if (!canAccessLibrary) return ApplicationErrors.Authorization.NotAuthorized; - return getAlbumResult.Value.ToResponse(); + return existingAlbum.ToResponse(); } } diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryValidator.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryValidator.cs index 5aa7d43c..c8b19b36 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryValidator.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryValidator.cs @@ -17,10 +17,34 @@ public class GetAlbumQueryValidator : AbstractValidator /// public GetAlbumQueryValidator() { + // Validates the identifier of the media library the album belongs to, taken from the route. + RuleFor(query => query.LibraryId) + .NotEmpty() + .WithError(Errors.Library.LibraryIdCannotBeEmpty); + + RuleFor(query => query.LibraryId) + .Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty) + .When(query => query.LibraryId is not null && query.LibraryId.Length > 0) + .WithError(Errors.Library.LibraryIdCannotBeEmpty); + + // Validates the identifier of the artist the album belongs to, taken from the route. + RuleFor(query => query.ArtistId) + .NotEmpty() + .WithError(Errors.Music.ArtistIdCannotBeEmpty); + + RuleFor(query => query.ArtistId) + .Must(artistId => Guid.TryParse(artistId, out Guid parsedArtistId) && parsedArtistId != Guid.Empty) + .When(query => query.ArtistId is not null && query.ArtistId.Length > 0) + .WithError(Errors.Music.ArtistIdCannotBeEmpty); + + // Validates the identifier of the album to get, taken from the route. RuleFor(query => query.AlbumId) .NotEmpty() - .WithError(Errors.Music.AlbumIdCannotBeEmpty) - .Must(albumId => albumId != Guid.Empty) + .WithError(Errors.Music.AlbumIdCannotBeEmpty); + + RuleFor(query => query.AlbumId) + .Must(albumId => Guid.TryParse(albumId, out Guid parsedAlbumId) && parsedAlbumId != Guid.Empty) + .When(query => query.AlbumId is not null && query.AlbumId.Length > 0) .WithError(Errors.Music.AlbumIdCannotBeEmpty); } } diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracks/GetAlbumTracksQuery.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracks/GetAlbumTracksQuery.cs index 2462c6f5..8003a14b 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracks/GetAlbumTracksQuery.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracks/GetAlbumTracksQuery.cs @@ -9,8 +9,12 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums. /// /// Query for getting all the tracks of an album. /// -/// The unique identifier of the album whose tracks are retrieved. +/// The unique identifier of the media library the album belongs to, taken from the route. +/// The unique identifier of the artist the album belongs to, taken from the route. +/// The unique identifier of the album whose tracks are retrieved, taken from the route. [DebuggerDisplay("AlbumId: {AlbumId}")] public record GetAlbumTracksQuery( - Guid AlbumId + string? LibraryId, + string? ArtistId, + string? AlbumId ) : IQuery; diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracks/GetAlbumTracksQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracks/GetAlbumTracksQueryHandler.cs index 2f238094..a1da9d43 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracks/GetAlbumTracksQueryHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracks/GetAlbumTracksQueryHandler.cs @@ -65,19 +65,30 @@ public class GetAlbumTracksQueryHandler : IQueryHandler getAlbumResult = await _unitOfWork.AlbumRepository.GetByIdAsync(query.AlbumId, cancellationToken: cancellationToken).ConfigureAwait(false); + // The validator guarantees that the route identifiers are non-empty Guids before this point. + Guid libraryId = Guid.Parse(query.LibraryId!); + Guid artistId = Guid.Parse(query.ArtistId!); + Guid albumId = Guid.Parse(query.AlbumId!); + + Result getAlbumResult = await _unitOfWork.AlbumRepository.GetByIdAsync(albumId, shouldIncludeNavigationProperties: false, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false); if (getAlbumResult.IsFailure) return getAlbumResult.Errors; if (getAlbumResult.Value is null) return Errors.Music.AlbumNotFound; + AlbumEntity existingAlbum = getAlbumResult.Value; + + // Resource scoping: the album must belong to the library and the artist named by the route, so that the tracks of an album can never be read + // through another library's or artist's route; the mismatch is reported as not found, without disclosing that the album exists elsewhere. + if (existingAlbum.LibraryId != libraryId || existingAlbum.ArtistId != artistId) + return Errors.Music.AlbumNotFound; // Admins can see the tracks of the albums of all libraries; for everyone else, only of the libraries they own. bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync( - userId, new LibraryOwnershipPolicyContext(getAlbumResult.Value.LibraryId), cancellationToken).ConfigureAwait(false); + userId, new LibraryOwnershipPolicyContext(existingAlbum.LibraryId), cancellationToken).ConfigureAwait(false); if (!canAccessLibrary) return ApplicationErrors.Authorization.NotAuthorized; - Result> getTracksResult = await _unitOfWork.TrackRepository.GetByAlbumIdAsync(query.AlbumId, cancellationToken).ConfigureAwait(false); + Result> getTracksResult = await _unitOfWork.TrackRepository.GetByAlbumIdAsync(albumId, cancellationToken).ConfigureAwait(false); return getTracksResult.Match(value => Result.From(value.ToResponses()), errors => errors); } } diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracks/GetAlbumTracksQueryValidator.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracks/GetAlbumTracksQueryValidator.cs index b826b648..014c8c30 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracks/GetAlbumTracksQueryValidator.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracks/GetAlbumTracksQueryValidator.cs @@ -17,10 +17,34 @@ public class GetAlbumTracksQueryValidator : AbstractValidator public GetAlbumTracksQueryValidator() { + // Validates the identifier of the media library the album belongs to, taken from the route. + RuleFor(query => query.LibraryId) + .NotEmpty() + .WithError(Errors.Library.LibraryIdCannotBeEmpty); + + RuleFor(query => query.LibraryId) + .Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty) + .When(query => query.LibraryId is not null && query.LibraryId.Length > 0) + .WithError(Errors.Library.LibraryIdCannotBeEmpty); + + // Validates the identifier of the artist the album belongs to, taken from the route. + RuleFor(query => query.ArtistId) + .NotEmpty() + .WithError(Errors.Music.ArtistIdCannotBeEmpty); + + RuleFor(query => query.ArtistId) + .Must(artistId => Guid.TryParse(artistId, out Guid parsedArtistId) && parsedArtistId != Guid.Empty) + .When(query => query.ArtistId is not null && query.ArtistId.Length > 0) + .WithError(Errors.Music.ArtistIdCannotBeEmpty); + + // Validates the identifier of the album whose tracks are retrieved, taken from the route. RuleFor(query => query.AlbumId) .NotEmpty() - .WithError(Errors.Music.AlbumIdCannotBeEmpty) - .Must(albumId => albumId != Guid.Empty) + .WithError(Errors.Music.AlbumIdCannotBeEmpty); + + RuleFor(query => query.AlbumId) + .Must(albumId => Guid.TryParse(albumId, out Guid parsedAlbumId) && parsedAlbumId != Guid.Empty) + .When(query => query.AlbumId is not null && query.AlbumId.Length > 0) .WithError(Errors.Music.AlbumIdCannotBeEmpty); } } diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracksLite/GetAlbumTracksLiteQuery.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracksLite/GetAlbumTracksLiteQuery.cs index 58d4dbc9..aba57b5a 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracksLite/GetAlbumTracksLiteQuery.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracksLite/GetAlbumTracksLiteQuery.cs @@ -1,6 +1,6 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.CQRS; -using System; +using Lumina.Application.Common.DTO.Pagination; using System.Diagnostics; #endregion @@ -9,12 +9,14 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums. /// /// Query for getting the lightweight read models of all the tracks of an album. /// -/// The unique identifier of the album whose tracks are retrieved. -/// The page of results to retrieve. -/// The maximum number of tracks to retrieve per page. +/// The unique identifier of the media library the album belongs to, taken from the route. +/// The unique identifier of the artist the album belongs to, taken from the route. +/// The unique identifier of the album whose tracks are retrieved, taken from the route. +/// The object containing the requested pagination data. [DebuggerDisplay("AlbumId: {AlbumId}")] public record GetAlbumTracksLiteQuery( - Guid AlbumId, - int? CurrentPage, - int? PerPage + string? LibraryId, + string? ArtistId, + string? AlbumId, + PaginationDataDto? PaginationData ) : IQuery; diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracksLite/GetAlbumTracksLiteQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracksLite/GetAlbumTracksLiteQueryHandler.cs index 25692a17..bc424d69 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracksLite/GetAlbumTracksLiteQueryHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracksLite/GetAlbumTracksLiteQueryHandler.cs @@ -67,25 +67,30 @@ public class GetAlbumTracksLiteQueryHandler : IQueryHandler getAlbumResult = await _unitOfWork.AlbumRepository.GetByIdAsync(query.AlbumId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false); + // The validator guarantees that the route identifiers are non-empty Guids before this point. + Guid libraryId = Guid.Parse(query.LibraryId!); + Guid artistId = Guid.Parse(query.ArtistId!); + Guid albumId = Guid.Parse(query.AlbumId!); + + Result getAlbumResult = await _unitOfWork.AlbumRepository.GetByIdAsync(albumId, shouldIncludeNavigationProperties: false, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false); if (getAlbumResult.IsFailure) return getAlbumResult.Errors; if (getAlbumResult.Value is null) return Errors.Music.AlbumNotFound; + AlbumEntity existingAlbum = getAlbumResult.Value; + + // Resource scoping: the album must belong to the library and the artist named by the route, so that the tracks of an album can never be read + // through another library's or artist's route; the mismatch is reported as not found, without disclosing that the album exists elsewhere. + if (existingAlbum.LibraryId != libraryId || existingAlbum.ArtistId != artistId) + return Errors.Music.AlbumNotFound; // Admins can see the tracks of the albums of all libraries; for everyone else, only of the libraries they own. bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync( - userId, new LibraryOwnershipPolicyContext(getAlbumResult.Value.LibraryId), cancellationToken).ConfigureAwait(false); + userId, new LibraryOwnershipPolicyContext(existingAlbum.LibraryId), cancellationToken).ConfigureAwait(false); if (!canAccessLibrary) return ApplicationErrors.Authorization.NotAuthorized; - PaginationDataDto paginationData = new() - { - CurrentPage = query.CurrentPage ?? 1, - PerPage = query.PerPage ?? 200 - }; - - Result> getTracksResult = await _unitOfWork.TrackRepository.GetTracksLiteByAlbumIdAsync(query.AlbumId, paginationData, cancellationToken).ConfigureAwait(false); + Result> getTracksResult = await _unitOfWork.TrackRepository.GetTracksLiteByAlbumIdAsync(albumId, query.PaginationData, cancellationToken).ConfigureAwait(false); return getTracksResult.Match(value => Result.From(value.ToResponses()), errors => errors); } } diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracksLite/GetAlbumTracksLiteQueryValidator.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracksLite/GetAlbumTracksLiteQueryValidator.cs index 3a241a57..6d1e263b 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracksLite/GetAlbumTracksLiteQueryValidator.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbumTracksLite/GetAlbumTracksLiteQueryValidator.cs @@ -17,10 +17,34 @@ public class GetAlbumTracksLiteQueryValidator : AbstractValidator public GetAlbumTracksLiteQueryValidator() { + // Validates the identifier of the media library the album belongs to, taken from the route. + RuleFor(query => query.LibraryId) + .NotEmpty() + .WithError(Errors.Library.LibraryIdCannotBeEmpty); + + RuleFor(query => query.LibraryId) + .Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty) + .When(query => query.LibraryId is not null && query.LibraryId.Length > 0) + .WithError(Errors.Library.LibraryIdCannotBeEmpty); + + // Validates the identifier of the artist the album belongs to, taken from the route. + RuleFor(query => query.ArtistId) + .NotEmpty() + .WithError(Errors.Music.ArtistIdCannotBeEmpty); + + RuleFor(query => query.ArtistId) + .Must(artistId => Guid.TryParse(artistId, out Guid parsedArtistId) && parsedArtistId != Guid.Empty) + .When(query => query.ArtistId is not null && query.ArtistId.Length > 0) + .WithError(Errors.Music.ArtistIdCannotBeEmpty); + + // Validates the identifier of the album whose tracks are retrieved, taken from the route. RuleFor(query => query.AlbumId) .NotEmpty() - .WithError(Errors.Music.AlbumIdCannotBeEmpty) - .Must(albumId => albumId != Guid.Empty) + .WithError(Errors.Music.AlbumIdCannotBeEmpty); + + RuleFor(query => query.AlbumId) + .Must(albumId => Guid.TryParse(albumId, out Guid parsedAlbumId) && parsedAlbumId != Guid.Empty) + .When(query => query.AlbumId is not null && query.AlbumId.Length > 0) .WithError(Errors.Music.AlbumIdCannotBeEmpty); } } diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/DeleteAlbumRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/DeleteAlbumRequest.cs deleted file mode 100644 index 2e9828a5..00000000 --- a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/DeleteAlbumRequest.cs +++ /dev/null @@ -1,17 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using System; -using System.Diagnostics; -#endregion - -namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; - -/// -/// Represents a request to delete an album by the specified Id. -/// -/// The unique identifier of the artist the album belongs to, taken from the route. -/// The unique identifier of the album to delete. -[DebuggerDisplay("AlbumId: {AlbumId}")] -public record DeleteAlbumRequest( - Guid ArtistId, - Guid AlbumId -); diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumRequest.cs deleted file mode 100644 index b834f728..00000000 --- a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumRequest.cs +++ /dev/null @@ -1,17 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using System; -using System.Diagnostics; -#endregion - -namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; - -/// -/// Represents a request to get an album by the specified Id. -/// -/// The unique identifier of the artist the album belongs to, taken from the route. -/// The unique identifier of the album to retrieve. -[DebuggerDisplay("AlbumId: {AlbumId}")] -public record GetAlbumRequest( - Guid ArtistId, - Guid AlbumId -); diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLiteRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLiteRequest.cs index e6560abd..0f97b4ad 100644 --- a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLiteRequest.cs +++ b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLiteRequest.cs @@ -1,5 +1,4 @@ #region ========================================================================= USING ===================================================================================== -using System; using System.Diagnostics; #endregion @@ -8,14 +7,10 @@ namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Album /// /// Represents a request to get the lightweight read models of the tracks of an album. /// -/// The unique identifier of the artist the album belongs to, taken from the route. -/// The unique identifier of the album whose tracks are retrieved. /// The page of results to retrieve. Optional. /// The maximum number of tracks to retrieve per page. Optional. -[DebuggerDisplay("AlbumId: {AlbumId}")] +[DebuggerDisplay("CurrentPage: {CurrentPage}, PerPage: {PerPage}")] public record GetAlbumTracksLiteRequest( - Guid ArtistId, - Guid AlbumId, int? CurrentPage, int? PerPage ); diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksRequest.cs deleted file mode 100644 index aa1bdaa3..00000000 --- a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksRequest.cs +++ /dev/null @@ -1,17 +0,0 @@ -#region ========================================================================= USING ===================================================================================== -using System; -using System.Diagnostics; -#endregion - -namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; - -/// -/// Represents a request to get the tracks of an album. -/// -/// The unique identifier of the artist the album belongs to, taken from the route. -/// The unique identifier of the album whose tracks are retrieved. -[DebuggerDisplay("AlbumId: {AlbumId}")] -public record GetAlbumTracksRequest( - Guid ArtistId, - Guid AlbumId -); diff --git a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/AlbumRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/AlbumRepository.cs index ef6ee056..9ebe9d8a 100644 --- a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/AlbumRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/AlbumRepository.cs @@ -197,23 +197,6 @@ internal sealed class AlbumRepository : IAlbumRepository return await query.FirstOrDefaultAsync(album => album.Id == id, cancellationToken).ConfigureAwait(false); } - /// - /// Deletes the album identified by . - /// - /// The Id of the album to delete. - /// Cancellation token that can be used to stop the execution. - /// An representing either a successful operation, or an error. - public async Task> DeleteByIdAsync(Guid id, CancellationToken cancellationToken) - { - AlbumEntity? album = await _luminaDbContext.Albums - .FirstOrDefaultAsync(repositoryAlbum => repositoryAlbum.Id == id, cancellationToken).ConfigureAwait(false); - if (album is null) - return Errors.Music.AlbumNotFound; - - _luminaDbContext.Albums.Remove(album); - return Result.Deleted; - } - /// /// Gets all the albums of the artist identified by . /// diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/DeleteAlbum/DeleteAlbumEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/DeleteAlbum/DeleteAlbumEndpoint.cs index 7dbd7949..6f5078bb 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/DeleteAlbum/DeleteAlbumEndpoint.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/DeleteAlbum/DeleteAlbumEndpoint.cs @@ -1,8 +1,6 @@ #region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.CQRS; -using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums; using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.DeleteAlbum; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; using Lumina.Domain.Common.Primitives; using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; using Lumina.Presentation.Api.Core.Endpoints.Common; @@ -14,9 +12,9 @@ using System.Threading.Tasks; namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.DeleteAlbum; /// -/// API endpoint for the /artists/{artistId}/albums/{albumId} route. +/// API endpoint for the /libraries/{libraryId}/artists/{artistId}/albums/{albumId} route. /// -public class DeleteAlbumEndpoint : BaseEndpoint +public class DeleteAlbumEndpoint : BaseEndpoint { private readonly ICommandHandler> _deleteAlbumCommandHandler; @@ -43,11 +41,16 @@ public class DeleteAlbumEndpoint : BaseEndpoint /// /// Deletes an album by Id. /// - /// The request containing the id of the album to be deleted. + /// The request object. /// Cancellation token that can be used to stop the execution. - public override async Task ExecuteAsync(DeleteAlbumRequest request, CancellationToken cancellationToken) + public override async Task ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken) { - Result result = await _deleteAlbumCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false); + // Take unique identifiers from the route. + string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString(); + string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString(); + string? albumId = HttpContext.Request.RouteValues["albumId"]?.ToString(); + Result result = await _deleteAlbumCommandHandler + .HandleAsync(new DeleteAlbumCommand(libraryId, artistId, albumId), cancellationToken).ConfigureAwait(false); return result.Match(success => TypedResults.Ok(success), Problem); } } diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/DeleteAlbum/DeleteAlbumEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/DeleteAlbum/DeleteAlbumEndpointSummary.cs index 40645ebe..86cae407 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/DeleteAlbum/DeleteAlbumEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/DeleteAlbum/DeleteAlbumEndpointSummary.cs @@ -1,6 +1,5 @@ #region ========================================================================= USING ===================================================================================== using FastEndpoints; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -12,7 +11,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibra /// Class used for providing a textual description for the API endpoint, for OpenAPI. /// [ExcludeFromCodeCoverage] -public class DeleteAlbumEndpointSummary : Summary +public class DeleteAlbumEndpointSummary : Summary { /// /// Initializes a new instance of the class. @@ -20,15 +19,7 @@ public class DeleteAlbumEndpointSummary : Summary r.ArtistId, "The unique identifier of the artist the album belongs to, taken from the route."); - RequestParam(r => r.AlbumId, "The Id of the album to delete, taken from the route. Required."); + 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."; Response(200, "The album was successfully deleted."); @@ -40,16 +31,16 @@ public class DeleteAlbumEndpointSummary : Summary { { "General.Validation", new[] { + "LibraryIdCannotBeEmpty", + "ArtistIdCannotBeEmpty", "AlbumIdCannotBeEmpty" } } diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbum/GetAlbumEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbum/GetAlbumEndpoint.cs index 83d30a44..0a0934b6 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbum/GetAlbumEndpoint.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbum/GetAlbumEndpoint.cs @@ -1,9 +1,7 @@ #region ========================================================================= USING ===================================================================================== using FastEndpoints; using Lumina.Application.Common.CQRS; -using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums; using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Queries.GetAlbum; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums; using Lumina.Domain.Common.Primitives; using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; @@ -18,7 +16,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibra /// /// API endpoint for the /artists/{artistId}/albums/{albumId} route. /// -public class GetAlbumEndpoint : BaseEndpoint +public class GetAlbumEndpoint : BaseEndpoint { private readonly IQueryHandler> _getAlbumQueryHandler; @@ -45,11 +43,16 @@ public class GetAlbumEndpoint : BaseEndpoint /// /// Gets an album by Id. /// - /// The request containing the id of the album to be retrieved. + /// The request object. /// Cancellation token that can be used to stop the execution. - public override async Task ExecuteAsync(GetAlbumRequest request, CancellationToken cancellationToken) + public override async Task ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken) { - Result result = await _getAlbumQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false); + // Take unique identifiers from the route. + string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString(); + string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString(); + string? albumId = HttpContext.Request.RouteValues["albumId"]?.ToString(); + GetAlbumQuery query = new(libraryId, artistId, albumId); + Result result = await _getAlbumQueryHandler.HandleAsync(query, cancellationToken).ConfigureAwait(false); return result.Match(success => TypedResults.Ok(success), Problem); } } diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbum/GetAlbumEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbum/GetAlbumEndpointSummary.cs index 3ff3cd62..876fa112 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbum/GetAlbumEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbum/GetAlbumEndpointSummary.cs @@ -4,7 +4,6 @@ using Lumina.Contracts.DTO.Common; using Lumina.Contracts.DTO.MediaContributors; using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary; using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums; using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using Lumina.Domain.SharedKernel.Common.Enums.Common; @@ -20,7 +19,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibra /// Class used for providing a textual description for the API endpoint, for OpenAPI. /// [ExcludeFromCodeCoverage] -public class GetAlbumEndpointSummary : Summary +public class GetAlbumEndpointSummary : Summary { /// /// Initializes a new instance of the class. @@ -28,15 +27,7 @@ public class GetAlbumEndpointSummary : Summary r.ArtistId, "The unique identifier of the artist the album belongs to, taken from the route."); - RequestParam(r => r.AlbumId, "The Id of the album to get. Required."); + Description = "Returns the full details of the album identified by the route. The album is returned to an Admin, who can see the albums of all libraries, or to the owner of the library of the album."; ResponseParam(r => r.Id, "The Id of the album."); ResponseParam(r => r.ArtistId, "The Id of the artist the album belongs to."); @@ -159,7 +150,7 @@ public class GetAlbumEndpointSummary : Summary { { diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracks/GetAlbumTracksEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracks/GetAlbumTracksEndpoint.cs index 96b95d67..283af3f9 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracks/GetAlbumTracksEndpoint.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracks/GetAlbumTracksEndpoint.cs @@ -1,9 +1,7 @@ #region ========================================================================= USING ===================================================================================== using FastEndpoints; using Lumina.Application.Common.CQRS; -using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums; using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Queries.GetAlbumTracks; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks; using Lumina.Domain.Common.Primitives; using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary; @@ -19,7 +17,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibra /// /// API endpoint for the /artists/{artistId}/albums/{albumId}/tracks route. /// -public class GetAlbumTracksEndpoint : BaseEndpoint +public class GetAlbumTracksEndpoint : BaseEndpoint { private readonly IQueryHandler>> _getAlbumTracksQueryHandler; @@ -44,13 +42,18 @@ public class GetAlbumTracksEndpoint : BaseEndpoint - /// Gets the list of all the tracks of the album identified by . + /// Gets the list of all the tracks of the album identified by the route. /// - /// The request containing the id of the album whose tracks are retrieved. + /// The request object. /// Cancellation token that can be used to stop the execution. - public override async Task ExecuteAsync(GetAlbumTracksRequest request, CancellationToken cancellationToken) + public override async Task ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken) { - Result> result = await _getAlbumTracksQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false); + // Take unique identifiers from the route. + string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString(); + string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString(); + string? albumId = HttpContext.Request.RouteValues["albumId"]?.ToString(); + GetAlbumTracksQuery query = new(libraryId, artistId, albumId); + Result> result = await _getAlbumTracksQueryHandler.HandleAsync(query, cancellationToken).ConfigureAwait(false); return result.Match(success => TypedResults.Ok(success), Problem); } } diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracks/GetAlbumTracksEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracks/GetAlbumTracksEndpointSummary.cs index 515a12f0..edbdbda5 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracks/GetAlbumTracksEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracks/GetAlbumTracksEndpointSummary.cs @@ -4,7 +4,6 @@ using Lumina.Contracts.DTO.Common; using Lumina.Contracts.DTO.MediaContributors; using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary; using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary; -using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums; using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks; using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using Lumina.Domain.SharedKernel.Common.Enums.Common; @@ -20,7 +19,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibra /// Class used for providing a textual description for the API endpoint, for OpenAPI. /// [ExcludeFromCodeCoverage] -public class GetAlbumTracksEndpointSummary : Summary +public class GetAlbumTracksEndpointSummary : Summary { /// /// Initializes a new instance of the class. @@ -28,15 +27,7 @@ public class GetAlbumTracksEndpointSummary : Summary r.ArtistId, "The unique identifier of the artist the album belongs to, taken from the route."); - RequestParam(r => r.AlbumId, "The Id of the album whose tracks are retrieved, taken from the route. Required."); + Description = "Returns the full details of the tracks of the album identified by the route. The list is returned to an Admin, who can see the tracks of the albums of all libraries, or to the owner of the library of the album."; ResponseParam(r => r.Id, "The Id of the track."); ResponseParam(r => r.AlbumId, "The Id of the album the track belongs to."); @@ -266,7 +257,7 @@ public class GetAlbumTracksEndpointSummary : Summary { { diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLite/GetAlbumTracksLiteEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLite/GetAlbumTracksLiteEndpoint.cs index 6e9536dc..bcf82b57 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLite/GetAlbumTracksLiteEndpoint.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLite/GetAlbumTracksLiteEndpoint.cs @@ -44,13 +44,17 @@ public class GetAlbumTracksLiteEndpoint : BaseEndpoint - /// Gets the lightweight read models of all the tracks of the album identified by . + /// Gets the lightweight read models of all the tracks of the album identified by the route. /// - /// The request containing the id of the album whose tracks are retrieved. + /// The request containing the pagination options of the tracks to be retrieved. /// Cancellation token that can be used to stop the execution. public override async Task ExecuteAsync(GetAlbumTracksLiteRequest request, CancellationToken cancellationToken) { - Result> result = await _getAlbumTracksLiteQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false); + // Take unique identifiers from the route. + string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString(); + string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString(); + string? albumId = HttpContext.Request.RouteValues["albumId"]?.ToString(); + Result> result = await _getAlbumTracksLiteQueryHandler.HandleAsync(request.ToQuery(libraryId, artistId, albumId), cancellationToken).ConfigureAwait(false); return result.Match(success => TypedResults.Ok(success), Problem); } } diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLite/GetAlbumTracksLiteEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLite/GetAlbumTracksLiteEndpointSummary.cs index b3c5ede8..a87aa8f9 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLite/GetAlbumTracksLiteEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLite/GetAlbumTracksLiteEndpointSummary.cs @@ -25,14 +25,10 @@ public class GetAlbumTracksLiteEndpointSummary : Summary r.ArtistId, "The unique identifier of the artist the album belongs to, taken from the route."); - RequestParam(r => r.AlbumId, "The Id of the album whose tracks are retrieved. Required."); RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional."); RequestParam(r => r.PerPage, "The maximum number of tracks to retrieve per page. Optional."); @@ -75,7 +71,7 @@ public class GetAlbumTracksLiteEndpointSummary : Summary { {