Refactors the album slice across the stack

This commit is contained in:
BinaryAlley committed 2026-09-19 12:57:39 -07:00
1 parent aa097ecc98
commit d4cc3c1f8d
37 files changed
+600 -305

No files matched your search

@@ -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).
@@ -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}}
@@ -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}}
@@ -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}}
@@ -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}}
@@ -19,8 +19,7 @@ namespace Lumina.Application.Common.DataAccess.Repositories.MusicLibrary;
public interface IAlbumRepository : IRepository<AlbumEntity>,
IInsertRepositoryAction<AlbumEntity>,
IUpdateRepositoryAction<AlbumEntity>,
IGetByIdRepositoryAction<AlbumEntity, Guid>,
IDeleteByIdRepositoryAction<Guid>
IGetByIdRepositoryAction<AlbumEntity, Guid>
{
/// <summary>
/// Gets all the albums of the artist identified by <paramref name="artistId"/>.
@@ -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;
/// <summary>
/// Extension methods for converting <see cref="DeleteAlbumRequest"/>.
/// </summary>
public static class DeleteAlbumRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="DeleteAlbumCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted command.</returns>
public static DeleteAlbumCommand ToCommand(this DeleteAlbumRequest request)
{
return new DeleteAlbumCommand(
request.AlbumId);
}
}
@@ -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;
/// <summary>
/// Extension methods for converting <see cref="GetAlbumRequest"/>.
/// </summary>
public static class GetAlbumRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetAlbumQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetAlbumQuery ToQuery(this GetAlbumRequest request)
{
return new GetAlbumQuery(
request.AlbumId);
}
}
@@ -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 <paramref name="request"/> to <see cref="GetAlbumTracksLiteQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <param name="libraryId">The Id of the library the album belongs to, taken from the route.</param>
/// <param name="artistId">The Id of the artist the album belongs to, taken from the route.</param>
/// <param name="albumId">The Id of the album whose tracks are retrieved, taken from the route.</param>
/// <returns>The converted query.</returns>
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);
}
}
@@ -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;
/// <summary>
/// Extension methods for converting <see cref="GetAlbumTracksRequest"/>.
/// </summary>
public static class GetAlbumTracksRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="GetAlbumTracksQuery"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <returns>The converted query.</returns>
public static GetAlbumTracksQuery ToQuery(this GetAlbumTracksRequest request)
{
return new GetAlbumTracksQuery(
request.AlbumId);
}
}
@@ -81,7 +81,7 @@ public class AddAlbumCommandHandler : ICommandHandler<AddAlbumCommand, Result<Al
Guid artistId = Guid.Parse(command.ArtistId!);
// An album is a child of the artist aggregate, so the whole aggregate is loaded and the album is added within it.
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, cancellationToken: cancellationToken).ConfigureAwait(false);
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
if (getArtistResult.IsFailure)
return getArtistResult.Errors;
if (getArtistResult.Value is null)
@@ -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.
/// <summary>
/// Command for deleting an album by its Id.
/// </summary>
/// <param name="AlbumId">The unique identifier of the album to delete.</param>
/// <param name="LibraryId">The unique identifier of the media library this album belongs to, taken from the route.</param>
/// <param name="ArtistId">The unique identifier of the artist the album belongs to, taken from the route.</param>
/// <param name="AlbumId">The unique identifier of the album to delete, taken from the route.</param>
[DebuggerDisplay("AlbumId: {AlbumId}")]
public record DeleteAlbumCommand(
Guid AlbumId
string? LibraryId,
string? ArtistId,
string? AlbumId
) : ICommand;
@@ -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<DeleteAlbumCommand, Res
return ApplicationErrors.Authorization.NotAuthorized;
Guid userId = currentUserId.Value;
Result<AlbumEntity?> 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<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository
.GetByIdAsync(artistId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
if (getArtistResult.IsFailure)
return getArtistResult.Errors;
if (getArtistResult.Value is null)
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<ILibraryOwnershipPolicy>(
userId, new LibraryOwnershipPolicyContext(getAlbumResult.Value.LibraryId), cancellationToken).ConfigureAwait(false);
userId, new LibraryOwnershipPolicyContext(existingArtist.LibraryId), cancellationToken).ConfigureAwait(false);
if (!canAccessLibrary)
return ApplicationErrors.Authorization.NotAuthorized;
Result<Deleted> 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<LibraryEntity?> 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<Artist> 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<Deleted> removeAlbumResult = artistResult.Value.RemoveAlbum(domainAlbum);
if (removeAlbumResult.IsFailure)
return removeAlbumResult.Errors;
Result<Updated> updateResult = await _unitOfWork.ArtistRepository
.UpdateAsync(artistResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateResult.IsFailure)
return updateResult.Errors;
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
if (saveChangesResult.IsFailure)
return saveChangesResult.Errors;
return deleteAlbumResult;
return Result.Deleted;
}
}
@@ -17,10 +17,34 @@ public class DeleteAlbumCommandValidator : AbstractValidator<DeleteAlbumCommand>
/// </summary>
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);
}
}
@@ -88,7 +88,7 @@ public class UpdateAlbumCommandHandler : ICommandHandler<UpdateAlbumCommand, Res
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 edited within it.
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, cancellationToken: cancellationToken).ConfigureAwait(false);
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
if (getArtistResult.IsFailure)
return getArtistResult.Errors;
@@ -9,8 +9,12 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.
/// <summary>
/// Query for getting an album by its Id.
/// </summary>
/// <param name="AlbumId">The unique identifier of the album to get.</param>
/// <param name="LibraryId">The unique identifier of the media library the album belongs to, taken from the route.</param>
/// <param name="ArtistId">The unique identifier of the artist the album belongs to, taken from the route.</param>
/// <param name="AlbumId">The unique identifier of the album to get, taken from the route.</param>
[DebuggerDisplay("AlbumId: {AlbumId}")]
public record GetAlbumQuery(
Guid AlbumId
string? LibraryId,
string? ArtistId,
string? AlbumId
) : IQuery;
@@ -65,18 +65,29 @@ public class GetAlbumQueryHandler : IQueryHandler<GetAlbumQuery, Result<AlbumRes
return ApplicationErrors.Authorization.NotAuthorized;
Guid userId = currentUserId.Value;
Result<AlbumEntity?> 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<AlbumEntity?> 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<ILibraryOwnershipPolicy>(
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();
}
}
@@ -17,10 +17,34 @@ public class GetAlbumQueryValidator : AbstractValidator<GetAlbumQuery>
/// </summary>
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);
}
}
@@ -9,8 +9,12 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.
/// <summary>
/// Query for getting all the tracks of an album.
/// </summary>
/// <param name="AlbumId">The unique identifier of the album whose tracks are retrieved.</param>
/// <param name="LibraryId">The unique identifier of the media library the album belongs to, taken from the route.</param>
/// <param name="ArtistId">The unique identifier of the artist the album belongs to, taken from the route.</param>
/// <param name="AlbumId">The unique identifier of the album whose tracks are retrieved, taken from the route.</param>
[DebuggerDisplay("AlbumId: {AlbumId}")]
public record GetAlbumTracksQuery(
Guid AlbumId
string? LibraryId,
string? ArtistId,
string? AlbumId
) : IQuery;
@@ -65,19 +65,30 @@ public class GetAlbumTracksQueryHandler : IQueryHandler<GetAlbumTracksQuery, Res
return ApplicationErrors.Authorization.NotAuthorized;
Guid userId = currentUserId.Value;
Result<AlbumEntity?> 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<AlbumEntity?> 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<ILibraryOwnershipPolicy>(
userId, new LibraryOwnershipPolicyContext(getAlbumResult.Value.LibraryId), cancellationToken).ConfigureAwait(false);
userId, new LibraryOwnershipPolicyContext(existingAlbum.LibraryId), cancellationToken).ConfigureAwait(false);
if (!canAccessLibrary)
return ApplicationErrors.Authorization.NotAuthorized;
Result<IReadOnlyList<TrackEntity>> getTracksResult = await _unitOfWork.TrackRepository.GetByAlbumIdAsync(query.AlbumId, cancellationToken).ConfigureAwait(false);
Result<IReadOnlyList<TrackEntity>> getTracksResult = await _unitOfWork.TrackRepository.GetByAlbumIdAsync(albumId, cancellationToken).ConfigureAwait(false);
return getTracksResult.Match(value => Result.From(value.ToResponses()), errors => errors);
}
}
@@ -17,10 +17,34 @@ public class GetAlbumTracksQueryValidator : AbstractValidator<GetAlbumTracksQuer
/// </summary>
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);
}
}
@@ -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.
/// <summary>
/// Query for getting the lightweight read models of all the tracks of an album.
/// </summary>
/// <param name="AlbumId">The unique identifier of the album whose tracks are retrieved.</param>
/// <param name="CurrentPage">The page of results to retrieve.</param>
/// <param name="PerPage">The maximum number of tracks to retrieve per page.</param>
/// <param name="LibraryId">The unique identifier of the media library the album belongs to, taken from the route.</param>
/// <param name="ArtistId">The unique identifier of the artist the album belongs to, taken from the route.</param>
/// <param name="AlbumId">The unique identifier of the album whose tracks are retrieved, taken from the route.</param>
/// <param name="PaginationData">The object containing the requested pagination data.</param>
[DebuggerDisplay("AlbumId: {AlbumId}")]
public record GetAlbumTracksLiteQuery(
Guid AlbumId,
int? CurrentPage,
int? PerPage
string? LibraryId,
string? ArtistId,
string? AlbumId,
PaginationDataDto? PaginationData
) : IQuery;
@@ -67,25 +67,30 @@ public class GetAlbumTracksLiteQueryHandler : IQueryHandler<GetAlbumTracksLiteQu
return ApplicationErrors.Authorization.NotAuthorized;
Guid userId = currentUserId.Value;
Result<AlbumEntity?> 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<AlbumEntity?> 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<ILibraryOwnershipPolicy>(
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<PaginatedResultDto<TrackLiteRow>> getTracksResult = await _unitOfWork.TrackRepository.GetTracksLiteByAlbumIdAsync(query.AlbumId, paginationData, cancellationToken).ConfigureAwait(false);
Result<PaginatedResultDto<TrackLiteRow>> getTracksResult = await _unitOfWork.TrackRepository.GetTracksLiteByAlbumIdAsync(albumId, query.PaginationData, cancellationToken).ConfigureAwait(false);
return getTracksResult.Match(value => Result.From(value.ToResponses()), errors => errors);
}
}
@@ -17,10 +17,34 @@ public class GetAlbumTracksLiteQueryValidator : AbstractValidator<GetAlbumTracks
/// </summary>
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);
}
}
@@ -1,17 +0,0 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Diagnostics;
#endregion
namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
/// <summary>
/// Represents a request to delete an album by the specified Id.
/// </summary>
/// <param name="ArtistId">The unique identifier of the artist the album belongs to, taken from the route.</param>
/// <param name="AlbumId">The unique identifier of the album to delete.</param>
[DebuggerDisplay("AlbumId: {AlbumId}")]
public record DeleteAlbumRequest(
Guid ArtistId,
Guid AlbumId
);
@@ -1,17 +0,0 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Diagnostics;
#endregion
namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
/// <summary>
/// Represents a request to get an album by the specified Id.
/// </summary>
/// <param name="ArtistId">The unique identifier of the artist the album belongs to, taken from the route.</param>
/// <param name="AlbumId">The unique identifier of the album to retrieve.</param>
[DebuggerDisplay("AlbumId: {AlbumId}")]
public record GetAlbumRequest(
Guid ArtistId,
Guid AlbumId
);
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Diagnostics;
#endregion
@@ -8,14 +7,10 @@ namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Album
/// <summary>
/// Represents a request to get the lightweight read models of the tracks of an album.
/// </summary>
/// <param name="ArtistId">The unique identifier of the artist the album belongs to, taken from the route.</param>
/// <param name="AlbumId">The unique identifier of the album whose tracks are retrieved.</param>
/// <param name="CurrentPage">The page of results to retrieve. Optional.</param>
/// <param name="PerPage">The maximum number of tracks to retrieve per page. Optional.</param>
[DebuggerDisplay("AlbumId: {AlbumId}")]
[DebuggerDisplay("CurrentPage: {CurrentPage}, PerPage: {PerPage}")]
public record GetAlbumTracksLiteRequest(
Guid ArtistId,
Guid AlbumId,
int? CurrentPage,
int? PerPage
);
@@ -1,17 +0,0 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Diagnostics;
#endregion
namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
/// <summary>
/// Represents a request to get the tracks of an album.
/// </summary>
/// <param name="ArtistId">The unique identifier of the artist the album belongs to, taken from the route.</param>
/// <param name="AlbumId">The unique identifier of the album whose tracks are retrieved.</param>
[DebuggerDisplay("AlbumId: {AlbumId}")]
public record GetAlbumTracksRequest(
Guid ArtistId,
Guid AlbumId
);
@@ -197,23 +197,6 @@ internal sealed class AlbumRepository : IAlbumRepository
return await query.FirstOrDefaultAsync(album => album.Id == id, cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// Deletes the album identified by <paramref name="id"/>.
/// </summary>
/// <param name="id">The Id of the album to delete.</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 operation, or an error.</returns>
public async Task<Result<Deleted>> 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;
}
/// <summary>
/// Gets all the albums of the artist identified by <paramref name="artistId"/>.
/// </summary>
@@ -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;
/// <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 DeleteAlbumEndpoint : BaseEndpoint<DeleteAlbumRequest, IResult>
public class DeleteAlbumEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
{
private readonly ICommandHandler<DeleteAlbumCommand, Result<Deleted>> _deleteAlbumCommandHandler;
@@ -43,11 +41,16 @@ public class DeleteAlbumEndpoint : BaseEndpoint<DeleteAlbumRequest, IResult>
/// <summary>
/// Deletes an album by Id.
/// </summary>
/// <param name="request">The request containing the id of the album to be deleted.</param>
/// <param name="request">The request object.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(DeleteAlbumRequest request, CancellationToken cancellationToken)
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
{
Result<Deleted> 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<Deleted> result = await _deleteAlbumCommandHandler
.HandleAsync(new DeleteAlbumCommand(libraryId, artistId, albumId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -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 <see cref="DeleteAlbumEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteAlbumEndpointSummary : Summary<DeleteAlbumEndpoint, DeleteAlbumRequest>
public class DeleteAlbumEndpointSummary : Summary<DeleteAlbumEndpoint, EmptyRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="DeleteAlbumEndpointSummary"/> class.
@@ -20,15 +19,7 @@ public class DeleteAlbumEndpointSummary : Summary<DeleteAlbumEndpoint, DeleteAlb
public DeleteAlbumEndpointSummary()
{
Summary = "Deletes an existing album.";
Description = "Deletes the album identified by the request, together with its tracks. 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.";
ExampleRequest = new DeleteAlbumRequest(
ArtistId: Guid.NewGuid(),
AlbumId: Guid.NewGuid()
);
RequestParam(r => 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<DeleteAlbumEndpoint, DeleteAlb
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
detail = "Authentication failed",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}"
},
new
{
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'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
detail = "The token has expired",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}"
},
new
{
@@ -57,32 +48,65 @@ public class DeleteAlbumEndpointSummary : Summary<DeleteAlbumEndpoint, DeleteAlb
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}"
}
}
);
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
example: new
Response(403, "The request failed because the user making the request is not an Admin or the owner of the media library, or because deleting the album would leave its artist without any albums.", "application/problem+json",
example: new[]
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Unauthorized",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Unauthorized",
status = 403,
detail = "NotAuthorized",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Forbidden",
status = 403,
detail = "ArtistMustHaveAtLeastOneAlbum",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
}
);
Response(404, "The request failed because the requested album does not exist.", "application/problem+json",
example: new
Response(404, "The request failed because the requested artist, album, or their media library does not exist.", "application/problem+json",
example: new[]
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "AlbumNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
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",
title = "General.NotFound",
status = 404,
detail = "AlbumNotFound",
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",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
}
);
@@ -93,12 +117,14 @@ public class DeleteAlbumEndpointSummary : Summary<DeleteAlbumEndpoint, DeleteAlb
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"ArtistIdCannotBeEmpty",
"AlbumIdCannotBeEmpty"
}
}
@@ -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
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums/{albumId}</c> route.
/// </summary>
public class GetAlbumEndpoint : BaseEndpoint<GetAlbumRequest, IResult>
public class GetAlbumEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
{
private readonly IQueryHandler<GetAlbumQuery, Result<AlbumResponse>> _getAlbumQueryHandler;
@@ -45,11 +43,16 @@ public class GetAlbumEndpoint : BaseEndpoint<GetAlbumRequest, IResult>
/// <summary>
/// Gets an album by Id.
/// </summary>
/// <param name="request">The request containing the id of the album to be retrieved.</param>
/// <param name="request">The request object.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetAlbumRequest request, CancellationToken cancellationToken)
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
{
Result<AlbumResponse> 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<AlbumResponse> result = await _getAlbumQueryHandler.HandleAsync(query, cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -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 <see cref="GetAlbumEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, GetAlbumRequest>
public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, EmptyRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetAlbumEndpointSummary"/> class.
@@ -28,15 +27,7 @@ public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, GetAlbumRequest
public GetAlbumEndpointSummary()
{
Summary = "Gets an album by its Id.";
Description = "Returns the full details of the album identified by the request. 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.";
ExampleRequest = new GetAlbumRequest(
ArtistId: Guid.NewGuid(),
AlbumId: Guid.NewGuid()
);
RequestParam(r => 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<AlbumResponse>(r => r.Id, "The Id of the album.");
ResponseParam<AlbumResponse>(r => r.ArtistId, "The Id of the artist the album belongs to.");
@@ -159,7 +150,7 @@ public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, GetAlbumRequest
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}"
},
new
{
@@ -167,7 +158,7 @@ public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, GetAlbumRequest
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}"
},
new
{
@@ -175,7 +166,7 @@ public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, GetAlbumRequest
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}"
}
}
);
@@ -187,7 +178,7 @@ public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, GetAlbumRequest
title = "General.Unauthorized",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
@@ -199,7 +190,7 @@ public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, GetAlbumRequest
title = "General.NotFound",
status = 404,
detail = "AlbumNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
);
@@ -211,7 +202,7 @@ public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, GetAlbumRequest
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}",
errors = new Dictionary<string, string[]>
{
{
@@ -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
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums/{albumId}/tracks</c> route.
/// </summary>
public class GetAlbumTracksEndpoint : BaseEndpoint<GetAlbumTracksRequest, IResult>
public class GetAlbumTracksEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
{
private readonly IQueryHandler<GetAlbumTracksQuery, Result<IReadOnlyList<TrackResponse>>> _getAlbumTracksQueryHandler;
@@ -44,13 +42,18 @@ public class GetAlbumTracksEndpoint : BaseEndpoint<GetAlbumTracksRequest, IResul
}
/// <summary>
/// Gets the list of all the tracks of the album identified by <paramref name="request"/>.
/// Gets the list of all the tracks of the album identified by the route.
/// </summary>
/// <param name="request">The request containing the id of the album whose tracks are retrieved.</param>
/// <param name="request">The request object.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetAlbumTracksRequest request, CancellationToken cancellationToken)
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
{
Result<IReadOnlyList<TrackResponse>> 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<IReadOnlyList<TrackResponse>> result = await _getAlbumTracksQueryHandler.HandleAsync(query, cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -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 <see cref="GetAlbumTracksEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, GetAlbumTracksRequest>
public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, EmptyRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetAlbumTracksEndpointSummary"/> class.
@@ -28,15 +27,7 @@ public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, Get
public GetAlbumTracksEndpointSummary()
{
Summary = "Retrieves the list of tracks of an album.";
Description = "Returns the full details of the tracks of the album identified by the request. 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.";
ExampleRequest = new GetAlbumTracksRequest(
ArtistId: Guid.NewGuid(),
AlbumId: Guid.NewGuid()
);
RequestParam(r => 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<TrackResponse>(r => r.Id, "The Id of the track.");
ResponseParam<TrackResponse>(r => r.AlbumId, "The Id of the album the track belongs to.");
@@ -266,7 +257,7 @@ public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, Get
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks"
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks"
},
new
{
@@ -274,7 +265,7 @@ public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, Get
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks"
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks"
},
new
{
@@ -282,7 +273,7 @@ public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, Get
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks"
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks"
}
}
);
@@ -294,7 +285,7 @@ public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, Get
title = "General.Unauthorized",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
@@ -306,7 +297,7 @@ public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, Get
title = "General.NotFound",
status = 404,
detail = "AlbumNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
);
@@ -318,7 +309,7 @@ public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, Get
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks",
errors = new Dictionary<string, string[]>
{
{
@@ -44,13 +44,17 @@ public class GetAlbumTracksLiteEndpoint : BaseEndpoint<GetAlbumTracksLiteRequest
}
/// <summary>
/// Gets the lightweight read models of all the tracks of the album identified by <paramref name="request"/>.
/// Gets the lightweight read models of all the tracks of the album identified by the route.
/// </summary>
/// <param name="request">The request containing the id of the album whose tracks are retrieved.</param>
/// <param name="request">The request containing the pagination options of the tracks to be retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetAlbumTracksLiteRequest request, CancellationToken cancellationToken)
{
Result<PaginatedResponse<TrackLiteResponse>> 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<PaginatedResponse<TrackLiteResponse>> result = await _getAlbumTracksLiteQueryHandler.HandleAsync(request.ToQuery(libraryId, artistId, albumId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -25,14 +25,10 @@ public class GetAlbumTracksLiteEndpointSummary : Summary<GetAlbumTracksLiteEndpo
Description = "Returns the lightweight read models of the tracks of the album identified by its Id, projecting only the fields needed to display the songs of an album, without loading the full track entities and their related data. The page 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.";
ExampleRequest = new GetAlbumTracksLiteRequest(
ArtistId: Guid.NewGuid(),
AlbumId: Guid.NewGuid(),
CurrentPage: 1,
PerPage: 48
);
RequestParam(r => 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<GetAlbumTracksLiteEndpo
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite"
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/lite"
},
new
{
@@ -83,7 +79,7 @@ public class GetAlbumTracksLiteEndpointSummary : Summary<GetAlbumTracksLiteEndpo
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite"
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/lite"
},
new
{
@@ -91,7 +87,7 @@ public class GetAlbumTracksLiteEndpointSummary : Summary<GetAlbumTracksLiteEndpo
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite"
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/lite"
}
}
);
@@ -103,7 +99,7 @@ public class GetAlbumTracksLiteEndpointSummary : Summary<GetAlbumTracksLiteEndpo
title = "General.Unauthorized",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/lite",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
@@ -115,7 +111,7 @@ public class GetAlbumTracksLiteEndpointSummary : Summary<GetAlbumTracksLiteEndpo
title = "General.NotFound",
status = 404,
detail = "AlbumNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/lite",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
);
@@ -127,7 +123,7 @@ public class GetAlbumTracksLiteEndpointSummary : Summary<GetAlbumTracksLiteEndpo
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/lite",
errors = new Dictionary<string, string[]>
{
{