mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Refactors the artist slice across the stack
This commit is contained in:
1 parent
c112c64c25
commit
aa097ecc98
55 files changed
+3219
-278
No files matched your search
@@ -619,6 +619,7 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}
|
||||
],
|
||||
"albums": [
|
||||
{
|
||||
"albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f",
|
||||
"metadata": {
|
||||
"title": "A Night at the Opera",
|
||||
"originalTitle": "A Night at the Opera",
|
||||
@@ -680,6 +681,7 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}
|
||||
],
|
||||
"tracks": [
|
||||
{
|
||||
"trackId": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f",
|
||||
"path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
|
||||
"metadata": {
|
||||
"title": "Bohemian Rhapsody",
|
||||
@@ -754,6 +756,7 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}
|
||||
]
|
||||
},
|
||||
{
|
||||
"trackId": "8e1f2a3b-4c5d-4e6f-8a9b-0c1d2e3f4a5b",
|
||||
"path": "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac",
|
||||
"metadata": {
|
||||
"title": "You're My Best Friend",
|
||||
|
||||
@@ -12,6 +12,7 @@ Content-Type: application/json
|
||||
],
|
||||
"albums": [
|
||||
{
|
||||
"albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f",
|
||||
"metadata": {
|
||||
"title": "A Night at the Opera",
|
||||
"originalTitle": "A Night at the Opera",
|
||||
@@ -73,6 +74,7 @@ Content-Type: application/json
|
||||
],
|
||||
"tracks": [
|
||||
{
|
||||
"trackId": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f",
|
||||
"path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
|
||||
"metadata": {
|
||||
"title": "Bohemian Rhapsody",
|
||||
@@ -147,6 +149,7 @@ Content-Type: application/json
|
||||
]
|
||||
},
|
||||
{
|
||||
"trackId": "8e1f2a3b-4c5d-4e6f-8a9b-0c1d2e3f4a5b",
|
||||
"path": "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac",
|
||||
"metadata": {
|
||||
"title": "You're My Best Friend",
|
||||
|
||||
+3
-2
@@ -40,8 +40,9 @@ public static class ArtistMapping
|
||||
Albums = [.. domainEntity.Albums.Select(album => album.ToRepositoryEntity(domainEntity.Id.Value, domainEntity.LibraryId.Value))],
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedOnUtc = domainEntity.UpdatedOnUtc.HasValue ? domainEntity.UpdatedOnUtc : null,
|
||||
UpdatedBy = domainEntity.UpdatedOnUtc.HasValue ? Guid.NewGuid() : null
|
||||
// The audit columns are owned by the auditing interceptor, which stamps only the rows that actually changed, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
};
|
||||
}
|
||||
}
|
||||
+15
-4
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtistAlbumsLite;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
#endregion
|
||||
@@ -14,12 +15,22 @@ public static class GetArtistAlbumsLiteRequestMapping
|
||||
/// Converts <paramref name="request"/> to <see cref="GetArtistAlbumsLiteQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="libraryId">The Id of the library the artist belongs to, taken from the route.</param>
|
||||
/// <param name="artistId">The Id of the artist whose albums are retrieved, taken from the route.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetArtistAlbumsLiteQuery ToQuery(this GetArtistAlbumsLiteRequest request)
|
||||
public static GetArtistAlbumsLiteQuery ToQuery(this GetArtistAlbumsLiteRequest request, string? libraryId, string? artistId)
|
||||
{
|
||||
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 GetArtistAlbumsLiteQuery(
|
||||
request.ArtistId,
|
||||
request.CurrentPage,
|
||||
request.PerPage);
|
||||
libraryId,
|
||||
artistId,
|
||||
paginationData);
|
||||
}
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtistAlbums;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetArtistAlbumsRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetArtistAlbumsRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetArtistAlbumsQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetArtistAlbumsQuery ToQuery(this GetArtistAlbumsRequest request)
|
||||
{
|
||||
return new GetArtistAlbumsQuery(
|
||||
request.ArtistId);
|
||||
}
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtist;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetArtistRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetArtistRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetArtistQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetArtistQuery ToQuery(this GetArtistRequest request)
|
||||
{
|
||||
return new GetArtistQuery(
|
||||
request.ArtistId);
|
||||
}
|
||||
}
|
||||
+13
-4
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtistsLite;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
#endregion
|
||||
@@ -14,13 +15,21 @@ public static class GetArtistsLiteRequestMapping
|
||||
/// Converts <paramref name="request"/> to <see cref="GetArtistsLiteQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="libraryId">The Id of the library whose artists are retrieved, taken from the route.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetArtistsLiteQuery ToQuery(this GetArtistsLiteRequest request)
|
||||
public static GetArtistsLiteQuery ToQuery(this GetArtistsLiteRequest request, string? libraryId)
|
||||
{
|
||||
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 GetArtistsLiteQuery(
|
||||
request.LibraryId,
|
||||
request.CurrentPage,
|
||||
request.PerPage,
|
||||
libraryId,
|
||||
paginationData,
|
||||
request.SearchTerm);
|
||||
}
|
||||
}
|
||||
+13
-4
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtists;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
#endregion
|
||||
@@ -14,13 +15,21 @@ public static class GetArtistsRequestMapping
|
||||
/// Converts <paramref name="request"/> to <see cref="GetArtistsQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="libraryId">The Id of the library whose artists are retrieved, taken from the route.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetArtistsQuery ToQuery(this GetArtistsRequest request)
|
||||
public static GetArtistsQuery ToQuery(this GetArtistsRequest request, string? libraryId)
|
||||
{
|
||||
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 GetArtistsQuery(
|
||||
request.LibraryId,
|
||||
request.CurrentPage,
|
||||
request.PerPage,
|
||||
libraryId,
|
||||
paginationData,
|
||||
request.SearchTerm);
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.AddAlbum;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="UpdateArtistAlbumRequest"/>.
|
||||
/// </summary>
|
||||
public static class UpdateArtistAlbumRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="AddAlbumCommand"/>.
|
||||
/// </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>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static AddAlbumCommand ToCommand(this UpdateArtistAlbumRequest request, string? libraryId, string? artistId)
|
||||
{
|
||||
return new AddAlbumCommand(
|
||||
libraryId,
|
||||
artistId,
|
||||
request.Metadata,
|
||||
request.MediaFormat,
|
||||
request.Barcode,
|
||||
request.CatalogNumber,
|
||||
request.MusicBrainzReleaseId,
|
||||
request.MusicBrainzReleaseGroupId,
|
||||
request.MusicBrainzReleaseArtistId,
|
||||
request.Contributors,
|
||||
request.Ratings,
|
||||
request.Tracks?.ToCommands(libraryId, artistId, null).ToList(),
|
||||
request.AlbumId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="requests"/> to a collection of <see cref="AddAlbumCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="requests">The requests to be converted.</param>
|
||||
/// <param name="libraryId">The Id of the library the albums belong to, taken from the route.</param>
|
||||
/// <param name="artistId">The Id of the artist the albums belong to, taken from the route.</param>
|
||||
/// <returns>The converted commands.</returns>
|
||||
public static IEnumerable<AddAlbumCommand> ToCommands(this IEnumerable<UpdateArtistAlbumRequest> requests, string? libraryId, string? artistId)
|
||||
{
|
||||
return requests.Select(request => request.ToCommand(libraryId, artistId));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -32,13 +32,13 @@ public static class UpdateArtistCommandMapping
|
||||
{
|
||||
// Map the media contributors that make up the artist to their domain counterparts.
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors) ?? []];
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
// Build each album of the artist, together with its metadata, contributors, ratings and tracks.
|
||||
IEnumerable<Result<Album>> domainAlbumsResult = command.Albums!.ToDomainEntities();
|
||||
errors = [.. domainAlbumsResult.Where(albumResult => albumResult.IsFailure).SelectMany(albumResult => albumResult.Errors) ?? []];
|
||||
errors = [.. domainAlbumsResult.Where(albumResult => albumResult.IsFailure).SelectMany(albumResult => albumResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.UpdateArtist;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using System.Linq;
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.AddTrack;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="UpdateArtistTrackRequest"/>.
|
||||
/// </summary>
|
||||
public static class UpdateArtistTrackRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="AddTrackCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="libraryId">The Id of the library the track belongs to, taken from the route.</param>
|
||||
/// <param name="artistId">The Id of the artist the track belongs to, taken from the route.</param>
|
||||
/// <param name="albumId">The Id of the album the track belongs to, taken from the route.</param>
|
||||
/// <returns>The converted command.</returns>
|
||||
public static AddTrackCommand ToCommand(this UpdateArtistTrackRequest request, string? libraryId, string? artistId, string? albumId)
|
||||
{
|
||||
return new AddTrackCommand(
|
||||
libraryId,
|
||||
artistId,
|
||||
albumId,
|
||||
request.Path,
|
||||
request.Metadata,
|
||||
request.TrackNumber,
|
||||
request.DiscNumber,
|
||||
request.Script,
|
||||
request.Key,
|
||||
request.Bpm,
|
||||
request.Work,
|
||||
request.MusicBrainzRecordingId,
|
||||
request.MusicBrainzTrackId,
|
||||
request.MusicBrainzWorkId,
|
||||
request.Moods,
|
||||
request.Isrcs,
|
||||
request.Contributors,
|
||||
request.Ratings,
|
||||
request.TrackId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="requests"/> to a collection of <see cref="AddTrackCommand"/>.
|
||||
/// </summary>
|
||||
/// <param name="requests">The requests to be converted.</param>
|
||||
/// <param name="libraryId">The Id of the library the tracks belong to, taken from the route.</param>
|
||||
/// <param name="artistId">The Id of the artist the tracks belong to, taken from the route.</param>
|
||||
/// <param name="albumId">The Id of the album the tracks belong to, taken from the route.</param>
|
||||
/// <returns>The converted commands.</returns>
|
||||
public static IEnumerable<AddTrackCommand> ToCommands(this IEnumerable<UpdateArtistTrackRequest> requests, string? libraryId, string? artistId, string? albumId)
|
||||
{
|
||||
return requests.Select(request => request.ToCommand(libraryId, artistId, albumId));
|
||||
}
|
||||
}
|
||||
+10
@@ -242,6 +242,16 @@ public class AddArtistCommandValidator : AbstractValidator<AddArtistCommand>
|
||||
.When(a => a!.CatalogNumber is not null)
|
||||
.WithError(Errors.Music.CatalogNumberMustBeMaximum50CharactersLong);
|
||||
|
||||
album.RuleFor(a => a!.Barcode)
|
||||
.NotEmpty()
|
||||
.When(a => a!.Barcode is not null)
|
||||
.WithError(Errors.Music.BarcodeValueCannotBeEmpty);
|
||||
|
||||
album.RuleFor(a => a!.Barcode)
|
||||
.Matches(@"^\d{12,13}$")
|
||||
.When(a => a!.Barcode is not null && a!.Barcode.Length > 0)
|
||||
.WithError(Errors.Music.InvalidFormatForBarcode);
|
||||
|
||||
// Validates the MusicBrainz identifiers of the album.
|
||||
album.RuleFor(a => a!.MusicBrainzReleaseId)
|
||||
.Must(musicBrainzReleaseId => musicBrainzReleaseId != Guid.Empty)
|
||||
|
||||
+1
-1
@@ -100,6 +100,6 @@ public class DeleteArtistCommandHandler : ICommandHandler<DeleteArtistCommand, R
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
|
||||
return deleteArtistResult;
|
||||
return Result.Deleted;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -79,8 +79,8 @@ public class UpdateArtistCommandHandler : ICommandHandler<UpdateArtistCommand, R
|
||||
Guid libraryId = Guid.Parse(command.LibraryId!);
|
||||
Guid artistId = Guid.Parse(command.ArtistId!);
|
||||
|
||||
// Get the existing artist with all its related data.
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
// Get the existing artist, only for its identity and creation metadata; the repository reloads and tracks the whole aggregate when it applies the update.
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: false, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getArtistResult.IsFailure)
|
||||
return getArtistResult.Errors;
|
||||
if (getArtistResult.Value is null)
|
||||
|
||||
+22
@@ -82,6 +82,12 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
RuleForEach(command => command.Albums)
|
||||
.ChildRules(album =>
|
||||
{
|
||||
// Validates the identifier of the album, when the album already exists.
|
||||
album.RuleFor(a => a!.AlbumId)
|
||||
.Must(albumId => albumId != Guid.Empty)
|
||||
.When(a => a!.AlbumId.HasValue)
|
||||
.WithError(Errors.Music.AlbumIdCannotBeEmpty);
|
||||
|
||||
// Validates the metadata of the album: title, lengths, release type and status, and disc and track counts.
|
||||
album.RuleFor(a => a!.Metadata)
|
||||
.NotNull()
|
||||
@@ -252,6 +258,16 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
.When(a => a!.CatalogNumber is not null)
|
||||
.WithError(Errors.Music.CatalogNumberMustBeMaximum50CharactersLong);
|
||||
|
||||
album.RuleFor(a => a!.Barcode)
|
||||
.NotEmpty()
|
||||
.When(a => a!.Barcode is not null)
|
||||
.WithError(Errors.Music.BarcodeValueCannotBeEmpty);
|
||||
|
||||
album.RuleFor(a => a!.Barcode)
|
||||
.Matches(@"^\d{12,13}$")
|
||||
.When(a => a!.Barcode is not null && a!.Barcode.Length > 0)
|
||||
.WithError(Errors.Music.InvalidFormatForBarcode);
|
||||
|
||||
// Validates the MusicBrainz identifiers of the album.
|
||||
album.RuleFor(a => a!.MusicBrainzReleaseId)
|
||||
.Must(musicBrainzReleaseId => musicBrainzReleaseId != Guid.Empty)
|
||||
@@ -319,6 +335,12 @@ public class UpdateArtistCommandValidator : AbstractValidator<UpdateArtistComman
|
||||
album.RuleForEach(a => a!.Tracks)
|
||||
.ChildRules(track =>
|
||||
{
|
||||
// Validates the identifier of the track, when the track already exists.
|
||||
track.RuleFor(t => t!.TrackId)
|
||||
.Must(trackId => trackId != Guid.Empty)
|
||||
.When(t => t!.TrackId.HasValue)
|
||||
.WithError(Errors.Music.TrackIdCannotBeEmpty);
|
||||
|
||||
// Validates the file system path of the track.
|
||||
track.RuleFor(t => t!.Path)
|
||||
.NotEmpty()
|
||||
|
||||
+4
-2
@@ -9,8 +9,10 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists
|
||||
/// <summary>
|
||||
/// Query for getting an artist by its Id.
|
||||
/// </summary>
|
||||
/// <param name="ArtistId">The unique identifier of the artist to get.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the media library the artist belongs to, taken from the route.</param>
|
||||
/// <param name="ArtistId">The unique identifier of the artist to get, taken from the route.</param>
|
||||
[DebuggerDisplay("ArtistId: {ArtistId}")]
|
||||
public record GetArtistQuery(
|
||||
Guid ArtistId
|
||||
string? LibraryId,
|
||||
string? ArtistId
|
||||
) : IQuery;
|
||||
+14
-4
@@ -65,18 +65,28 @@ public class GetArtistQueryHandler : IQueryHandler<GetArtistQuery, Result<Artist
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// Admins can see all artists; for everyone else, only the artists of the libraries they own.
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(query.ArtistId, 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!);
|
||||
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getArtistResult.IsFailure)
|
||||
return getArtistResult.Errors;
|
||||
if (getArtistResult.Value is null)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
ArtistEntity existingArtist = getArtistResult.Value;
|
||||
|
||||
// Resource scoping: the artist must belong to the library named by the route, so that an artist can never be read through another
|
||||
// library's route; the mismatch is reported as not found, without disclosing that the artist exists in another library.
|
||||
if (existingArtist.LibraryId != libraryId)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
|
||||
// Admins can see all artists; for everyone else, only the artists of the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(getArtistResult.Value.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
userId, new LibraryOwnershipPolicyContext(existingArtist.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
return getArtistResult.Value.ToResponse();
|
||||
return existingArtist.ToResponse();
|
||||
}
|
||||
}
|
||||
+16
-2
@@ -17,10 +17,24 @@ public class GetArtistQueryValidator : AbstractValidator<GetArtistQuery>
|
||||
/// </summary>
|
||||
public GetArtistQueryValidator()
|
||||
{
|
||||
// Validates the identifier of the media library the artist 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 to get, taken from the route.
|
||||
RuleFor(query => query.ArtistId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.ArtistIdCannotBeEmpty)
|
||||
.Must(id => id != Guid.Empty)
|
||||
.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);
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -9,8 +9,10 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists
|
||||
/// <summary>
|
||||
/// Query for getting all the albums of an artist.
|
||||
/// </summary>
|
||||
/// <param name="ArtistId">The unique identifier of the artist whose albums are retrieved.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the media library the artist belongs to, taken from the route.</param>
|
||||
/// <param name="ArtistId">The unique identifier of the artist whose albums are retrieved, taken from the route.</param>
|
||||
[DebuggerDisplay("ArtistId: {ArtistId}")]
|
||||
public record GetArtistAlbumsQuery(
|
||||
Guid ArtistId
|
||||
string? LibraryId,
|
||||
string? ArtistId
|
||||
) : IQuery;
|
||||
+13
-3
@@ -65,19 +65,29 @@ public class GetArtistAlbumsQueryHandler : IQueryHandler<GetArtistAlbumsQuery, R
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(query.ArtistId, 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!);
|
||||
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: false, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getArtistResult.IsFailure)
|
||||
return getArtistResult.Errors;
|
||||
if (getArtistResult.Value is null)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
ArtistEntity existingArtist = getArtistResult.Value;
|
||||
|
||||
// Resource scoping: the artist must belong to the library named by the route, so that the albums of an artist can never be read through
|
||||
// another library's route; the mismatch is reported as not found, without disclosing that the artist exists in another library.
|
||||
if (existingArtist.LibraryId != libraryId)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
|
||||
// Admins can see the albums of the artists of all libraries; for everyone else, only of the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(getArtistResult.Value.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
userId, new LibraryOwnershipPolicyContext(existingArtist.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Result<IReadOnlyList<AlbumEntity>> getAlbumsResult = await _unitOfWork.AlbumRepository.GetByArtistIdAsync(query.ArtistId, cancellationToken).ConfigureAwait(false);
|
||||
Result<IReadOnlyList<AlbumEntity>> getAlbumsResult = await _unitOfWork.AlbumRepository.GetByArtistIdAsync(artistId, cancellationToken).ConfigureAwait(false);
|
||||
return getAlbumsResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
}
|
||||
}
|
||||
+16
-2
@@ -17,10 +17,24 @@ public class GetArtistAlbumsQueryValidator : AbstractValidator<GetArtistAlbumsQu
|
||||
/// </summary>
|
||||
public GetArtistAlbumsQueryValidator()
|
||||
{
|
||||
// Validates the identifier of the media library the artist 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 whose albums are retrieved, taken from the route.
|
||||
RuleFor(query => query.ArtistId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.ArtistIdCannotBeEmpty)
|
||||
.Must(artistId => artistId != Guid.Empty)
|
||||
.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);
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -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,12 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists
|
||||
/// <summary>
|
||||
/// Query for getting the lightweight read models of all the albums of an artist.
|
||||
/// </summary>
|
||||
/// <param name="ArtistId">The unique identifier of the artist whose albums are retrieved.</param>
|
||||
/// <param name="CurrentPage">The page of results to retrieve.</param>
|
||||
/// <param name="PerPage">The maximum number of albums to retrieve per page.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the media library the artist belongs to, taken from the route.</param>
|
||||
/// <param name="ArtistId">The unique identifier of the artist whose albums are retrieved, taken from the route.</param>
|
||||
/// <param name="PaginationData">The object containing the requested pagination data.</param>
|
||||
[DebuggerDisplay("ArtistId: {ArtistId}")]
|
||||
public record GetArtistAlbumsLiteQuery(
|
||||
Guid ArtistId,
|
||||
int? CurrentPage,
|
||||
int? PerPage
|
||||
string? LibraryId,
|
||||
string? ArtistId,
|
||||
PaginationDataDto? PaginationData
|
||||
) : IQuery;
|
||||
+13
-9
@@ -67,25 +67,29 @@ public class GetArtistAlbumsLiteQueryHandler : IQueryHandler<GetArtistAlbumsLite
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(query.ArtistId, 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!);
|
||||
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: false, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getArtistResult.IsFailure)
|
||||
return getArtistResult.Errors;
|
||||
if (getArtistResult.Value is null)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
ArtistEntity existingArtist = getArtistResult.Value;
|
||||
|
||||
// Resource scoping: the artist must belong to the library named by the route, so that the albums of an artist can never be read through
|
||||
// another library's route; the mismatch is reported as not found, without disclosing that the artist exists in another library.
|
||||
if (existingArtist.LibraryId != libraryId)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
|
||||
// Admins can see the albums of the artists of all libraries; for everyone else, only of the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(getArtistResult.Value.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
userId, new LibraryOwnershipPolicyContext(existingArtist.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
PaginationDataDto paginationData = new()
|
||||
{
|
||||
CurrentPage = query.CurrentPage ?? 1,
|
||||
PerPage = query.PerPage ?? 200
|
||||
};
|
||||
|
||||
Result<PaginatedResultDto<AlbumLiteRow>> getAlbumsResult = await _unitOfWork.AlbumRepository.GetAlbumsLiteByArtistIdAsync(query.ArtistId, paginationData, cancellationToken).ConfigureAwait(false);
|
||||
Result<PaginatedResultDto<AlbumLiteRow>> getAlbumsResult = await _unitOfWork.AlbumRepository.GetAlbumsLiteByArtistIdAsync(artistId, query.PaginationData, cancellationToken).ConfigureAwait(false);
|
||||
return getAlbumsResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
}
|
||||
}
|
||||
+16
-2
@@ -17,10 +17,24 @@ public class GetArtistAlbumsLiteQueryValidator : AbstractValidator<GetArtistAlbu
|
||||
/// </summary>
|
||||
public GetArtistAlbumsLiteQueryValidator()
|
||||
{
|
||||
// Validates the identifier of the media library the artist 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 whose albums are retrieved, taken from the route.
|
||||
RuleFor(query => query.ArtistId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.ArtistIdCannotBeEmpty)
|
||||
.Must(artistId => artistId != Guid.Empty)
|
||||
.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);
|
||||
}
|
||||
}
|
||||
+5
-7
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -9,14 +9,12 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists
|
||||
/// <summary>
|
||||
/// Query for getting all the artists of a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library whose artists are retrieved.</param>
|
||||
/// <param name="CurrentPage">The page of results to retrieve.</param>
|
||||
/// <param name="PerPage">The maximum number of artists to retrieve per page.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the media library whose artists are retrieved, taken from the route.</param>
|
||||
/// <param name="PaginationData">The object containing the requested pagination data.</param>
|
||||
/// <param name="SearchTerm">The search term used to filter the artists by name.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
public record GetArtistsQuery(
|
||||
Guid LibraryId,
|
||||
int? CurrentPage,
|
||||
int? PerPage,
|
||||
string? LibraryId,
|
||||
PaginationDataDto? PaginationData,
|
||||
string? SearchTerm
|
||||
) : IQuery;
|
||||
+6
-9
@@ -67,26 +67,23 @@ public class GetArtistsQueryHandler : IQueryHandler<GetArtistsQuery, Result<Pagi
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// The validator guarantees that the library id of the route is a non-empty Guid before this point.
|
||||
Guid libraryId = Guid.Parse(query.LibraryId!);
|
||||
|
||||
// Admins can see the artists of all libraries; for everyone else, only the artists of the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(query.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
userId, new LibraryOwnershipPolicyContext(libraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
PaginationDataDto paginationData = new()
|
||||
{
|
||||
CurrentPage = query.CurrentPage ?? 1,
|
||||
PerPage = query.PerPage ?? 200
|
||||
};
|
||||
|
||||
LibraryFilterDto libraryFilter = new()
|
||||
{
|
||||
LibraryId = query.LibraryId,
|
||||
LibraryId = libraryId,
|
||||
SearchTerm = query.SearchTerm
|
||||
};
|
||||
|
||||
Result<PaginatedResultDto<ArtistEntity>> getArtistsResult = await _unitOfWork.ArtistRepository
|
||||
.GetAllAsync(paginationData, filterModel: libraryFilter, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
.GetAllAsync(query.PaginationData, filterModel: libraryFilter, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return getArtistsResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -17,10 +17,14 @@ public class GetArtistsQueryValidator : AbstractValidator<GetArtistsQuery>
|
||||
/// </summary>
|
||||
public GetArtistsQueryValidator()
|
||||
{
|
||||
// Validates the identifier of the media library whose artists are retrieved, taken from the route.
|
||||
RuleFor(query => query.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty)
|
||||
.Must(libraryId => libraryId != Guid.Empty)
|
||||
.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);
|
||||
}
|
||||
}
|
||||
+5
-7
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -9,14 +9,12 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists
|
||||
/// <summary>
|
||||
/// Query for getting the lightweight read models of all the artists of a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library whose artists are retrieved.</param>
|
||||
/// <param name="CurrentPage">The page of results to retrieve.</param>
|
||||
/// <param name="PerPage">The maximum number of artists to retrieve per page.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the media library whose artists are retrieved, taken from the route.</param>
|
||||
/// <param name="PaginationData">The object containing the requested pagination data.</param>
|
||||
/// <param name="SearchTerm">The search term used to filter the artists by name.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
public record GetArtistsLiteQuery(
|
||||
Guid LibraryId,
|
||||
int? CurrentPage,
|
||||
int? PerPage,
|
||||
string? LibraryId,
|
||||
PaginationDataDto? PaginationData,
|
||||
string? SearchTerm
|
||||
) : IQuery;
|
||||
+6
-8
@@ -66,25 +66,23 @@ public class GetArtistsLiteQueryHandler : IQueryHandler<GetArtistsLiteQuery, Res
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// The validator guarantees that the library id of the route is a non-empty Guid before this point.
|
||||
Guid libraryId = Guid.Parse(query.LibraryId!);
|
||||
|
||||
// Admins can see the artists of all libraries; for everyone else, only the artists of the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(query.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
userId, new LibraryOwnershipPolicyContext(libraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
PaginationDataDto paginationData = new()
|
||||
{
|
||||
CurrentPage = query.CurrentPage ?? 1,
|
||||
PerPage = query.PerPage ?? 200
|
||||
};
|
||||
LibraryFilterDto filter = new()
|
||||
{
|
||||
LibraryId = query.LibraryId,
|
||||
LibraryId = libraryId,
|
||||
SearchTerm = query.SearchTerm
|
||||
};
|
||||
|
||||
Result<PaginatedResultDto<ArtistLiteRow>> getArtistsResult = await _unitOfWork.ArtistRepository.GetAllLiteAsync(
|
||||
paginationData,
|
||||
query.PaginationData,
|
||||
filterModel: filter,
|
||||
cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return getArtistsResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
|
||||
+6
-2
@@ -17,10 +17,14 @@ public class GetArtistsLiteQueryValidator : AbstractValidator<GetArtistsLiteQuer
|
||||
/// </summary>
|
||||
public GetArtistsLiteQueryValidator()
|
||||
{
|
||||
// Validates the identifier of the media library whose artists are retrieved, taken from the route.
|
||||
RuleFor(query => query.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty)
|
||||
.Must(libraryId => libraryId != Guid.Empty)
|
||||
.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);
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -8,12 +7,10 @@ namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artis
|
||||
/// <summary>
|
||||
/// Represents a request to get the lightweight read models of the albums of an artist.
|
||||
/// </summary>
|
||||
/// <param name="ArtistId">The unique identifier of the artist whose albums are retrieved.</param>
|
||||
/// <param name="CurrentPage">The page of results to retrieve. Optional.</param>
|
||||
/// <param name="PerPage">The maximum number of albums to retrieve per page. Optional.</param>
|
||||
[DebuggerDisplay("ArtistId: {ArtistId}")]
|
||||
[DebuggerDisplay("CurrentPage: {CurrentPage}, PerPage: {PerPage}")]
|
||||
public record GetArtistAlbumsLiteRequest(
|
||||
Guid ArtistId,
|
||||
int? CurrentPage,
|
||||
int? PerPage
|
||||
);
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to get the albums of an artist.
|
||||
/// </summary>
|
||||
/// <param name="ArtistId">The unique identifier of the artist whose albums are retrieved.</param>
|
||||
[DebuggerDisplay("ArtistId: {ArtistId}")]
|
||||
public record GetArtistAlbumsRequest(
|
||||
Guid ArtistId
|
||||
);
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to get an artist by the specified Id.
|
||||
/// </summary>
|
||||
/// <param name="ArtistId">The unique identifier of the artist to retrieve.</param>
|
||||
[DebuggerDisplay("ArtistId: {ArtistId}")]
|
||||
public record GetArtistRequest(
|
||||
Guid ArtistId
|
||||
);
|
||||
+1
-4
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -8,13 +7,11 @@ namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artis
|
||||
/// <summary>
|
||||
/// Represents a request to get the lightweight read models of the artists of a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library whose artists are retrieved. Required.</param>
|
||||
/// <param name="CurrentPage">The page of results to retrieve. Optional.</param>
|
||||
/// <param name="PerPage">The maximum number of artists to retrieve per page. Optional.</param>
|
||||
/// <param name="SearchTerm">The search term used to filter the artists by name. Optional.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
[DebuggerDisplay("SearchTerm: {SearchTerm}")]
|
||||
public record GetArtistsLiteRequest(
|
||||
Guid LibraryId,
|
||||
int? CurrentPage,
|
||||
int? PerPage,
|
||||
string? SearchTerm
|
||||
|
||||
+1
-4
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -8,13 +7,11 @@ namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artis
|
||||
/// <summary>
|
||||
/// Represents a request to get the artists of a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library whose artists are retrieved. Required.</param>
|
||||
/// <param name="CurrentPage">The page of results to retrieve. Optional.</param>
|
||||
/// <param name="PerPage">The maximum number of artists to retrieve per page. Optional.</param>
|
||||
/// <param name="SearchTerm">The search term used to filter the artists by name. Optional.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
[DebuggerDisplay("SearchTerm: {SearchTerm}")]
|
||||
public record GetArtistsRequest(
|
||||
Guid LibraryId,
|
||||
int? CurrentPage,
|
||||
int? PerPage,
|
||||
string? SearchTerm
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to update an album of an artist, together with the tracks of the album, within an artist update.
|
||||
/// </summary>
|
||||
/// <param name="AlbumId">The Id of the album, when the album already exists. Optional.</param>
|
||||
/// <param name="Metadata">The album metadata of the album. Required.</param>
|
||||
/// <param name="MediaFormat">The physical or digital medium of the album. Optional.</param>
|
||||
/// <param name="Barcode">The barcode of the album. Optional.</param>
|
||||
/// <param name="CatalogNumber">The catalog number of the album. Optional.</param>
|
||||
/// <param name="MusicBrainzReleaseId">The MusicBrainz identifier of the release. Optional.</param>
|
||||
/// <param name="MusicBrainzReleaseGroupId">The MusicBrainz identifier of the release group. Optional.</param>
|
||||
/// <param name="MusicBrainzReleaseArtistId">The MusicBrainz identifier of the release artist. Optional.</param>
|
||||
/// <param name="Contributors">The list of media contributors that performed on the album. Required.</param>
|
||||
/// <param name="Ratings">The list of ratings for this album. Required.</param>
|
||||
/// <param name="Tracks">The list of tracks of the album, each with the Id of the track when the track already exists. Required.</param>
|
||||
[DebuggerDisplay("Title: {Metadata.Title}")]
|
||||
public record UpdateArtistAlbumRequest(
|
||||
Guid? AlbumId,
|
||||
AlbumMetadataDto? Metadata,
|
||||
MusicMediaFormat? MediaFormat,
|
||||
string? Barcode,
|
||||
string? CatalogNumber,
|
||||
Guid? MusicBrainzReleaseId,
|
||||
Guid? MusicBrainzReleaseGroupId,
|
||||
Guid? MusicBrainzReleaseArtistId,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AudioRatingDto>? Ratings,
|
||||
List<UpdateArtistTrackRequest>? Tracks
|
||||
);
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -22,5 +21,5 @@ public record UpdateArtistRequest(
|
||||
string? Website,
|
||||
Guid? MusicBrainzArtistId,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AddAlbumRequest>? Albums
|
||||
List<UpdateArtistAlbumRequest>? Albums
|
||||
);
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
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.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to update a track of an album of an artist, within an artist update.
|
||||
/// </summary>
|
||||
/// <param name="TrackId">The Id of the track, when the track already exists. Optional.</param>
|
||||
/// <param name="Path">The file system path of the track. Required.</param>
|
||||
/// <param name="Metadata">The audio metadata of the track. Required.</param>
|
||||
/// <param name="TrackNumber">The number of the track on its disc. Required.</param>
|
||||
/// <param name="DiscNumber">The number of the disc the track belongs to. Optional.</param>
|
||||
/// <param name="Script">The script used by the language of the track. Optional.</param>
|
||||
/// <param name="Key">The musical key of the track. Optional.</param>
|
||||
/// <param name="Bpm">The tempo of the track in beats per minute. Optional.</param>
|
||||
/// <param name="Work">The title of the work the track is a recording of. Optional.</param>
|
||||
/// <param name="MusicBrainzRecordingId">The MusicBrainz identifier of the recording. Optional.</param>
|
||||
/// <param name="MusicBrainzTrackId">The MusicBrainz identifier of the track. Optional.</param>
|
||||
/// <param name="MusicBrainzWorkId">The MusicBrainz identifier of the work. Optional.</param>
|
||||
/// <param name="Moods">The list of moods of the track. Optional.</param>
|
||||
/// <param name="Isrcs">The list of ISRC (International Standard Recording Code) of the track. Optional.</param>
|
||||
/// <param name="Contributors">The list of media contributors that performed on the track. Required.</param>
|
||||
/// <param name="Ratings">The list of ratings for this track. Required.</param>
|
||||
[DebuggerDisplay("Title: {Metadata.Title}")]
|
||||
public record UpdateArtistTrackRequest(
|
||||
Guid? TrackId,
|
||||
string? Path,
|
||||
AudioMetadataDto? Metadata,
|
||||
int? TrackNumber,
|
||||
int? DiscNumber,
|
||||
string? Script,
|
||||
MusicKey? Key,
|
||||
int? Bpm,
|
||||
string? Work,
|
||||
Guid? MusicBrainzRecordingId,
|
||||
Guid? MusicBrainzTrackId,
|
||||
Guid? MusicBrainzWorkId,
|
||||
List<MoodDto>? Moods,
|
||||
List<IsrcDto>? Isrcs,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AudioRatingDto>? Ratings
|
||||
);
|
||||
Generated
+2608
File diff suppressed because it is too large.
Load diff
+37
@@ -0,0 +1,37 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Lumina.DataAccess.Common.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class MakesArtistNameUniquePerLibrary : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Artists_LibraryId_Name",
|
||||
table: "Artists");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Artists_LibraryId_Name",
|
||||
table: "Artists",
|
||||
columns: new[] { "LibraryId", "Name" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Artists_LibraryId_Name",
|
||||
table: "Artists");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Artists_LibraryId_Name",
|
||||
table: "Artists",
|
||||
columns: new[] { "LibraryId", "Name" });
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -370,4 +370,27 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
|
||||
return Result.Created;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a track from an album of the artist.
|
||||
/// </summary>
|
||||
/// <param name="albumId">The Id of the album the track is removed from.</param>
|
||||
/// <param name="trackId">The Id of the track to remove.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
/// <remarks>
|
||||
/// A track is a child entity of the artist aggregate, not an aggregate root, so it is removed through its owning artist,
|
||||
/// which is the consistency boundary. This difference is intentional.
|
||||
/// </remarks>
|
||||
public Result<Deleted> RemoveTrackFromAlbum(AlbumId albumId, TrackId trackId)
|
||||
{
|
||||
Album? album = _albums.FirstOrDefault(album => album.Id == albumId);
|
||||
if (album is null)
|
||||
return Errors.Music.AlbumNotFound;
|
||||
|
||||
Track? track = album.Tracks.FirstOrDefault(track => track.Id == trackId);
|
||||
if (track is null)
|
||||
return Errors.Music.TrackNotFound;
|
||||
|
||||
return album.RemoveTrack(track);
|
||||
}
|
||||
}
|
||||
+23
-10
@@ -775,15 +775,27 @@ public class AddArtistEndpointSummary : Summary<AddArtistEndpoint, AddArtistRequ
|
||||
}
|
||||
);
|
||||
|
||||
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 the artist would be created 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/{Guid.NewGuid()}/artists",
|
||||
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",
|
||||
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",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -889,6 +901,8 @@ public class AddArtistEndpointSummary : Summary<AddArtistEndpoint, AddArtistRequ
|
||||
"LanguageNativeNameMustBeMaximum50CharactersLong",
|
||||
"UnknownMusicMediaFormat",
|
||||
"CatalogNumberMustBeMaximum50CharactersLong",
|
||||
"BarcodeValueCannotBeEmpty",
|
||||
"InvalidFormatForBarcode",
|
||||
"RatingsListCannotBeNull",
|
||||
"RatingValueMustBePositive",
|
||||
"RatingValueCannotBeGreaterThanMaxValue",
|
||||
@@ -905,8 +919,7 @@ public class AddArtistEndpointSummary : Summary<AddArtistEndpoint, AddArtistRequ
|
||||
"WorkMustBeMaximum255CharactersLong",
|
||||
"MoodNameCannotBeEmpty",
|
||||
"IsrcValueCannotBeEmpty",
|
||||
"TrackPathMustBeWithinLibraryContentLocations",
|
||||
"ArtistMustHaveAtLeastOneAlbum"
|
||||
"TrackPathMustBeWithinLibraryContentLocations"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.DeleteArtist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{libraryId}/artists/{artistId}</c> route.
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}</c> route.
|
||||
/// </summary>
|
||||
public class DeleteArtistEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
|
||||
+8
-6
@@ -1,9 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtist;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
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}</c> route.
|
||||
/// </summary>
|
||||
public class GetArtistEndpoint : BaseEndpoint<GetArtistRequest, IResult>
|
||||
public class GetArtistEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetArtistQuery, Result<ArtistResponse>> _getArtistQueryHandler;
|
||||
|
||||
@@ -45,11 +43,15 @@ public class GetArtistEndpoint : BaseEndpoint<GetArtistRequest, IResult>
|
||||
/// <summary>
|
||||
/// Gets an artist by Id.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the id of the artist 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(GetArtistRequest request, CancellationToken cancellationToken)
|
||||
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<ArtistResponse> result = await _getArtistQueryHandler.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();
|
||||
GetArtistQuery query = new(libraryId, artistId);
|
||||
Result<ArtistResponse> result = await _getArtistQueryHandler.HandleAsync(query, cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+8
-15
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using System;
|
||||
@@ -14,7 +13,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibra
|
||||
/// Class used for providing a textual description for the <see cref="GetArtistEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, GetArtistRequest>
|
||||
public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetArtistEndpointSummary"/> class.
|
||||
@@ -22,13 +21,7 @@ public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, GetArtistRequ
|
||||
public GetArtistEndpointSummary()
|
||||
{
|
||||
Summary = "Gets an artist by its Id.";
|
||||
Description = "Returns the full details of the artist identified by the request. The artist is returned to an Admin, who can see the artists of all libraries, or to the owner of the library of the artist.";
|
||||
|
||||
ExampleRequest = new GetArtistRequest(
|
||||
ArtistId: Guid.NewGuid()
|
||||
);
|
||||
|
||||
RequestParam(r => r.ArtistId, "The Id of the artist to get. Required.");
|
||||
Description = "Returns the full details of the artist identified by the route. The artist is returned to an Admin, who can see the artists of all libraries, or to the owner of the library of the artist.";
|
||||
|
||||
ResponseParam<ArtistResponse>(r => r.Id, "The Id of the artist.");
|
||||
ResponseParam<ArtistResponse>(r => r.LibraryId, "The Id of the media library this artist belongs to.");
|
||||
@@ -67,7 +60,7 @@ public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, GetArtistRequ
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}"
|
||||
},
|
||||
new
|
||||
{
|
||||
@@ -75,7 +68,7 @@ public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, GetArtistRequ
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}"
|
||||
},
|
||||
new
|
||||
{
|
||||
@@ -83,7 +76,7 @@ public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, GetArtistRequ
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}"
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -95,7 +88,7 @@ public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, GetArtistRequ
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
@@ -107,7 +100,7 @@ public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, GetArtistRequ
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "ArtistNotFound",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
@@ -119,7 +112,7 @@ public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, GetArtistRequ
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
|
||||
+9
-7
@@ -1,9 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtistAlbums;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
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</c> route.
|
||||
/// </summary>
|
||||
public class GetArtistAlbumsEndpoint : BaseEndpoint<GetArtistAlbumsRequest, IResult>
|
||||
public class GetArtistAlbumsEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetArtistAlbumsQuery, Result<IReadOnlyList<AlbumResponse>>> _getArtistAlbumsQueryHandler;
|
||||
|
||||
@@ -44,13 +42,17 @@ public class GetArtistAlbumsEndpoint : BaseEndpoint<GetArtistAlbumsRequest, IRes
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of all the albums of the artist identified by <paramref name="request"/>.
|
||||
/// Gets the list of all the albums of the artist identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the id of the artist whose albums 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(GetArtistAlbumsRequest request, CancellationToken cancellationToken)
|
||||
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<IReadOnlyList<AlbumResponse>> result = await _getArtistAlbumsQueryHandler.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();
|
||||
GetArtistAlbumsQuery query = new(libraryId, artistId);
|
||||
Result<IReadOnlyList<AlbumResponse>> result = await _getArtistAlbumsQueryHandler.HandleAsync(query, cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+8
-15
@@ -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.Artists;
|
||||
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="GetArtistAlbumsEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, GetArtistAlbumsRequest>
|
||||
public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetArtistAlbumsEndpointSummary"/> class.
|
||||
@@ -28,13 +27,7 @@ public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, G
|
||||
public GetArtistAlbumsEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the list of albums of an artist.";
|
||||
Description = "Returns the full details of the albums of the artist identified by the request, with the full details of each album. The list is returned to an Admin, who can see the albums of the artists of all libraries, or to the owner of the library of the artist.";
|
||||
|
||||
ExampleRequest = new GetArtistAlbumsRequest(
|
||||
ArtistId: Guid.NewGuid()
|
||||
);
|
||||
|
||||
RequestParam(r => r.ArtistId, "The Id of the artist whose albums are retrieved, taken from the route. Required.");
|
||||
Description = "Returns the full details of the albums of the artist identified by the route, with the full details of each album. The list is returned to an Admin, who can see the albums of the artists of all libraries, or to the owner of the library of the artist.";
|
||||
|
||||
ResponseParam<AlbumResponse>(r => r.Id, "The Id of the album.");
|
||||
ResponseParam<AlbumResponse>(r => r.ArtistId, "The Id of the artist the album belongs to.");
|
||||
@@ -233,7 +226,7 @@ public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, G
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums"
|
||||
},
|
||||
new
|
||||
{
|
||||
@@ -241,7 +234,7 @@ public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, G
|
||||
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"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums"
|
||||
},
|
||||
new
|
||||
{
|
||||
@@ -249,7 +242,7 @@ public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, G
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums"
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -261,7 +254,7 @@ public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, G
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
@@ -273,7 +266,7 @@ public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, G
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "ArtistNotFound",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
@@ -285,7 +278,7 @@ public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, G
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
|
||||
+6
-3
@@ -44,13 +44,16 @@ public class GetArtistAlbumsLiteEndpoint : BaseEndpoint<GetArtistAlbumsLiteReque
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lightweight read models of all the albums of the artist identified by <paramref name="request"/>.
|
||||
/// Gets the lightweight read models of all the albums of the artist identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the id of the artist whose albums are retrieved.</param>
|
||||
/// <param name="request">The request containing the pagination options of the albums to be retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetArtistAlbumsLiteRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<PaginatedResponse<AlbumLiteResponse>> result = await _getArtistAlbumsLiteQueryHandler.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();
|
||||
Result<PaginatedResponse<AlbumLiteResponse>> result = await _getArtistAlbumsLiteQueryHandler.HandleAsync(request.ToQuery(libraryId, artistId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+6
-8
@@ -25,12 +25,10 @@ public class GetArtistAlbumsLiteEndpointSummary : Summary<GetArtistAlbumsLiteEnd
|
||||
Description = "Returns the lightweight read models of the albums of the artist identified by its Id, projecting only the fields needed to display the albums in a card-based grid, without loading the full album entities and their related data. The page is returned to an Admin, who can see the albums of the artists of all libraries, or to the owner of the library of the artist.";
|
||||
|
||||
ExampleRequest = new GetArtistAlbumsLiteRequest(
|
||||
ArtistId: Guid.NewGuid(),
|
||||
CurrentPage: 1,
|
||||
PerPage: 48
|
||||
);
|
||||
|
||||
RequestParam(r => r.ArtistId, "The Id of the artist whose albums are retrieved. Required.");
|
||||
RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional.");
|
||||
RequestParam(r => r.PerPage, "The maximum number of albums to retrieve per page. Optional.");
|
||||
|
||||
@@ -70,7 +68,7 @@ public class GetArtistAlbumsLiteEndpointSummary : Summary<GetArtistAlbumsLiteEnd
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/lite"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/lite"
|
||||
},
|
||||
new
|
||||
{
|
||||
@@ -78,7 +76,7 @@ public class GetArtistAlbumsLiteEndpointSummary : Summary<GetArtistAlbumsLiteEnd
|
||||
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/lite"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/lite"
|
||||
},
|
||||
new
|
||||
{
|
||||
@@ -86,7 +84,7 @@ public class GetArtistAlbumsLiteEndpointSummary : Summary<GetArtistAlbumsLiteEnd
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/lite"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/lite"
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -98,7 +96,7 @@ public class GetArtistAlbumsLiteEndpointSummary : Summary<GetArtistAlbumsLiteEnd
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/lite",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/lite",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
@@ -110,7 +108,7 @@ public class GetArtistAlbumsLiteEndpointSummary : Summary<GetArtistAlbumsLiteEnd
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "ArtistNotFound",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/lite",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/lite",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
@@ -122,7 +120,7 @@ public class GetArtistAlbumsLiteEndpointSummary : Summary<GetArtistAlbumsLiteEnd
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/lite",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/lite",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
|
||||
+5
-3
@@ -44,13 +44,15 @@ public class GetArtistsEndpoint : BaseEndpoint<GetArtistsRequest, IResult>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of all the artists of the media library identified by <paramref name="request"/>.
|
||||
/// Gets the list of all the artists of the media library identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Id of the media library whose artists are retrieved.</param>
|
||||
/// <param name="request">The request containing the pagination and filtering options of the artists to be retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetArtistsRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<PaginatedResponse<ArtistResponse>> result = await _getArtistsQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
// Take unique identifiers from the route.
|
||||
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
|
||||
Result<PaginatedResponse<ArtistResponse>> result = await _getArtistsQueryHandler.HandleAsync(request.ToQuery(libraryId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+5
-7
@@ -25,13 +25,11 @@ public class GetArtistsEndpointSummary : Summary<GetArtistsEndpoint, GetArtistsR
|
||||
Description = "Returns the paginated list of the artists of the media library identified by the request, with the full details of each artist. The page is returned to an Admin, who can see the artists of all libraries, or to the owner of the library.";
|
||||
|
||||
ExampleRequest = new GetArtistsRequest(
|
||||
LibraryId: Guid.NewGuid(),
|
||||
CurrentPage: 1,
|
||||
PerPage: 48,
|
||||
SearchTerm: "queen"
|
||||
);
|
||||
|
||||
RequestParam(r => r.LibraryId, "The Id of the media library whose artists are retrieved. Required.");
|
||||
RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional.");
|
||||
RequestParam(r => r.PerPage, "The maximum number of artists to retrieve per page. Optional.");
|
||||
RequestParam(r => r.SearchTerm, "The search term used to filter the artists by name. Optional.");
|
||||
@@ -90,7 +88,7 @@ public class GetArtistsEndpointSummary : Summary<GetArtistsEndpoint, GetArtistsR
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists"
|
||||
},
|
||||
new
|
||||
{
|
||||
@@ -98,7 +96,7 @@ public class GetArtistsEndpointSummary : Summary<GetArtistsEndpoint, GetArtistsR
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists"
|
||||
},
|
||||
new
|
||||
{
|
||||
@@ -106,7 +104,7 @@ public class GetArtistsEndpointSummary : Summary<GetArtistsEndpoint, GetArtistsR
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists"
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -118,7 +116,7 @@ public class GetArtistsEndpointSummary : Summary<GetArtistsEndpoint, GetArtistsR
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
@@ -130,7 +128,7 @@ public class GetArtistsEndpointSummary : Summary<GetArtistsEndpoint, GetArtistsR
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
|
||||
+5
-3
@@ -44,13 +44,15 @@ public class GetArtistsLiteEndpoint : BaseEndpoint<GetArtistsLiteRequest, IResul
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lightweight read models of all the artists of the media library identified by <paramref name="request"/>.
|
||||
/// Gets the lightweight read models of all the artists of the media library identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the Id of the media library whose artists are retrieved.</param>
|
||||
/// <param name="request">The request containing the pagination and filtering options of the artists to be retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetArtistsLiteRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<PaginatedResponse<ArtistLiteResponse>> result = await _getArtistsLiteQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
// Take unique identifiers from the route.
|
||||
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
|
||||
Result<PaginatedResponse<ArtistLiteResponse>> result = await _getArtistsLiteQueryHandler.HandleAsync(request.ToQuery(libraryId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+5
-7
@@ -25,13 +25,11 @@ public class GetArtistsLiteEndpointSummary : Summary<GetArtistsLiteEndpoint, Get
|
||||
Description = "Returns the lightweight read models of the artists of a media library, projecting only the fields needed to display the artists in a card-based grid, without loading the full artist entities and their related data. The page is returned to an Admin, who can see the artists of all libraries, or to the owner of the library.";
|
||||
|
||||
ExampleRequest = new GetArtistsLiteRequest(
|
||||
LibraryId: Guid.NewGuid(),
|
||||
CurrentPage: 1,
|
||||
PerPage: 48,
|
||||
SearchTerm: "queen"
|
||||
);
|
||||
|
||||
RequestParam(r => r.LibraryId, "The Id of the media library whose artists are retrieved. Required.");
|
||||
RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional.");
|
||||
RequestParam(r => r.PerPage, "The maximum number of artists to retrieve per page. Optional.");
|
||||
RequestParam(r => r.SearchTerm, "The search term used to filter the artists by name. Optional.");
|
||||
@@ -69,7 +67,7 @@ public class GetArtistsLiteEndpointSummary : Summary<GetArtistsLiteEndpoint, Get
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/lite"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/lite"
|
||||
},
|
||||
new
|
||||
{
|
||||
@@ -77,7 +75,7 @@ public class GetArtistsLiteEndpointSummary : Summary<GetArtistsLiteEndpoint, Get
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/lite"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/lite"
|
||||
},
|
||||
new
|
||||
{
|
||||
@@ -85,7 +83,7 @@ public class GetArtistsLiteEndpointSummary : Summary<GetArtistsLiteEndpoint, Get
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/lite"
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/lite"
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -97,7 +95,7 @@ public class GetArtistsLiteEndpointSummary : Summary<GetArtistsLiteEndpoint, Get
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/lite",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/lite",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
@@ -109,7 +107,7 @@ public class GetArtistsLiteEndpointSummary : Summary<GetArtistsLiteEndpoint, Get
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/libraries/{libraryId}/artists/lite",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/lite",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
|
||||
+33
-15
@@ -4,9 +4,7 @@ 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.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
@@ -39,6 +37,7 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
RequestParam(r => r.MusicBrainzArtistId, "The MusicBrainz identifier of the artist. Optional.");
|
||||
RequestParam(r => r.Contributors, "The list of media contributors that make up the artist. Required.");
|
||||
RequestParam(r => r.Albums, "The list of albums of the artist, each with its own list of tracks. Required.");
|
||||
RequestParam(r => r.Albums![0].AlbumId, "The Id of the album, when the album already exists. Optional.");
|
||||
RequestParam(r => r.Albums![0].Metadata, "The album metadata of the album. Required.");
|
||||
RequestParam(r => r.Albums![0].Metadata!.Title, "The title of the album. Required.");
|
||||
RequestParam(r => r.Albums![0].Metadata!.OriginalTitle, "The original title of the album, if different from the current title. Optional.");
|
||||
@@ -73,6 +72,7 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
RequestParam(r => r.Albums![0].Contributors, "The list of media contributors that performed on the album. Required.");
|
||||
RequestParam(r => r.Albums![0].Ratings, "The list of ratings for this album. Required.");
|
||||
RequestParam(r => r.Albums![0].Tracks, "The list of tracks of the album. Required.");
|
||||
RequestParam(r => r.Albums![0].Tracks![0].TrackId, "The Id of the track, when the track already exists. Optional.");
|
||||
RequestParam(r => r.Albums![0].Tracks![0].Path, "The file system path of the track. It must be inside one of the content locations of the media library that owns it. Required.");
|
||||
RequestParam(r => r.Albums![0].Tracks![0].Metadata, "The audio metadata of the track. Required.");
|
||||
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Title, "The title of the track. Required.");
|
||||
@@ -131,7 +131,8 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
)
|
||||
],
|
||||
Albums: [
|
||||
new AddAlbumRequest(
|
||||
new UpdateArtistAlbumRequest(
|
||||
AlbumId: Guid.NewGuid(),
|
||||
Metadata: new AlbumMetadataDto(
|
||||
Title: "A Night at the Opera",
|
||||
OriginalTitle: "A Night at the Opera",
|
||||
@@ -199,7 +200,8 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
)
|
||||
],
|
||||
Tracks: [
|
||||
new AddTrackRequest(
|
||||
new UpdateArtistTrackRequest(
|
||||
TrackId: Guid.NewGuid(),
|
||||
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
|
||||
Metadata: new AudioMetadataDto(
|
||||
Title: "Bohemian Rhapsody",
|
||||
@@ -280,7 +282,8 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
)
|
||||
]
|
||||
),
|
||||
new AddTrackRequest(
|
||||
new UpdateArtistTrackRequest(
|
||||
TrackId: Guid.NewGuid(),
|
||||
Path: "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac",
|
||||
Metadata: new AudioMetadataDto(
|
||||
Title: "You're My Best Friend",
|
||||
@@ -776,15 +779,27 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
}
|
||||
);
|
||||
|
||||
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 the update would leave the 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/{Guid.NewGuid()}/artists/{Guid.NewGuid()}",
|
||||
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()}",
|
||||
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()}",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -844,6 +859,7 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
"MediaContributorIdCannotBeEmpty",
|
||||
"UnknownMediaContributorRole",
|
||||
"AlbumsListCannotBeNull",
|
||||
"AlbumIdCannotBeEmpty",
|
||||
"MetadataCannotBeNull",
|
||||
"AlbumTitleCannotBeEmpty",
|
||||
"AlbumTitleMustBeMaximum255CharactersLong",
|
||||
@@ -876,12 +892,15 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
"LanguageNativeNameMustBeMaximum50CharactersLong",
|
||||
"UnknownMusicMediaFormat",
|
||||
"CatalogNumberMustBeMaximum50CharactersLong",
|
||||
"BarcodeValueCannotBeEmpty",
|
||||
"InvalidFormatForBarcode",
|
||||
"RatingsListCannotBeNull",
|
||||
"RatingValueMustBePositive",
|
||||
"RatingValueCannotBeGreaterThanMaxValue",
|
||||
"RatingMaxValueMustBePositive",
|
||||
"RatingVoteCountMustBePositive",
|
||||
"TracksListCannotBeNull",
|
||||
"TrackIdCannotBeEmpty",
|
||||
"TrackPathCannotBeEmpty",
|
||||
"TrackPathMustBeMaximum2048CharactersLong",
|
||||
"TrackNumberMustBeGreaterThanZero",
|
||||
@@ -891,8 +910,7 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
"BpmMustBeGreaterThanZero",
|
||||
"WorkMustBeMaximum255CharactersLong",
|
||||
"MoodNameCannotBeEmpty",
|
||||
"IsrcValueCannotBeEmpty",
|
||||
"ArtistMustHaveAtLeastOneAlbum"
|
||||
"IsrcValueCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user