mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17:11:10 +00:00
Extends the music library listings with covers, sorting and alpha filtering.
This commit is contained in:
1 parent
0019821e87
commit
9d82f283e4
69 files changed
+3613
-268
No files matched your search
+20
-1
@@ -8,11 +8,15 @@ using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwn
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
@@ -88,6 +92,21 @@ public class GetAlbumQueryHandler : IQueryHandler<GetAlbumQuery, Result<AlbumRes
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
return existingAlbum.ToResponse();
|
||||
// The artwork of an album is stored in the MusicArtwork table, not on the album row, so it is loaded to expose the cover
|
||||
// and every other stored piece of artwork.
|
||||
Result<IReadOnlyList<MusicArtworkEntity>> getArtworkResult = await _unitOfWork.MusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Album, albumId, cancellationToken).ConfigureAwait(false);
|
||||
if (getArtworkResult.IsFailure)
|
||||
return getArtworkResult.Errors;
|
||||
string? coverPath = getArtworkResult.Value
|
||||
.Where(artwork => artwork.ArtworkType == ArtworkType.Cover)
|
||||
.Select(artwork => artwork.FileName)
|
||||
.FirstOrDefault();
|
||||
|
||||
// Only the artwork whose file has already been stored can be presented, so the ones that are still pending resolution are left out.
|
||||
List<MediaArtworkDto> artwork = [.. getArtworkResult.Value
|
||||
.Where(storedArtwork => !string.IsNullOrWhiteSpace(storedArtwork.FileName))
|
||||
.Select(storedArtwork => new MediaArtworkDto(storedArtwork.ArtworkType, storedArtwork.Ordinal, storedArtwork.FileName!))];
|
||||
|
||||
return existingAlbum.ToResponse(coverPath, artwork);
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -11,8 +11,11 @@ using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.A
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
@@ -87,6 +90,15 @@ public class GetArtistQueryHandler : IQueryHandler<GetArtistQuery, Result<Artist
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
return existingArtist.ToResponse();
|
||||
// The artwork of the artist is stored separately from the artist, so it is loaded to expose the cover of the artist in the response.
|
||||
Result<IReadOnlyList<MusicArtworkEntity>> getArtworkResult = await _unitOfWork.MusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Artist, artistId, cancellationToken).ConfigureAwait(false);
|
||||
if (getArtworkResult.IsFailure)
|
||||
return getArtworkResult.Errors;
|
||||
string? coverPath = getArtworkResult.Value
|
||||
.Where(artwork => artwork.ArtworkType == ArtworkType.Cover)
|
||||
.Select(artwork => artwork.FileName)
|
||||
.FirstOrDefault();
|
||||
|
||||
return existingArtist.ToResponse(coverPath);
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -12,9 +13,17 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists
|
||||
/// <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>
|
||||
/// <param name="FilterAlphaKey">The alpha key used to filter the artists by the first character of their name.</param>
|
||||
/// <param name="ShouldIgnoreThePrefixForAlphaPicker">Whether the leading "The " prefix of a name should be ignored when computing the alpha key, or not.</param>
|
||||
/// <param name="SortBy">The name of the field by which to sort the results.</param>
|
||||
/// <param name="SortOrder">The direction in which to sort the results.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
public record GetArtistsLiteQuery(
|
||||
string? LibraryId,
|
||||
PaginationDataDto? PaginationData,
|
||||
string? SearchTerm
|
||||
string? SearchTerm,
|
||||
string? FilterAlphaKey,
|
||||
bool ShouldIgnoreThePrefixForAlphaPicker,
|
||||
string? SortBy,
|
||||
SortOrder? SortOrder
|
||||
) : IQuery;
|
||||
+6
-2
@@ -78,12 +78,16 @@ public class GetArtistsLiteQueryHandler : IQueryHandler<GetArtistsLiteQuery, Res
|
||||
LibraryFilterDto filter = new()
|
||||
{
|
||||
LibraryId = libraryId,
|
||||
SearchTerm = query.SearchTerm
|
||||
SearchTerm = query.SearchTerm,
|
||||
FilterAlphaKey = query.FilterAlphaKey,
|
||||
ShouldIgnoreThePrefixForAlphaPicker = query.ShouldIgnoreThePrefixForAlphaPicker
|
||||
};
|
||||
|
||||
Result<PaginatedResultDto<ArtistLiteRow>> getArtistsResult = await _unitOfWork.ArtistRepository.GetAllLiteAsync(
|
||||
query.PaginationData,
|
||||
filterModel: filter,
|
||||
query.SortBy,
|
||||
query.SortOrder,
|
||||
filter,
|
||||
cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return getArtistsResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
}
|
||||
|
||||
+10
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
@@ -26,5 +27,14 @@ public class GetArtistsLiteQueryValidator : AbstractValidator<GetArtistsLiteQuer
|
||||
.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);
|
||||
|
||||
// The alpha key must be exactly one of the three picker bucket kinds, so that the filter specification can
|
||||
// derive the key of a name unambiguously: no filter, a number bucket, a symbol bucket, or a single ASCII letter.
|
||||
RuleFor(query => query.FilterAlphaKey)
|
||||
.Must(alphaKey => alphaKey is null
|
||||
|| alphaKey == LibraryItemAlphaKeys.NUMBER
|
||||
|| alphaKey == LibraryItemAlphaKeys.SYMBOL
|
||||
|| (alphaKey.Length == 1 && char.IsAsciiLetter(alphaKey[0])))
|
||||
.WithError(Errors.Library.InvalidFilterAlphaKey);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user