From 9d82f283e4831294a56fe86e96a499b83d1651c6 Mon Sep 17 00:00:00 2001 From: Binary Alley Date: Tue, 13 Oct 2026 13:26:14 +0300 Subject: [PATCH] Extends the music library listings with covers, sorting and alpha filtering. --- .../audio-library/music-library/Api.Albums.md | 664 +++++++++++-- .../music-library/Api.Artists.md | 929 +++++++++++++++--- .../audio-library/music-library/Api.Tracks.md | 40 +- .../music-library/artists/GetArtistsLite.http | 2 +- .../MusicLibrary/Albums/AlbumLiteRow.cs | 17 + .../MusicLibrary/Artists/ArtistLiteRow.cs | 5 + .../MusicLibrary/Tracks/TrackLiteRow.cs | 5 + .../MusicLibrary/Albums/AlbumEntityMapping.cs | 8 +- .../Albums/AlbumLiteRowMapping.cs | 5 +- .../Artists/ArtistEntityMapping.cs | 6 +- .../Artists/ArtistLiteRowMapping.cs | 3 +- .../Artists/GetArtistsLiteRequestMapping.cs | 6 +- .../Tracks/TrackLiteRowMapping.cs | 3 +- .../Queries/GetAlbum/GetAlbumQueryHandler.cs | 21 +- .../GetArtist/GetArtistQueryHandler.cs | 14 +- .../GetArtistsLite/GetArtistsLiteQuery.cs | 11 +- .../GetArtistsLiteQueryHandler.cs | 8 +- .../GetArtistsLiteQueryValidator.cs | 10 + .../DTO/Common/MediaArtworkDto.cs | 19 + .../Artists/GetArtistsLiteRequest.cs | 15 +- .../MusicLibrary/Albums/AlbumLiteResponse.cs | 10 +- .../MusicLibrary/Albums/AlbumResponse.cs | 7 +- .../Artists/ArtistLiteResponse.cs | 4 +- .../MusicLibrary/Artists/ArtistResponse.cs | 4 +- .../MusicLibrary/Tracks/TrackLiteResponse.cs | 4 +- .../MusicLibrary/AlbumRepository.cs | 10 +- .../MusicLibrary/ArtistRepository.cs | 85 +- .../ArtistAlphaFilterSpecification.cs | 127 +++ .../MusicLibrary/TrackRepository.cs | 7 +- .../AddAlbum/AddAlbumEndpointSummary.cs | 2 + .../UpdateAlbum/UpdateAlbumEndpointSummary.cs | 2 + .../AddArtist/AddArtistEndpointSummary.cs | 3 + .../GetArtist/GetArtistEndpointSummary.cs | 1 + .../GetArtistAlbumsEndpointSummary.cs | 2 + .../GetArtistAlbumsLiteEndpointSummary.cs | 3 + .../GetArtists/GetArtistsEndpointSummary.cs | 1 + .../GetArtistsLiteEndpointSummary.cs | 3 +- .../UpdateArtistEndpointSummary.cs | 3 + .../Albums/AlbumLiteRowFixture.cs | 23 +- .../Artists/ArtistLiteRowFixture.cs | 9 +- .../Tracks/TrackLiteRowFixture.cs | 7 +- .../GetArtistsLiteQueryFixture.cs | 15 +- .../Core/DTO/Common/MediaArtworkDtoFixture.cs | 47 + .../Artists/GetArtistsLiteRequestFixture.cs | 34 +- .../Albums/AlbumLiteResponseFixture.cs | 24 +- .../Albums/AlbumResponseFixture.cs | 21 +- .../Artists/ArtistLiteResponseFixture.cs | 9 +- .../Artists/ArtistResponseFixture.cs | 9 +- .../Tracks/TrackLiteResponseFixture.cs | 7 +- .../MusicLibrary/AlbumRepositoryTests.cs | 108 ++ .../MusicLibrary/ArtistRepositoryTests.cs | 253 +++++ .../ArtistAlphaFilterSpecificationTests.cs | 235 +++++ .../MusicLibrary/TrackRepositoryTests.cs | 84 +- .../GetAlbumTracksLiteEndpointTests.cs | 1 + .../GetArtistAlbumsLiteEndpointTests.cs | 6 +- .../GetArtistsLiteEndpointTests.cs | 149 +++ .../Albums/AlbumEntityMappingTests.cs | 17 + .../Albums/AlbumLiteRowMappingTests.cs | 6 + .../Artists/ArtistEntityMappingTests.cs | 17 + .../Artists/ArtistLiteRowMappingTests.cs | 2 + .../GetArtistsLiteRequestMappingTests.cs | 21 + .../Tracks/TrackLiteRowMappingTests.cs | 1 + .../GetAlbum/GetAlbumQueryHandlerTests.cs | 133 ++- .../GetArtist/GetArtistQueryHandlerTests.cs | 104 +- .../GetArtistsLiteQueryHandlerTests.cs | 37 + .../GetArtistsLiteQueryValidatorTests.cs | 152 +++ .../MusicLibrary/AlbumRepositoryTests.cs | 107 ++ .../MusicLibrary/ArtistRepositoryTests.cs | 109 ++ .../MusicLibrary/TrackRepositoryTests.cs | 65 +- 69 files changed, 3613 insertions(+), 268 deletions(-) create mode 100644 src/Lumina.Contracts/DTO/Common/MediaArtworkDto.cs create mode 100644 src/Lumina.DataAccess/Core/Repositories/MusicLibrary/Specifications/ArtistAlphaFilterSpecification.cs create mode 100644 tests/Common/Lumina.Contracts.Fixtures/Core/DTO/Common/MediaArtworkDtoFixture.cs create mode 100644 tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/Specifications/ArtistAlphaFilterSpecificationTests.cs diff --git a/docs/technical/api/library/audio-library/music-library/Api.Albums.md b/docs/technical/api/library/audio-library/music-library/Api.Albums.md index 21459643..cbe5d852 100644 --- a/docs/technical/api/library/audio-library/music-library/Api.Albums.md +++ b/docs/technical/api/library/audio-library/music-library/Api.Albums.md @@ -17,6 +17,9 @@ - [Update Album](#update-album) - [Update Album Request](#update-album-request) - [Update Album Response](#update-album-response) + - [Update Album Cover](#update-album-cover) + - [Update Album Cover Request](#update-album-cover-request) + - [Update Album Cover Response](#update-album-cover-response) - [Delete Album](#delete-album) - [Get Album Tracks](#get-album-tracks) - [Get Album Tracks Request](#get-album-tracks-request) @@ -41,12 +44,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "title": "A Night at the Opera", "originalTitle": "A Night at the Opera", "description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.", - "disambiguation": null, + "disambiguation": "original release", "releaseInfo": { "originalReleaseDate": "1975-11-21", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Remastered" }, @@ -109,12 +112,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "title": "Bohemian Rhapsody", "originalTitle": "Bohemian Rhapsody", "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", - "disambiguation": null, + "disambiguation": "album version", "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, @@ -161,7 +164,7 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", @@ -197,12 +200,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "title": "You're My Best Friend", "originalTitle": "You're My Best Friend", "description": "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.", - "disambiguation": null, + "disambiguation": "album version", "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, @@ -231,11 +234,11 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "bitDepth": 16, "audioCodec": "FLAC", "bitrate": 912, - "acoustId": null, - "replayGainTrackGain": null, - "replayGainTrackPeak": null, - "replayGainAlbumGain": null, - "replayGainAlbumPeak": null + "acoustId": "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d", + "replayGainTrackGain": -7.2, + "replayGainTrackPeak": 0.9812, + "replayGainAlbumGain": -6.5, + "replayGainAlbumPeak": 0.9987 }, "trackNumber": 7, "discNumber": 1, @@ -249,7 +252,7 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "0f3e4d5c-6b7a-4f8e-9d0c-1b2a3c4d5e6f", "musicBrainzTrackId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", @@ -298,12 +301,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "title": "A Night at the Opera", "originalTitle": "A Night at the Opera", "description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.", - "disambiguation": null, + "disambiguation": "original release", "releaseInfo": { "originalReleaseDate": "1975-11-21", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Remastered" }, @@ -342,7 +345,7 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "musicBrainzReleaseGroupId": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e", "musicBrainzReleaseArtistId": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "contributors": [ { "contributorId": "0e7b4a6c-5f8d-6b9e-ca0b-3c4d5e6f7a8b", @@ -377,8 +380,8 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "title": "Bohemian Rhapsody", "originalTitle": "Bohemian Rhapsody", "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", - "disambiguation": null, - "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": null, "reReleaseYear": null, "releaseCountry": "GB", "releaseVersion": "Original" }, + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "tags": [ { "name": "classic" }, { "name": "epic" } ], @@ -408,12 +411,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "moods": [ { "name": "dramatic" }, { "name": "anxious" } @@ -455,8 +458,8 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "title": "You're My Best Friend", "originalTitle": "You're My Best Friend", "description": "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.", - "disambiguation": null, - "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, "reReleaseDate": null, "reReleaseYear": null, "releaseCountry": "GB", "releaseVersion": "Original" }, + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "tags": [ { "name": "classic" }, { "name": "love" } ], @@ -468,11 +471,11 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "bitDepth": 16, "audioCodec": "FLAC", "bitrate": 912, - "acoustId": null, - "replayGainTrackGain": null, - "replayGainTrackPeak": null, - "replayGainAlbumGain": null, - "replayGainAlbumPeak": null + "acoustId": "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d", + "replayGainTrackGain": -7.2, + "replayGainTrackPeak": 0.9812, + "replayGainAlbumGain": -6.5, + "replayGainAlbumPeak": 0.9987 }, "trackNumber": 7, "discNumber": 1, @@ -486,12 +489,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "0f3e4d5c-6b7a-4f8e-9d0c-1b2a3c4d5e6f", "musicBrainzTrackId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "moods": [ { "name": "happy" }, { "name": "warm" } @@ -524,6 +527,14 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b } ] } + ], + "coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg", + "artwork": [ + { + "type": "Cover", + "ordinal": 0, + "path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg" + } ] } ``` @@ -553,12 +564,12 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "title": "A Night at the Opera", "originalTitle": "A Night at the Opera", "description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.", - "disambiguation": null, + "disambiguation": "original release", "releaseInfo": { "originalReleaseDate": "1975-11-21", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Remastered" }, @@ -597,7 +608,7 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "musicBrainzReleaseGroupId": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e", "musicBrainzReleaseArtistId": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "contributors": [ { "contributorId": "0e7b4a6c-5f8d-6b9e-ca0b-3c4d5e6f7a8b", @@ -622,7 +633,172 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "voteCount": 1234 } ], - "tracks": [] + "tracks": [ + { + "id": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f", + "albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac", + "metadata": { + "title": "Bohemian Rhapsody", + "originalTitle": "Bohemian Rhapsody", + "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, + "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "tags": [ { "name": "classic" }, { "name": "epic" } ], + "genres": [ { "name": "Rock" }, { "name": "Progressive Rock" } ], + "isVideo": false, + "durationInSeconds": 354, + "sampleRate": 44100, + "channels": 2, + "bitDepth": 16, + "audioCodec": "FLAC", + "bitrate": 980, + "acoustId": "f0e1d2c3-b4a5-4c6d-8e7f-9a0b1c2d3e4f", + "replayGainTrackGain": -7.5, + "replayGainTrackPeak": 0.9877, + "replayGainAlbumGain": -6.8, + "replayGainAlbumPeak": 0.9999 + }, + "trackNumber": 1, + "discNumber": 1, + "script": "Latn", + "key": "CMajor", + "bpm": 72, + "work": { + "musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c", + "title": "Bohemian Rhapsody", + "type": "Song", + "languages": [ + { "languageCode": "en", "languageName": "English", "nativeName": "English" } + ], + "iswcs": ["T-010489707-6"] + }, + "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", + "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "moods": [ + { "name": "dramatic" }, + { "name": "anxious" } + ], + "isrcs": [ + { "value": "GBUM71029604" } + ], + "contributors": [ + { + "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", + "role": "Vocals" + }, + { + "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", + "role": "Guitar" + } + ], + "ratings": [ + { + "value": 4.5, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 2345 + }, + { + "value": 4.8, + "maxValue": 5, + "source": "LastFm", + "voteCount": 1234 + } + ] + }, + { + "id": "8e1f2a3b-4c5d-4e6f-8a9b-0c1d2e3f4a5b", + "albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "path": "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac", + "metadata": { + "title": "You're My Best Friend", + "originalTitle": "You're My Best Friend", + "description": "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.", + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, + "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "tags": [ { "name": "classic" }, { "name": "love" } ], + "genres": [ { "name": "Rock" }, { "name": "Pop Rock" } ], + "isVideo": false, + "durationInSeconds": 181, + "sampleRate": 44100, + "channels": 2, + "bitDepth": 16, + "audioCodec": "FLAC", + "bitrate": 912, + "acoustId": "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d", + "replayGainTrackGain": -7.2, + "replayGainTrackPeak": 0.9812, + "replayGainAlbumGain": -6.5, + "replayGainAlbumPeak": 0.9987 + }, + "trackNumber": 7, + "discNumber": 1, + "script": "Latn", + "key": "BMajor", + "bpm": 118, + "work": { + "musicBrainzWorkId": "2b3c4d5e-6f7a-4b8c-9d0e-1f2a3b4c5d6e", + "title": "You're My Best Friend", + "type": "Song", + "languages": [ + { "languageCode": "en", "languageName": "English", "nativeName": "English" } + ], + "iswcs": ["T-010489707-6"] + }, + "musicBrainzRecordingId": "0f3e4d5c-6b7a-4f8e-9d0c-1b2a3c4d5e6f", + "musicBrainzTrackId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "moods": [ + { "name": "happy" }, + { "name": "warm" } + ], + "isrcs": [ + { "value": "GBUM71029609" } + ], + "contributors": [ + { + "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", + "role": "Vocals" + }, + { + "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", + "role": "Guitar" + } + ], + "ratings": [ + { + "value": 4.2, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 1234 + }, + { + "value": 4.4, + "maxValue": 5, + "source": "LastFm", + "voteCount": 567 + } + ] + } + ], + "coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg", + "artwork": [ + { + "type": "Cover", + "ordinal": 0, + "path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg" + } + ] } ] ``` @@ -653,7 +829,10 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- { "id": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", "title": "A Night at the Opera", - "totalTracks": 12 + "totalTracks": 12, + "coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg", + "releaseYear": 1975, + "releaseTypes": [ "Album" ] } ], "currentPage": 1, @@ -687,12 +866,12 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "title": "A Night at the Opera", "originalTitle": "A Night at the Opera", "description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.", - "disambiguation": null, + "disambiguation": "original release", "releaseInfo": { "originalReleaseDate": "1975-11-21", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Remastered" }, @@ -731,7 +910,7 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "musicBrainzReleaseGroupId": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e", "musicBrainzReleaseArtistId": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "contributors": [ { "contributorId": "0e7b4a6c-5f8d-6b9e-ca0b-3c4d5e6f7a8b", @@ -756,7 +935,182 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "voteCount": 1234 } ], - "tracks": [] + "tracks": [ + { + "id": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f", + "albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac", + "metadata": { + "title": "Bohemian Rhapsody", + "originalTitle": "Bohemian Rhapsody", + "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, + "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "tags": [ { "name": "classic" }, { "name": "epic" } ], + "genres": [ { "name": "Rock" }, { "name": "Progressive Rock" } ], + "isVideo": false, + "durationInSeconds": 354, + "sampleRate": 44100, + "channels": 2, + "bitDepth": 16, + "audioCodec": "FLAC", + "bitrate": 980, + "acoustId": "f0e1d2c3-b4a5-4c6d-8e7f-9a0b1c2d3e4f", + "replayGainTrackGain": -7.5, + "replayGainTrackPeak": 0.9877, + "replayGainAlbumGain": -6.8, + "replayGainAlbumPeak": 0.9999 + }, + "trackNumber": 1, + "discNumber": 1, + "script": "Latn", + "key": "CMajor", + "bpm": 72, + "work": { + "musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c", + "title": "Bohemian Rhapsody", + "type": "Song", + "languages": [ + { "languageCode": "en", "languageName": "English", "nativeName": "English" } + ], + "iswcs": ["T-010489707-6"] + }, + "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", + "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "moods": [ + { "name": "dramatic" }, + { "name": "anxious" } + ], + "isrcs": [ + { "value": "GBUM71029604" } + ], + "contributors": [ + { + "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", + "role": "Vocals" + }, + { + "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", + "role": "Guitar" + } + ], + "ratings": [ + { + "value": 4.5, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 2345 + }, + { + "value": 4.8, + "maxValue": 5, + "source": "LastFm", + "voteCount": 1234 + } + ] + }, + { + "id": "8e1f2a3b-4c5d-4e6f-8a9b-0c1d2e3f4a5b", + "albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "path": "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac", + "metadata": { + "title": "You're My Best Friend", + "originalTitle": "You're My Best Friend", + "description": "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.", + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, + "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "tags": [ { "name": "classic" }, { "name": "love" } ], + "genres": [ { "name": "Rock" }, { "name": "Pop Rock" } ], + "isVideo": false, + "durationInSeconds": 181, + "sampleRate": 44100, + "channels": 2, + "bitDepth": 16, + "audioCodec": "FLAC", + "bitrate": 912, + "acoustId": "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d", + "replayGainTrackGain": -7.2, + "replayGainTrackPeak": 0.9812, + "replayGainAlbumGain": -6.5, + "replayGainAlbumPeak": 0.9987 + }, + "trackNumber": 7, + "discNumber": 1, + "script": "Latn", + "key": "BMajor", + "bpm": 118, + "work": { + "musicBrainzWorkId": "2b3c4d5e-6f7a-4b8c-9d0e-1f2a3b4c5d6e", + "title": "You're My Best Friend", + "type": "Song", + "languages": [ + { "languageCode": "en", "languageName": "English", "nativeName": "English" } + ], + "iswcs": ["T-010489707-6"] + }, + "musicBrainzRecordingId": "0f3e4d5c-6b7a-4f8e-9d0c-1b2a3c4d5e6f", + "musicBrainzTrackId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "moods": [ + { "name": "happy" }, + { "name": "warm" } + ], + "isrcs": [ + { "value": "GBUM71029609" } + ], + "contributors": [ + { + "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", + "role": "Vocals" + }, + { + "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", + "role": "Guitar" + } + ], + "ratings": [ + { + "value": 4.2, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 1234 + }, + { + "value": 4.4, + "maxValue": 5, + "source": "LastFm", + "voteCount": 567 + } + ] + } + ], + "coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg", + "artwork": [ + { + "type": "Cover", + "ordinal": 0, + "path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg" + }, + { + "type": "Back", + "ordinal": 0, + "path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/back.jpg" + }, + { + "type": "Booklet", + "ordinal": 0, + "path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/booklet.jpg" + } + ] } ``` @@ -775,12 +1129,12 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "title": "A Night at the Opera", "originalTitle": "A Night at the Opera", "description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.", - "disambiguation": null, + "disambiguation": "original release", "releaseInfo": { "originalReleaseDate": "1975-11-21", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Remastered" }, @@ -854,12 +1208,12 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "title": "A Night at the Opera", "originalTitle": "A Night at the Opera", "description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.", - "disambiguation": null, + "disambiguation": "original release", "releaseInfo": { "originalReleaseDate": "1975-11-21", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Remastered" }, @@ -898,7 +1252,7 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "musicBrainzReleaseGroupId": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e", "musicBrainzReleaseArtistId": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "contributors": [ { "contributorId": "0e7b4a6c-5f8d-6b9e-ca0b-3c4d5e6f7a8b", @@ -923,7 +1277,202 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "voteCount": 1234 } ], - "tracks": [] + "tracks": [ + { + "id": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f", + "albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac", + "metadata": { + "title": "Bohemian Rhapsody", + "originalTitle": "Bohemian Rhapsody", + "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, + "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "tags": [ { "name": "classic" }, { "name": "epic" } ], + "genres": [ { "name": "Rock" }, { "name": "Progressive Rock" } ], + "isVideo": false, + "durationInSeconds": 354, + "sampleRate": 44100, + "channels": 2, + "bitDepth": 16, + "audioCodec": "FLAC", + "bitrate": 980, + "acoustId": "f0e1d2c3-b4a5-4c6d-8e7f-9a0b1c2d3e4f", + "replayGainTrackGain": -7.5, + "replayGainTrackPeak": 0.9877, + "replayGainAlbumGain": -6.8, + "replayGainAlbumPeak": 0.9999 + }, + "trackNumber": 1, + "discNumber": 1, + "script": "Latn", + "key": "CMajor", + "bpm": 72, + "work": { + "musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c", + "title": "Bohemian Rhapsody", + "type": "Song", + "languages": [ + { "languageCode": "en", "languageName": "English", "nativeName": "English" } + ], + "iswcs": ["T-010489707-6"] + }, + "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", + "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "moods": [ + { "name": "dramatic" }, + { "name": "anxious" } + ], + "isrcs": [ + { "value": "GBUM71029604" } + ], + "contributors": [ + { + "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", + "role": "Vocals" + }, + { + "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", + "role": "Guitar" + } + ], + "ratings": [ + { + "value": 4.5, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 2345 + }, + { + "value": 4.8, + "maxValue": 5, + "source": "LastFm", + "voteCount": 1234 + } + ] + }, + { + "id": "8e1f2a3b-4c5d-4e6f-8a9b-0c1d2e3f4a5b", + "albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "path": "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac", + "metadata": { + "title": "You're My Best Friend", + "originalTitle": "You're My Best Friend", + "description": "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.", + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, + "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "tags": [ { "name": "classic" }, { "name": "love" } ], + "genres": [ { "name": "Rock" }, { "name": "Pop Rock" } ], + "isVideo": false, + "durationInSeconds": 181, + "sampleRate": 44100, + "channels": 2, + "bitDepth": 16, + "audioCodec": "FLAC", + "bitrate": 912, + "acoustId": "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d", + "replayGainTrackGain": -7.2, + "replayGainTrackPeak": 0.9812, + "replayGainAlbumGain": -6.5, + "replayGainAlbumPeak": 0.9987 + }, + "trackNumber": 7, + "discNumber": 1, + "script": "Latn", + "key": "BMajor", + "bpm": 118, + "work": { + "musicBrainzWorkId": "2b3c4d5e-6f7a-4b8c-9d0e-1f2a3b4c5d6e", + "title": "You're My Best Friend", + "type": "Song", + "languages": [ + { "languageCode": "en", "languageName": "English", "nativeName": "English" } + ], + "iswcs": ["T-010489707-6"] + }, + "musicBrainzRecordingId": "0f3e4d5c-6b7a-4f8e-9d0c-1b2a3c4d5e6f", + "musicBrainzTrackId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "moods": [ + { "name": "happy" }, + { "name": "warm" } + ], + "isrcs": [ + { "value": "GBUM71029609" } + ], + "contributors": [ + { + "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", + "role": "Vocals" + }, + { + "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", + "role": "Guitar" + } + ], + "ratings": [ + { + "value": 4.2, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 1234 + }, + { + "value": 4.4, + "maxValue": 5, + "source": "LastFm", + "voteCount": 567 + } + ] + } + ], + "coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg", + "artwork": [ + { + "type": "Cover", + "ordinal": 0, + "path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg" + } + ] +} +``` + +### Update Album Cover + +Updates the cover image of the album identified by `albumId` with the image uploaded in the multipart form of the request. The album must belong to the artist identified by `artistId` and to the media library identified by `libraryId`, and the uploaded file must be an image. + +#### Update Album Cover Request + +```js +PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/{albumId}/cover +Content-Type: multipart/form-data; boundary=LuminaBoundary + +--LuminaBoundary +Content-Disposition: form-data; name="cover"; filename="cover.jpg" +Content-Type: image/jpeg + +< ./cover.jpg +--LuminaBoundary-- +``` + +#### Update Album Cover Response + +```js +200 Ok +``` + +```json +{ + "coverPath": "/media/music/music-3f2504e0-4f89-41d3-9a0c-0305e82c3301/Queen-2b0e5f5a-0b3f-4b7e-8f4a-8c9e3d2f5a6b/A Night at the Opera-7c1d2e3f-4a5b-6c7d-8e9f-0a1b2c3d4e5f/cover.jpg" } ``` @@ -966,8 +1515,8 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "title": "Bohemian Rhapsody", "originalTitle": "Bohemian Rhapsody", "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", - "disambiguation": null, - "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": null, "reReleaseYear": null, "releaseCountry": "GB", "releaseVersion": "Original" }, + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "tags": [ { "name": "classic" }, { "name": "epic" } ], @@ -997,12 +1546,12 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "moods": [ { "name": "dramatic" @@ -1071,7 +1620,8 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "id": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f", "title": "Bohemian Rhapsody", "trackNumber": 1, - "discNumber": 1 + "discNumber": 1, + "durationInSeconds": 354 } ], "currentPage": 1, diff --git a/docs/technical/api/library/audio-library/music-library/Api.Artists.md b/docs/technical/api/library/audio-library/music-library/Api.Artists.md index 5f37a0bb..3a5fe443 100644 --- a/docs/technical/api/library/audio-library/music-library/Api.Artists.md +++ b/docs/technical/api/library/audio-library/music-library/Api.Artists.md @@ -17,6 +17,9 @@ - [Update Artist](#update-artist) - [Update Artist Request](#update-artist-request) - [Update Artist Response](#update-artist-response) + - [Update Artist Cover](#update-artist-cover) + - [Update Artist Cover Request](#update-artist-cover-request) + - [Update Artist Cover Response](#update-artist-cover-response) - [Delete Artist](#delete-artist) ## Artist @@ -34,22 +37,36 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "metadata": { "name": "Queen", "sortName": "Queen", - "disambiguation": null, + "disambiguation": "British rock band", "type": "Group", - "gender": null, + "gender": "NotApplicable", "country": "GB", "area": { "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", "name": "United Kingdom", "sortName": "United Kingdom", - "disambiguation": null, + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, + "beginArea": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, + "endArea": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", "type": "Country", "iso3166Code": "GB" }, - "beginArea": null, - "endArea": null, "lifeSpanBegin": "1970-06-27", - "lifeSpanEnd": null, + "lifeSpanEnd": "1991-11-24", "isEnded": false, "genres": [ { "name": "Rock" } @@ -65,15 +82,15 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "locale": "en", "isPrimary": true, "beginDate": "1970-06-27", - "endDate": null, + "endDate": "1991-11-24", "isEnded": false } ] }, "website": "https://www.queenonline.com", "musicBrainzArtistId": "6f9c0b2a-1d3e-4a5b-8c7d-9e0f1a2b3c4d", - "ipis": [], - "isnis": [], + "ipis": ["00012345678"], + "isnis": ["0000000123456789"], "contributors": [ { "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", "role": "Vocals" }, { "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", "role": "Guitar" } @@ -92,12 +109,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "title": "A Night at the Opera", "originalTitle": "A Night at the Opera", "description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.", - "disambiguation": null, + "disambiguation": "original release", "releaseInfo": { "originalReleaseDate": "1975-11-21", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Remastered" }, @@ -160,12 +177,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "title": "Bohemian Rhapsody", "originalTitle": "Bohemian Rhapsody", "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", - "disambiguation": null, + "disambiguation": "album version", "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, @@ -212,7 +229,7 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", @@ -248,12 +265,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "title": "You're My Best Friend", "originalTitle": "You're My Best Friend", "description": "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.", - "disambiguation": null, + "disambiguation": "album version", "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, @@ -282,11 +299,11 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "bitDepth": 16, "audioCodec": "FLAC", "bitrate": 912, - "acoustId": null, - "replayGainTrackGain": null, - "replayGainTrackPeak": null, - "replayGainAlbumGain": null, - "replayGainAlbumPeak": null + "acoustId": "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d", + "replayGainTrackGain": -7.2, + "replayGainTrackPeak": 0.9812, + "replayGainAlbumGain": -6.5, + "replayGainAlbumPeak": 0.9987 }, "trackNumber": 7, "discNumber": 1, @@ -300,7 +317,7 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "0f3e4d5c-6b7a-4f8e-9d0c-1b2a3c4d5e6f", "musicBrainzTrackId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", @@ -349,22 +366,36 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "metadata": { "name": "Queen", "sortName": "Queen", - "disambiguation": null, + "disambiguation": "British rock band", "type": "Group", - "gender": null, + "gender": "NotApplicable", "country": "GB", "area": { "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", "name": "United Kingdom", "sortName": "United Kingdom", - "disambiguation": null, + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, + "beginArea": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, + "endArea": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", "type": "Country", "iso3166Code": "GB" }, - "beginArea": null, - "endArea": null, "lifeSpanBegin": "1970-06-27", - "lifeSpanEnd": null, + "lifeSpanEnd": "1991-11-24", "isEnded": false, "genres": [ { "name": "Rock" } @@ -380,17 +411,17 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "locale": "en", "isPrimary": true, "beginDate": "1970-06-27", - "endDate": null, + "endDate": "1991-11-24", "isEnded": false } ] }, "website": "https://www.queenonline.com", "musicBrainzArtistId": "6f9c0b2a-1d3e-4a5b-8c7d-9e0f1a2b3c4d", - "ipis": [], - "isnis": [], + "ipis": ["00012345678"], + "isnis": ["0000000123456789"], "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "contributors": [ { "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", "role": "Vocals" }, { "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", "role": "Guitar" } @@ -412,12 +443,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "title": "A Night at the Opera", "originalTitle": "A Night at the Opera", "description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.", - "disambiguation": null, + "disambiguation": "original release", "releaseInfo": { "originalReleaseDate": "1975-11-21", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Remastered" }, @@ -456,7 +487,7 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "musicBrainzReleaseGroupId": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e", "musicBrainzReleaseArtistId": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "contributors": [ { "contributorId": "0e7b4a6c-5f8d-6b9e-ca0b-3c4d5e6f7a8b", @@ -491,8 +522,8 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "title": "Bohemian Rhapsody", "originalTitle": "Bohemian Rhapsody", "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", - "disambiguation": null, - "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": null, "reReleaseYear": null, "releaseCountry": "GB", "releaseVersion": "Original" }, + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "tags": [ { "name": "classic" }, { "name": "epic" } ], @@ -522,12 +553,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "moods": [ { "name": "dramatic" }, { "name": "anxious" } @@ -569,8 +600,8 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "title": "You're My Best Friend", "originalTitle": "You're My Best Friend", "description": "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.", - "disambiguation": null, - "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, "reReleaseDate": null, "reReleaseYear": null, "releaseCountry": "GB", "releaseVersion": "Original" }, + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "tags": [ { "name": "classic" }, { "name": "love" } ], @@ -582,11 +613,11 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "bitDepth": 16, "audioCodec": "FLAC", "bitrate": 912, - "acoustId": null, - "replayGainTrackGain": null, - "replayGainTrackPeak": null, - "replayGainAlbumGain": null, - "replayGainAlbumPeak": null + "acoustId": "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d", + "replayGainTrackGain": -7.2, + "replayGainTrackPeak": 0.9812, + "replayGainAlbumGain": -6.5, + "replayGainAlbumPeak": 0.9987 }, "trackNumber": 7, "discNumber": 1, @@ -600,12 +631,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "0f3e4d5c-6b7a-4f8e-9d0c-1b2a3c4d5e6f", "musicBrainzTrackId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "moods": [ { "name": "happy" }, { "name": "warm" } @@ -638,9 +669,18 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists } ] } + ], + "coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg", + "artwork": [ + { + "type": "Cover", + "ordinal": 0, + "path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg" + } ] } - ] + ], + "coverPath": "/media/music/Queen-3b3a19f3/cover.jpg" } ``` @@ -674,29 +714,320 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists?currentPage=1& "metadata": { "name": "Queen", "sortName": "Queen", - "disambiguation": null, + "disambiguation": "British rock band", "type": "Group", - "gender": null, + "gender": "NotApplicable", "country": "GB", - "area": null, - "beginArea": null, - "endArea": null, + "area": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, + "beginArea": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, + "endArea": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, "lifeSpanBegin": "1970-06-27", - "lifeSpanEnd": null, + "lifeSpanEnd": "1991-11-24", "isEnded": false, - "genres": [], - "tags": [], - "aliases": [] + "genres": [ + { "name": "Rock" } + ], + "tags": [ + { "name": "classic" } + ], + "aliases": [ + { + "name": "The Queen", + "sortName": "Queen", + "type": "Artist name", + "locale": "en", + "isPrimary": false, + "beginDate": "1970-06-27", + "endDate": "1991-11-24", + "isEnded": true + } + ] }, "website": "https://www.queenonline.com", "musicBrainzArtistId": "6f9c0b2a-1d3e-4a5b-8c7d-9e0f1a2b3c4d", - "ipis": [], - "isnis": [], + "ipis": ["00012345678"], + "isnis": ["0000000123456789"], "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, - "contributors": [], - "ratings": [], - "albums": [] + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "contributors": [ + { "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", "role": "Vocals" } + ], + "ratings": [ + { + "value": 4.5, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 2345 + } + ], + "albums": [ + { + "id": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "artistId": "d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "metadata": { + "title": "A Night at the Opera", + "originalTitle": "A Night at the Opera", + "description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.", + "disambiguation": "original release", + "releaseInfo": { + "originalReleaseDate": "1975-11-21", + "originalReleaseYear": 1975, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, + "releaseCountry": "GB", + "releaseVersion": "Remastered" + }, + "language": { + "languageCode": "en", + "languageName": "English", + "nativeName": "English" + }, + "originalLanguage": { + "languageCode": "en", + "languageName": "English", + "nativeName": "English" + }, + "tags": [ + { "name": "classic" }, + { "name": "vinyl" } + ], + "genres": [ + { "name": "Rock" }, + { "name": "Progressive Rock" } + ], + "script": "Latn", + "releaseTypes": [ "Album" ], + "releaseStatus": "Official", + "totalDiscs": 1, + "totalTracks": 12, + "releaseTitle": "A Night at the Opera" + }, + "mediaFormat": "CD", + "packaging": "JewelCase", + "barcode": "0042282778329", + "catalogNumbers": ["EMC 4008"], + "label": "EMI", + "asin": "B000000000", + "musicBrainzReleaseId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d", + "musicBrainzReleaseGroupId": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e", + "musicBrainzReleaseArtistId": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "contributors": [ + { + "contributorId": "0e7b4a6c-5f8d-6b9e-ca0b-3c4d5e6f7a8b", + "role": "Producer" + }, + { + "contributorId": "1a8c5b7d-6a9e-7c0f-db1c-4d5e6f7a8b9c", + "role": "Engineer" + } + ], + "ratings": [ + { + "value": 4.5, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 2345 + }, + { + "value": 4.8, + "maxValue": 5, + "source": "LastFm", + "voteCount": 1234 + } + ], + "tracks": [ + { + "id": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f", + "albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac", + "metadata": { + "title": "Bohemian Rhapsody", + "originalTitle": "Bohemian Rhapsody", + "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, + "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "tags": [ { "name": "classic" }, { "name": "epic" } ], + "genres": [ { "name": "Rock" }, { "name": "Progressive Rock" } ], + "isVideo": false, + "durationInSeconds": 354, + "sampleRate": 44100, + "channels": 2, + "bitDepth": 16, + "audioCodec": "FLAC", + "bitrate": 980, + "acoustId": "f0e1d2c3-b4a5-4c6d-8e7f-9a0b1c2d3e4f", + "replayGainTrackGain": -7.5, + "replayGainTrackPeak": 0.9877, + "replayGainAlbumGain": -6.8, + "replayGainAlbumPeak": 0.9999 + }, + "trackNumber": 1, + "discNumber": 1, + "script": "Latn", + "key": "CMajor", + "bpm": 72, + "work": { + "musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c", + "title": "Bohemian Rhapsody", + "type": "Song", + "languages": [ + { "languageCode": "en", "languageName": "English", "nativeName": "English" } + ], + "iswcs": ["T-010489707-6"] + }, + "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", + "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "moods": [ + { "name": "dramatic" }, + { "name": "anxious" } + ], + "isrcs": [ + { "value": "GBUM71029604" } + ], + "contributors": [ + { + "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", + "role": "Vocals" + }, + { + "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", + "role": "Guitar" + } + ], + "ratings": [ + { + "value": 4.5, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 2345 + }, + { + "value": 4.8, + "maxValue": 5, + "source": "LastFm", + "voteCount": 1234 + } + ] + }, + { + "id": "8e1f2a3b-4c5d-4e6f-8a9b-0c1d2e3f4a5b", + "albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "path": "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac", + "metadata": { + "title": "You're My Best Friend", + "originalTitle": "You're My Best Friend", + "description": "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.", + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, + "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "tags": [ { "name": "classic" }, { "name": "love" } ], + "genres": [ { "name": "Rock" }, { "name": "Pop Rock" } ], + "isVideo": false, + "durationInSeconds": 181, + "sampleRate": 44100, + "channels": 2, + "bitDepth": 16, + "audioCodec": "FLAC", + "bitrate": 912, + "acoustId": "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d", + "replayGainTrackGain": -7.2, + "replayGainTrackPeak": 0.9812, + "replayGainAlbumGain": -6.5, + "replayGainAlbumPeak": 0.9987 + }, + "trackNumber": 7, + "discNumber": 1, + "script": "Latn", + "key": "BMajor", + "bpm": 118, + "work": { + "musicBrainzWorkId": "2b3c4d5e-6f7a-4b8c-9d0e-1f2a3b4c5d6e", + "title": "You're My Best Friend", + "type": "Song", + "languages": [ + { "languageCode": "en", "languageName": "English", "nativeName": "English" } + ], + "iswcs": ["T-010489707-6"] + }, + "musicBrainzRecordingId": "0f3e4d5c-6b7a-4f8e-9d0c-1b2a3c4d5e6f", + "musicBrainzTrackId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "moods": [ + { "name": "happy" }, + { "name": "warm" } + ], + "isrcs": [ + { "value": "GBUM71029609" } + ], + "contributors": [ + { + "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", + "role": "Vocals" + }, + { + "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", + "role": "Guitar" + } + ], + "ratings": [ + { + "value": 4.2, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 1234 + }, + { + "value": 4.4, + "maxValue": 5, + "source": "LastFm", + "voteCount": 567 + } + ] + } + ], + "coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg", + "artwork": [ + { + "type": "Cover", + "ordinal": 0, + "path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg" + } + ] + } + ], + "coverPath": "/media/music/Queen-3b3a19f3/cover.jpg" } ], "currentPage": 1, @@ -712,7 +1043,7 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists?currentPage=1& #### Get Artists Lite Request ```js -GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/lite?currentPage=1&perPage=10&searchTerm=queen +GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/lite?currentPage=1&perPage=10&searchTerm=queen&filterAlphaKey=q&shouldIgnoreThePrefixForAlphaPicker=true&sortBy=name&sortOrder=Ascending ``` | Query Parameter | Type | Description | @@ -720,6 +1051,10 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/lite?currentPa | `currentPage` | `int` | Optional. The page of results to retrieve. | | `perPage` | `int` | Optional. The maximum number of artists to retrieve per page. | | `searchTerm` | `string` | Optional. The search term used to filter the artists by name. | +| `filterAlphaKey` | `string` | Optional. Filters results by the first character of their name. A single ASCII letter (case-insensitive), `#` for names starting with a digit, or `*` for names starting with any other character. | +| `shouldIgnoreThePrefixForAlphaPicker` | `bool` | Whether the leading "The " prefix of a name should be ignored when computing the alpha key. | +| `sortBy` | `string` | Optional. The name of the field by which to sort the results. | +| `sortOrder` | `string` | Optional. The direction in which to sort the results (`Ascending` or `Descending`). | #### Get Artists Lite Response @@ -732,7 +1067,8 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/lite?currentPa "data": [ { "id": "d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a", - "name": "Queen" + "name": "Queen", + "coverPath": "/media/music/Queen-3b3a19f3/cover.jpg" } ], "currentPage": 1, @@ -764,22 +1100,36 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "metadata": { "name": "Queen", "sortName": "Queen", - "disambiguation": null, + "disambiguation": "British rock band", "type": "Group", - "gender": null, + "gender": "NotApplicable", "country": "GB", "area": { "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", "name": "United Kingdom", "sortName": "United Kingdom", - "disambiguation": null, + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, + "beginArea": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, + "endArea": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", "type": "Country", "iso3166Code": "GB" }, - "beginArea": null, - "endArea": null, "lifeSpanBegin": "1970-06-27", - "lifeSpanEnd": null, + "lifeSpanEnd": "1991-11-24", "isEnded": false, "genres": [ { "name": "Rock" } @@ -795,17 +1145,17 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "locale": "en", "isPrimary": true, "beginDate": "1970-06-27", - "endDate": null, + "endDate": "1991-11-24", "isEnded": false } ] }, "website": "https://www.queenonline.com", "musicBrainzArtistId": "6f9c0b2a-1d3e-4a5b-8c7d-9e0f1a2b3c4d", - "ipis": [], - "isnis": [], + "ipis": ["00012345678"], + "isnis": ["0000000123456789"], "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "contributors": [ { "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", "role": "Vocals" }, { "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", "role": "Guitar" } @@ -818,7 +1168,253 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "voteCount": 2345 } ], - "albums": [] + "albums": [ + { + "id": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "artistId": "d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "metadata": { + "title": "A Night at the Opera", + "originalTitle": "A Night at the Opera", + "description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.", + "disambiguation": "original release", + "releaseInfo": { + "originalReleaseDate": "1975-11-21", + "originalReleaseYear": 1975, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, + "releaseCountry": "GB", + "releaseVersion": "Remastered" + }, + "language": { + "languageCode": "en", + "languageName": "English", + "nativeName": "English" + }, + "originalLanguage": { + "languageCode": "en", + "languageName": "English", + "nativeName": "English" + }, + "tags": [ + { "name": "classic" }, + { "name": "vinyl" } + ], + "genres": [ + { "name": "Rock" }, + { "name": "Progressive Rock" } + ], + "script": "Latn", + "releaseTypes": [ "Album" ], + "releaseStatus": "Official", + "totalDiscs": 1, + "totalTracks": 12, + "releaseTitle": "A Night at the Opera" + }, + "mediaFormat": "CD", + "packaging": "JewelCase", + "barcode": "0042282778329", + "catalogNumbers": ["EMC 4008"], + "label": "EMI", + "asin": "B000000000", + "musicBrainzReleaseId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d", + "musicBrainzReleaseGroupId": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e", + "musicBrainzReleaseArtistId": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "contributors": [ + { + "contributorId": "0e7b4a6c-5f8d-6b9e-ca0b-3c4d5e6f7a8b", + "role": "Producer" + }, + { + "contributorId": "1a8c5b7d-6a9e-7c0f-db1c-4d5e6f7a8b9c", + "role": "Engineer" + } + ], + "ratings": [ + { + "value": 4.5, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 2345 + }, + { + "value": 4.8, + "maxValue": 5, + "source": "LastFm", + "voteCount": 1234 + } + ], + "tracks": [ + { + "id": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f", + "albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac", + "metadata": { + "title": "Bohemian Rhapsody", + "originalTitle": "Bohemian Rhapsody", + "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, + "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "tags": [ { "name": "classic" }, { "name": "epic" } ], + "genres": [ { "name": "Rock" }, { "name": "Progressive Rock" } ], + "isVideo": false, + "durationInSeconds": 354, + "sampleRate": 44100, + "channels": 2, + "bitDepth": 16, + "audioCodec": "FLAC", + "bitrate": 980, + "acoustId": "f0e1d2c3-b4a5-4c6d-8e7f-9a0b1c2d3e4f", + "replayGainTrackGain": -7.5, + "replayGainTrackPeak": 0.9877, + "replayGainAlbumGain": -6.8, + "replayGainAlbumPeak": 0.9999 + }, + "trackNumber": 1, + "discNumber": 1, + "script": "Latn", + "key": "CMajor", + "bpm": 72, + "work": { + "musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c", + "title": "Bohemian Rhapsody", + "type": "Song", + "languages": [ + { "languageCode": "en", "languageName": "English", "nativeName": "English" } + ], + "iswcs": ["T-010489707-6"] + }, + "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", + "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "moods": [ + { "name": "dramatic" }, + { "name": "anxious" } + ], + "isrcs": [ + { "value": "GBUM71029604" } + ], + "contributors": [ + { + "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", + "role": "Vocals" + }, + { + "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", + "role": "Guitar" + } + ], + "ratings": [ + { + "value": 4.5, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 2345 + }, + { + "value": 4.8, + "maxValue": 5, + "source": "LastFm", + "voteCount": 1234 + } + ] + }, + { + "id": "8e1f2a3b-4c5d-4e6f-8a9b-0c1d2e3f4a5b", + "albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f", + "libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a", + "path": "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac", + "metadata": { + "title": "You're My Best Friend", + "originalTitle": "You're My Best Friend", + "description": "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.", + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, + "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, + "tags": [ { "name": "classic" }, { "name": "love" } ], + "genres": [ { "name": "Rock" }, { "name": "Pop Rock" } ], + "isVideo": false, + "durationInSeconds": 181, + "sampleRate": 44100, + "channels": 2, + "bitDepth": 16, + "audioCodec": "FLAC", + "bitrate": 912, + "acoustId": "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d", + "replayGainTrackGain": -7.2, + "replayGainTrackPeak": 0.9812, + "replayGainAlbumGain": -6.5, + "replayGainAlbumPeak": 0.9987 + }, + "trackNumber": 7, + "discNumber": 1, + "script": "Latn", + "key": "BMajor", + "bpm": 118, + "work": { + "musicBrainzWorkId": "2b3c4d5e-6f7a-4b8c-9d0e-1f2a3b4c5d6e", + "title": "You're My Best Friend", + "type": "Song", + "languages": [ + { "languageCode": "en", "languageName": "English", "nativeName": "English" } + ], + "iswcs": ["T-010489707-6"] + }, + "musicBrainzRecordingId": "0f3e4d5c-6b7a-4f8e-9d0c-1b2a3c4d5e6f", + "musicBrainzTrackId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", + "createdOnUtc": "2025-01-01T12:00:00.0000000Z", + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", + "moods": [ + { "name": "happy" }, + { "name": "warm" } + ], + "isrcs": [ + { "value": "GBUM71029609" } + ], + "contributors": [ + { + "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", + "role": "Vocals" + }, + { + "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", + "role": "Guitar" + } + ], + "ratings": [ + { + "value": 4.2, + "maxValue": 5, + "source": "MusicBrainz", + "voteCount": 1234 + }, + { + "value": 4.4, + "maxValue": 5, + "source": "LastFm", + "voteCount": 567 + } + ] + } + ], + "coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg", + "artwork": [ + { + "type": "Cover", + "ordinal": 0, + "path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg" + } + ] + } + ], + "coverPath": "/media/music/Queen-3b3a19f3/cover.jpg" } ``` @@ -836,22 +1432,36 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "metadata": { "name": "Queen", "sortName": "Queen", - "disambiguation": null, + "disambiguation": "British rock band", "type": "Group", - "gender": null, + "gender": "NotApplicable", "country": "GB", "area": { "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", "name": "United Kingdom", "sortName": "United Kingdom", - "disambiguation": null, + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, + "beginArea": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, + "endArea": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", "type": "Country", "iso3166Code": "GB" }, - "beginArea": null, - "endArea": null, "lifeSpanBegin": "1970-06-27", - "lifeSpanEnd": null, + "lifeSpanEnd": "1991-11-24", "isEnded": false, "genres": [ { "name": "Rock" } @@ -867,15 +1477,15 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "locale": "en", "isPrimary": true, "beginDate": "1970-06-27", - "endDate": null, + "endDate": "1991-11-24", "isEnded": false } ] }, "website": "https://www.queenonline.com", "musicBrainzArtistId": "6f9c0b2a-1d3e-4a5b-8c7d-9e0f1a2b3c4d", - "ipis": [], - "isnis": [], + "ipis": ["00012345678"], + "isnis": ["0000000123456789"], "contributors": [ { "contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d", "role": "Vocals" }, { "contributorId": "7b4e1d3f-2c5a-4e6b-9d7e-0f1a2b3c4d5e", "role": "Guitar" } @@ -895,12 +1505,12 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "title": "A Night at the Opera", "originalTitle": "A Night at the Opera", "description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.", - "disambiguation": null, + "disambiguation": "original release", "releaseInfo": { "originalReleaseDate": "1975-11-21", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Remastered" }, @@ -964,12 +1574,12 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "title": "Bohemian Rhapsody", "originalTitle": "Bohemian Rhapsody", "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", - "disambiguation": null, + "disambiguation": "album version", "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, @@ -1016,7 +1626,7 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", @@ -1053,12 +1663,12 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "title": "You're My Best Friend", "originalTitle": "You're My Best Friend", "description": "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.", - "disambiguation": null, + "disambiguation": "album version", "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, @@ -1087,11 +1697,11 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "bitDepth": 16, "audioCodec": "FLAC", "bitrate": 912, - "acoustId": null, - "replayGainTrackGain": null, - "replayGainTrackPeak": null, - "replayGainAlbumGain": null, - "replayGainAlbumPeak": null + "acoustId": "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d", + "replayGainTrackGain": -7.2, + "replayGainTrackPeak": 0.9812, + "replayGainAlbumGain": -6.5, + "replayGainAlbumPeak": 0.9987 }, "trackNumber": 7, "discNumber": 1, @@ -1105,7 +1715,7 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "0f3e4d5c-6b7a-4f8e-9d0c-1b2a3c4d5e6f", "musicBrainzTrackId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", @@ -1154,22 +1764,36 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "metadata": { "name": "Queen", "sortName": "Queen", - "disambiguation": null, + "disambiguation": "British rock band", "type": "Group", - "gender": null, + "gender": "NotApplicable", "country": "GB", "area": { "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", "name": "United Kingdom", "sortName": "United Kingdom", - "disambiguation": null, + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, + "beginArea": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", + "type": "Country", + "iso3166Code": "GB" + }, + "endArea": { + "musicBrainzAreaId": "7f2a1b3c-4d5e-4f6a-8b9c-0d1e2f3a4b5c", + "name": "United Kingdom", + "sortName": "United Kingdom", + "disambiguation": "sovereign state", "type": "Country", "iso3166Code": "GB" }, - "beginArea": null, - "endArea": null, "lifeSpanBegin": "1970-06-27", - "lifeSpanEnd": null, + "lifeSpanEnd": "1991-11-24", "isEnded": false, "genres": [ { "name": "Rock" } @@ -1185,15 +1809,15 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "locale": "en", "isPrimary": true, "beginDate": "1970-06-27", - "endDate": null, + "endDate": "1991-11-24", "isEnded": false } ] }, "website": "https://www.queenonline.com", "musicBrainzArtistId": "6f9c0b2a-1d3e-4a5b-8c7d-9e0f1a2b3c4d", - "ipis": [], - "isnis": [], + "ipis": ["00012345678"], + "isnis": ["0000000123456789"], "createdOnUtc": "2025-01-01T12:00:00.0000000Z", "updatedOnUtc": "2025-02-01T12:00:00.0000000Z", "contributors": [ @@ -1217,12 +1841,12 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "title": "A Night at the Opera", "originalTitle": "A Night at the Opera", "description": "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.", - "disambiguation": null, + "disambiguation": "original release", "releaseInfo": { "originalReleaseDate": "1975-11-21", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Remastered" }, @@ -1261,7 +1885,7 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "musicBrainzReleaseGroupId": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e", "musicBrainzReleaseArtistId": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "contributors": [ { "contributorId": "0e7b4a6c-5f8d-6b9e-ca0b-3c4d5e6f7a8b", @@ -1296,8 +1920,8 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "title": "Bohemian Rhapsody", "originalTitle": "Bohemian Rhapsody", "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", - "disambiguation": null, - "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": null, "reReleaseYear": null, "releaseCountry": "GB", "releaseVersion": "Original" }, + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "tags": [ { "name": "classic" }, { "name": "epic" } ], @@ -1327,12 +1951,12 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "moods": [ { "name": "dramatic" }, { "name": "anxious" } @@ -1374,8 +1998,8 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "title": "You're My Best Friend", "originalTitle": "You're My Best Friend", "description": "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.", - "disambiguation": null, - "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, "reReleaseDate": null, "reReleaseYear": null, "releaseCountry": "GB", "releaseVersion": "Original" }, + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1976-06-18", "originalReleaseYear": 1976, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "tags": [ { "name": "classic" }, { "name": "love" } ], @@ -1387,11 +2011,11 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "bitDepth": 16, "audioCodec": "FLAC", "bitrate": 912, - "acoustId": null, - "replayGainTrackGain": null, - "replayGainTrackPeak": null, - "replayGainAlbumGain": null, - "replayGainAlbumPeak": null + "acoustId": "0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d", + "replayGainTrackGain": -7.2, + "replayGainTrackPeak": 0.9812, + "replayGainAlbumGain": -6.5, + "replayGainAlbumPeak": 0.9987 }, "trackNumber": 7, "discNumber": 1, @@ -1405,12 +2029,12 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "0f3e4d5c-6b7a-4f8e-9d0c-1b2a3c4d5e6f", "musicBrainzTrackId": "1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "moods": [ { "name": "happy" }, { "name": "warm" } @@ -1443,9 +2067,48 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId} } ] } + ], + "coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg", + "artwork": [ + { + "type": "Cover", + "ordinal": 0, + "path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg" + } ] } - ] + ], + "coverPath": "/media/music/Queen-3b3a19f3/cover.jpg" +} +``` + +### Update Artist Cover + +Updates the cover image of the artist identified by `artistId` with the image uploaded in the multipart form of the request. The artist must belong to the media library identified by `libraryId`, and the uploaded file must be an image. + +#### Update Artist Cover Request + +```js +PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}/cover +Content-Type: multipart/form-data; boundary=LuminaBoundary + +--LuminaBoundary +Content-Disposition: form-data; name="cover"; filename="cover.jpg" +Content-Type: image/jpeg + +< ./cover.jpg +--LuminaBoundary-- +``` + +#### Update Artist Cover Response + +```js +200 Ok +``` + +```json +{ + "coverPath": "/media/music/music-3f2504e0-4f89-41d3-9a0c-0305e82c3301/Queen-2b0e5f5a-0b3f-4b7e-8f4a-8c9e3d2f5a6b/cover.jpg" } ``` diff --git a/docs/technical/api/library/audio-library/music-library/Api.Tracks.md b/docs/technical/api/library/audio-library/music-library/Api.Tracks.md index bdb6e2d9..4cf0d71c 100644 --- a/docs/technical/api/library/audio-library/music-library/Api.Tracks.md +++ b/docs/technical/api/library/audio-library/music-library/Api.Tracks.md @@ -30,12 +30,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "title": "Bohemian Rhapsody", "originalTitle": "Bohemian Rhapsody", "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", - "disambiguation": null, + "disambiguation": "album version", "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, @@ -82,7 +82,7 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", @@ -130,8 +130,8 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "title": "Bohemian Rhapsody", "originalTitle": "Bohemian Rhapsody", "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", - "disambiguation": null, - "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": null, "reReleaseYear": null, "releaseCountry": "GB", "releaseVersion": "Original" }, + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "tags": [ { "name": "classic" }, { "name": "epic" } ], @@ -161,12 +161,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "moods": [ { "name": "dramatic" @@ -232,8 +232,8 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "title": "Bohemian Rhapsody", "originalTitle": "Bohemian Rhapsody", "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", - "disambiguation": null, - "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": null, "reReleaseYear": null, "releaseCountry": "GB", "releaseVersion": "Original" }, + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "tags": [ { "name": "classic" }, { "name": "epic" } ], @@ -263,12 +263,12 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "moods": [ { "name": "dramatic" @@ -325,12 +325,12 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "title": "Bohemian Rhapsody", "originalTitle": "Bohemian Rhapsody", "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", - "disambiguation": null, + "disambiguation": "album version", "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, - "reReleaseDate": null, - "reReleaseYear": null, + "reReleaseDate": "2011-11-21", + "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, @@ -377,7 +377,7 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", @@ -425,8 +425,8 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "title": "Bohemian Rhapsody", "originalTitle": "Bohemian Rhapsody", "description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.", - "disambiguation": null, - "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": null, "reReleaseYear": null, "releaseCountry": "GB", "releaseVersion": "Original" }, + "disambiguation": "album version", + "releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": "2011-11-21", "reReleaseYear": 2011, "releaseCountry": "GB", "releaseVersion": "Original" }, "language": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" }, "tags": [ { "name": "classic" }, { "name": "epic" } ], @@ -456,12 +456,12 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b- "languages": [ { "languageCode": "en", "languageName": "English", "nativeName": "English" } ], - "iswcs": [] + "iswcs": ["T-010489707-6"] }, "musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a", "musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b", "createdOnUtc": "2025-01-01T12:00:00.0000000Z", - "updatedOnUtc": null, + "updatedOnUtc": "2025-01-20T14:45:00.0000000Z", "moods": [ { "name": "dramatic" diff --git a/docs/technical/requests/library/audio-library/music-library/artists/GetArtistsLite.http b/docs/technical/requests/library/audio-library/music-library/artists/GetArtistsLite.http index c95805e1..679436a5 100644 --- a/docs/technical/requests/library/audio-library/music-library/artists/GetArtistsLite.http +++ b/docs/technical/requests/library/audio-library/music-library/artists/GetArtistsLite.http @@ -1,2 +1,2 @@ -GET {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/lite?currentPage=1&perPage=10&searchTerm=queen +GET {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/lite?currentPage=1&perPage=10&searchTerm=queen&filterAlphaKey=q&shouldIgnoreThePrefixForAlphaPicker=true&sortBy=name&sortOrder=Ascending Authorization: Bearer {{ACCESS_TOKEN}} diff --git a/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRow.cs b/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRow.cs index 93b67e3a..9a74fa8a 100644 --- a/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRow.cs +++ b/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRow.cs @@ -1,5 +1,7 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using System; +using System.Collections.Generic; #endregion namespace Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Albums; @@ -23,4 +25,19 @@ public sealed record AlbumLiteRow /// Gets the number of tracks of the release. /// public int TotalTracks { get; init; } + + /// + /// Gets the path of the image representing the album, if available. + /// + public string? CoverPath { get; init; } + + /// + /// Gets the release year of the album (the re-release year, if available, or the original release year), if known. + /// + public int? ReleaseYear { get; init; } + + /// + /// Gets the set of types of the release. + /// + public List? ReleaseTypes { get; init; } } diff --git a/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRow.cs b/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRow.cs index 27aae3d4..31970314 100644 --- a/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRow.cs +++ b/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRow.cs @@ -18,4 +18,9 @@ public sealed record ArtistLiteRow /// Gets the name of the artist. /// public required string Name { get; init; } + + /// + /// Gets the path of the image representing the artist, if available. + /// + public string? CoverPath { get; init; } } diff --git a/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRow.cs b/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRow.cs index 2b21efcf..33275f1a 100644 --- a/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRow.cs +++ b/src/Lumina.Application/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRow.cs @@ -28,4 +28,9 @@ public sealed record TrackLiteRow /// Gets the number of the disc the track belongs to, if applicable. /// public int? DiscNumber { get; init; } + + /// + /// Gets the duration of the track in seconds. + /// + public int DurationInSeconds { get; init; } } diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumEntityMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumEntityMapping.cs index add81757..887dcb2c 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumEntityMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumEntityMapping.cs @@ -157,8 +157,10 @@ public static class AlbumEntityMapping /// Converts to . /// /// The repository entity to be converted. + /// The optional path of the image representing the album. + /// The optional stored artwork of the album, in display order. /// The converted response entity. - public static AlbumResponse ToResponse(this AlbumEntity repositoryEntity) + public static AlbumResponse ToResponse(this AlbumEntity repositoryEntity, string? coverPath = null, IReadOnlyList? artwork = null) { ReleaseInfoDto releaseInfo = new( repositoryEntity.OriginalReleaseDate, @@ -220,7 +222,9 @@ public static class AlbumEntityMapping repositoryEntity.UpdatedOnUtc, [.. repositoryEntity.Contributors.Select(contributor => new MediaContributorReferenceDto(contributor.MediaContributorId, contributor.Role))], [.. repositoryEntity.Ratings.ToResponses()], - [.. repositoryEntity.Tracks.Select(track => track.ToResponse())]); + [.. repositoryEntity.Tracks.Select(track => track.ToResponse())], + coverPath, + artwork ?? []); } /// diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRowMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRowMapping.cs index 4d5075a6..4cc0c2b7 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRowMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRowMapping.cs @@ -24,7 +24,10 @@ public static class AlbumLiteRowMapping return new AlbumLiteResponse( readModel.Id, readModel.Title, - readModel.TotalTracks); + readModel.TotalTracks, + readModel.CoverPath, + readModel.ReleaseYear, + readModel.ReleaseTypes); } /// diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistEntityMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistEntityMapping.cs index bf1560ba..c77a161e 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistEntityMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistEntityMapping.cs @@ -147,8 +147,9 @@ public static class ArtistEntityMapping /// Converts to . /// /// The repository entity to be converted. + /// The optional path of the image representing the artist. /// The converted response entity. - public static ArtistResponse ToResponse(this ArtistEntity repositoryEntity) + public static ArtistResponse ToResponse(this ArtistEntity repositoryEntity, string? coverPath = null) { MusicArtistMetadataDto metadata = new( repositoryEntity.Name, @@ -178,7 +179,8 @@ public static class ArtistEntityMapping repositoryEntity.UpdatedOnUtc, [.. repositoryEntity.Contributors.Select(contributor => new MediaContributorReferenceDto(contributor.MediaContributorId, contributor.Role))], [.. repositoryEntity.Ratings.ToResponses()], - [.. repositoryEntity.Albums.Select(album => album.ToResponse())]); + [.. repositoryEntity.Albums.Select(album => album.ToResponse())], + coverPath); } /// diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRowMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRowMapping.cs index b68bd3a7..d1d6c91a 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRowMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRowMapping.cs @@ -23,7 +23,8 @@ public static class ArtistLiteRowMapping { return new ArtistLiteResponse( readModel.Id, - readModel.Name); + readModel.Name, + readModel.CoverPath); } /// diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequestMapping.cs index 2eebc351..78957980 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequestMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequestMapping.cs @@ -30,6 +30,10 @@ public static class GetArtistsLiteRequestMapping return new GetArtistsLiteQuery( libraryId, paginationData, - request.SearchTerm); + request.SearchTerm, + request.FilterAlphaKey, + request.ShouldIgnoreThePrefixForAlphaPicker, + request.SortBy, + request.SortOrder); } } diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRowMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRowMapping.cs index a32662b9..cd5b67ca 100644 --- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRowMapping.cs +++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRowMapping.cs @@ -25,7 +25,8 @@ public static class TrackLiteRowMapping readModel.Id, readModel.Title, readModel.TrackNumber, - readModel.DiscNumber); + readModel.DiscNumber, + readModel.DurationInSeconds); } /// diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryHandler.cs index e0d81c41..7bf9d626 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryHandler.cs @@ -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> 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 artwork = [.. getArtworkResult.Value + .Where(storedArtwork => !string.IsNullOrWhiteSpace(storedArtwork.FileName)) + .Select(storedArtwork => new MediaArtworkDto(storedArtwork.ArtworkType, storedArtwork.Ordinal, storedArtwork.FileName!))]; + + return existingAlbum.ToResponse(coverPath, artwork); } } diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtist/GetArtistQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtist/GetArtistQueryHandler.cs index 6f712640..b9d0c4f5 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtist/GetArtistQueryHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtist/GetArtistQueryHandler.cs @@ -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> 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); } } diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQuery.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQuery.cs index 53533ad6..04bc19e2 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQuery.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQuery.cs @@ -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 /// The unique identifier of the media library whose artists are retrieved, taken from the route. /// The object containing the requested pagination data. /// The search term used to filter the artists by name. +/// The alpha key used to filter the artists by the first character of their name. +/// Whether the leading "The " prefix of a name should be ignored when computing the alpha key, or not. +/// The name of the field by which to sort the results. +/// The direction in which to sort the results. [DebuggerDisplay("LibraryId: {LibraryId}")] public record GetArtistsLiteQuery( string? LibraryId, PaginationDataDto? PaginationData, - string? SearchTerm + string? SearchTerm, + string? FilterAlphaKey, + bool ShouldIgnoreThePrefixForAlphaPicker, + string? SortBy, + SortOrder? SortOrder ) : IQuery; diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryHandler.cs index 01a281e2..5915245c 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryHandler.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryHandler.cs @@ -78,12 +78,16 @@ public class GetArtistsLiteQueryHandler : IQueryHandler> 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); } diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryValidator.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryValidator.cs index 3955889e..5825d84a 100644 --- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryValidator.cs +++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryValidator.cs @@ -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 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); } } diff --git a/src/Lumina.Contracts/DTO/Common/MediaArtworkDto.cs b/src/Lumina.Contracts/DTO/Common/MediaArtworkDto.cs new file mode 100644 index 00000000..7edd6862 --- /dev/null +++ b/src/Lumina.Contracts/DTO/Common/MediaArtworkDto.cs @@ -0,0 +1,19 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System.Diagnostics; +#endregion + +namespace Lumina.Contracts.DTO.Common; + +/// +/// Data transfer object for a stored piece of artwork of a media item. +/// +/// The type of the artwork, like the cover or the back of the media item. +/// The ordinal of the artwork within its type, so that multiple artworks of the same type can be ordered. +/// The relative path of the stored artwork file. +[DebuggerDisplay("Type: {Type}, Ordinal: {Ordinal}, Path: {Path}")] +public sealed record MediaArtworkDto( + ArtworkType Type, + int Ordinal, + string Path +); diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequest.cs index c4ff7444..82c4ca82 100644 --- a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequest.cs +++ b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequest.cs @@ -1,4 +1,5 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Domain.SharedKernel.Common.Enums.Common; using System.Diagnostics; #endregion @@ -10,9 +11,21 @@ namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artis /// The page of results to retrieve. Optional. /// The maximum number of artists to retrieve per page. Optional. /// The search term used to filter the artists by name. Optional. +/// +/// The alpha key used to filter the results by the first character of their name, for the alpha picker. Optional. +/// Can be to disable alpha filtering, a single ASCII letter (case-insensitive) to filter by that letter, +/// "#" to filter by names whose first character is a digit, or "*" to filter by names whose first character is neither a letter nor a digit. +/// +/// Whether the leading "The " prefix of a name should be ignored when computing the alpha key, or not. Optional. +/// The name of the field by which to sort the results. Optional. +/// The direction in which to sort the results. Optional. [DebuggerDisplay("SearchTerm: {SearchTerm}")] public record GetArtistsLiteRequest( int? CurrentPage, int? PerPage, - string? SearchTerm + string? SearchTerm, + string? FilterAlphaKey, + bool ShouldIgnoreThePrefixForAlphaPicker, + string? SortBy, + SortOrder? SortOrder ); diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteResponse.cs index ac6aa364..87411bb1 100644 --- a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteResponse.cs +++ b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteResponse.cs @@ -1,5 +1,7 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using System; +using System.Collections.Generic; using System.Diagnostics; #endregion @@ -11,9 +13,15 @@ namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albu /// The Id of the album. /// The title of the album. /// The number of tracks of the release. +/// The path of the image representing the album, if available. +/// The release year of the album (the re-release year, if available, or the original release year), if known. +/// The set of types of the release. [DebuggerDisplay("Title: {Title}")] public record AlbumLiteResponse( Guid Id, string Title, - int TotalTracks + int TotalTracks, + string? CoverPath, + int? ReleaseYear, + List? ReleaseTypes ); diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumResponse.cs index 84760c8f..cd72e94a 100644 --- a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumResponse.cs +++ b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumResponse.cs @@ -1,4 +1,5 @@ #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; @@ -32,6 +33,8 @@ namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albu /// The list of references to the media contributors that performed on the album, each with the role they played. /// The list of ratings for this album. /// The list of tracks of the album. +/// The path of the image representing the album, if available. +/// The stored artwork of the album, in display order, so that all of its pieces can be presented, not just the cover. [DebuggerDisplay("Title: {Metadata.Title}")] public record AlbumResponse( Guid Id, @@ -51,5 +54,7 @@ public record AlbumResponse( DateTime? UpdatedOnUtc, List? Contributors, List? Ratings, - List? Tracks + List? Tracks, + string? CoverPath, + IReadOnlyList Artwork ); diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteResponse.cs index aa4b7faf..f5cc8ea7 100644 --- a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteResponse.cs +++ b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteResponse.cs @@ -10,8 +10,10 @@ namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Arti /// /// The Id of the artist. /// The name of the artist. +/// The path of the image representing the artist, if available. [DebuggerDisplay("Name: {Name}")] public record ArtistLiteResponse( Guid Id, - string Name + string Name, + string? CoverPath ); diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistResponse.cs index ec147700..9a51928c 100644 --- a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistResponse.cs +++ b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistResponse.cs @@ -25,6 +25,7 @@ namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Arti /// The list of references to the media contributors that make up the artist, each with the role they played. /// The list of ratings for this artist. /// The list of albums of the artist, each with its own list of tracks. +/// The path of the image representing the artist, if available. [DebuggerDisplay("Name: {Metadata.Name}")] public record ArtistResponse( Guid Id, @@ -38,5 +39,6 @@ public record ArtistResponse( DateTime? UpdatedOnUtc, List? Contributors, List? Ratings, - List? Albums + List? Albums, + string? CoverPath ); diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteResponse.cs index 263b3669..071776ea 100644 --- a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteResponse.cs +++ b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteResponse.cs @@ -12,10 +12,12 @@ namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Trac /// The title of the track. /// The number of the track on its disc. /// The number of the disc the track belongs to, if applicable. +/// The duration of the track in seconds. [DebuggerDisplay("Title: {Title}")] public record TrackLiteResponse( Guid Id, string Title, int TrackNumber, - int? DiscNumber + int? DiscNumber, + int DurationInSeconds ); diff --git a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/AlbumRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/AlbumRepository.cs index c0f21bbb..232342f7 100644 --- a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/AlbumRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/AlbumRepository.cs @@ -284,7 +284,15 @@ internal sealed class AlbumRepository : IAlbumRepository { Id = album.Id, Title = album.Title, - TotalTracks = album.TotalTracks + TotalTracks = album.TotalTracks, + // The release year and the release types are exposed so that the clients can group and order the releases of an artist. + ReleaseYear = album.ReReleaseYear ?? album.OriginalReleaseYear, + ReleaseTypes = album.ReleaseTypes.Select(releaseType => releaseType.ReleaseType).ToList(), + // The cover of the album is the cover artwork stored for it, if any, and it is exposed so that the clients can display it without loading the whole album. + CoverPath = _luminaDbContext.MusicArtwork + .Where(artwork => artwork.OwnerType == MusicArtworkOwnerType.Album && artwork.OwnerId == album.Id && artwork.ArtworkType == ArtworkType.Cover) + .Select(artwork => artwork.FileName) + .FirstOrDefault() }); if (paginationData is null) diff --git a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/ArtistRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/ArtistRepository.cs index fea91e76..ff9a8e08 100644 --- a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/ArtistRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/ArtistRepository.cs @@ -18,6 +18,8 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; +using System.Reflection; using System.Threading; using System.Threading.Tasks; #endregion @@ -29,6 +31,10 @@ namespace Lumina.DataAccess.Core.Repositories.MusicLibrary; /// internal sealed class ArtistRepository : IArtistRepository { + private static readonly MethodInfo s_toLowerMethod = typeof(string).GetMethod(nameof(string.ToLower), Type.EmptyTypes)!; + private static readonly MethodInfo s_startsWithMethod = typeof(string).GetMethod(nameof(string.StartsWith), [typeof(string)])!; + private static readonly MethodInfo s_substringMethod = typeof(string).GetMethod(nameof(string.Substring), [typeof(int)])!; + private readonly LuminaDbContext _luminaDbContext; private readonly IAlbumRepository _albumRepository; private readonly ITrackRepository _trackRepository; @@ -488,7 +494,7 @@ internal sealed class ArtistRepository : IArtistRepository if (filterSpecification is not null) artistsQuery = artistsQuery.Where(filterSpecification.ToExpression()); - IQueryable orderedArtistsQuery = ApplySorting(artistsQuery, sortBy, sortOrder ?? SortOrder.Ascending); + IQueryable orderedArtistsQuery = ApplySorting(artistsQuery, sortBy, sortOrder ?? SortOrder.Ascending, libraryFilter.ShouldIgnoreThePrefixForAlphaPicker); // If no pagination was requested, return all the artists of the library. if (paginationData is null) @@ -559,11 +565,16 @@ internal sealed class ArtistRepository : IArtistRepository if (filterSpecification is not null) artistsQuery = artistsQuery.Where(filterSpecification.ToExpression()); - IQueryable liteRowsQuery = ApplySorting(artistsQuery, sortBy, sortOrder ?? SortOrder.Ascending) + IQueryable liteRowsQuery = ApplySorting(artistsQuery, sortBy, sortOrder ?? SortOrder.Ascending, libraryFilter.ShouldIgnoreThePrefixForAlphaPicker) .Select(artist => new ArtistLiteRow { Id = artist.Id, - Name = artist.Name + Name = artist.Name, + // The cover of the artist is the cover artwork stored for it, if any, and it is exposed so that the clients can display it without loading the whole artist. + CoverPath = _luminaDbContext.MusicArtwork + .Where(artwork => artwork.OwnerType == MusicArtworkOwnerType.Artist && artwork.OwnerId == artist.Id && artwork.ArtworkType == ArtworkType.Cover) + .Select(artwork => artwork.FileName) + .FirstOrDefault() }); // If no pagination was requested, return all the artists of the library. @@ -607,11 +618,22 @@ internal sealed class ArtistRepository : IArtistRepository /// A filter specification that can be used to query artists matching the provided criteria. private static FilterSpecification? BuildFilterSpecification(LibraryFilterDto libraryFilter) { + FilterSpecification? filterSpecification = null; + // Include the search term filter, if provided. if (!string.IsNullOrWhiteSpace(libraryFilter.SearchTerm)) - return new ArtistSearchSpecification(libraryFilter.SearchTerm); + filterSpecification = new ArtistSearchSpecification(libraryFilter.SearchTerm); - return null; + // Include the alpha key filter, if provided. + if (libraryFilter.FilterAlphaKey is not null) + { + ArtistAlphaFilterSpecification alphaFilterSpecification = new(libraryFilter.FilterAlphaKey, libraryFilter.ShouldIgnoreThePrefixForAlphaPicker); + filterSpecification = filterSpecification is null + ? alphaFilterSpecification + : filterSpecification.And(alphaFilterSpecification); + } + + return filterSpecification; } /// @@ -620,8 +642,8 @@ internal sealed class ArtistRepository : IArtistRepository /// The query to sort. /// The field to sort by (case-insensitive). /// The direction of the sorting. - /// An ordered artists query. - private static IOrderedQueryable ApplySorting(IQueryable artistsQuery, string? sortBy, SortOrder sortOrder) + /// Whether a leading "the " prefix of a name is ignored when deriving the name sort key, or not. + private static IOrderedQueryable ApplySorting(IQueryable artistsQuery, string? sortBy, SortOrder sortOrder, bool shouldIgnoreThePrefixForAlphaPicker) { return sortBy?.ToLowerInvariant() switch { @@ -638,11 +660,41 @@ internal sealed class ArtistRepository : IArtistRepository ? artistsQuery.OrderByDescending(artist => artist.UpdatedOnUtc).ThenBy(artist => artist.Id) : artistsQuery.OrderBy(artist => artist.UpdatedOnUtc).ThenBy(artist => artist.Id), _ => sortOrder == SortOrder.Descending - ? artistsQuery.OrderByDescending(artist => artist.Name).ThenBy(artist => artist.Id) - : artistsQuery.OrderBy(artist => artist.Name).ThenBy(artist => artist.Id), + ? artistsQuery.OrderByDescending(BuildNameSortKey(shouldIgnoreThePrefixForAlphaPicker)).ThenBy(artist => artist.Id) + : artistsQuery.OrderBy(BuildNameSortKey(shouldIgnoreThePrefixForAlphaPicker)).ThenBy(artist => artist.Id), }; } + /// + /// Builds the expression that derives the name sort key of an artist, matching the effective name used by the alpha filter: + /// the name lowercased, falling back to an empty string when the name is , and optionally + /// stripped of a leading "the " prefix. + /// + /// Whether a leading "the " prefix of a name is ignored when deriving the name sort key, or not. + /// An expression that evaluates to the name sort key of an artist. + private static Expression> BuildNameSortKey(bool shouldIgnoreThePrefixForAlphaPicker) + { + ParameterExpression artist = Expression.Parameter(typeof(ArtistEntity), "artist"); + + Expression nameProperty = Expression.Property(artist, nameof(ArtistEntity.Name)); + + // The raw name: the name, unless it is null, in which case an empty string is used. + Expression rawName = Expression.Coalesce(nameProperty, Expression.Constant(string.Empty)); + + MethodCallExpression lowerName = Expression.Call(rawName, s_toLowerMethod); + + // When ignoring the "The " prefix, strip a leading "the " from the lowercased name. + Expression effectiveName = lowerName; + if (shouldIgnoreThePrefixForAlphaPicker) + { + MethodCallExpression startsWithThe = Expression.Call(lowerName, s_startsWithMethod, Expression.Constant("the ")); + MethodCallExpression strippedName = Expression.Call(lowerName, s_substringMethod, Expression.Constant(4)); + effectiveName = Expression.Condition(startsWithThe, strippedName, lowerName); + } + + return Expression.Lambda>(effectiveName, artist); + } + /// /// Gets the artist of the library identified by that has the provided . /// @@ -793,4 +845,19 @@ internal sealed class ArtistRepository : IArtistRepository .ExecuteUpdateAsync(setters => setters.SetProperty(artist => artist.MetadataStatus, MetadataStatus.Pending), cancellationToken).ConfigureAwait(false); return Result.Updated; } + + /// + /// Deletes all the artists of the media library identified by , together with their albums and tracks and their related data. + /// + /// The Id of the media library whose artists are deleted. + /// Cancellation token that can be used to stop the execution. + /// An representing either a successful operation, or an error. + public async Task> DeleteByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken) + { + // The albums, tracks and the related data of the artists are removed by the database, through the cascading foreign keys. + await _luminaDbContext.Artists + .Where(artist => artist.LibraryId == libraryId) + .ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false); + return Result.Deleted; + } } diff --git a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/Specifications/ArtistAlphaFilterSpecification.cs b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/Specifications/ArtistAlphaFilterSpecification.cs new file mode 100644 index 00000000..c178cafe --- /dev/null +++ b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/Specifications/ArtistAlphaFilterSpecification.cs @@ -0,0 +1,127 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.Application.Common.DTO.Filtering; +using Lumina.Application.Common.Specifications; +using Microsoft.EntityFrameworkCore; +using System; +using System.Linq.Expressions; +using System.Reflection; +#endregion + +namespace Lumina.DataAccess.Core.Repositories.MusicLibrary.Specifications; + +/// +/// Represents a filter specification for filtering artists by the alpha key of their name, for the alpha picker. +/// The alpha key is the first character of the name, lowercased, and optionally computed after ignoring a leading "The " prefix. +/// +internal sealed class ArtistAlphaFilterSpecification : FilterSpecification +{ + private static readonly MethodInfo s_toLowerMethod = typeof(string).GetMethod(nameof(string.ToLower), Type.EmptyTypes)!; + private static readonly MethodInfo s_startsWithMethod = typeof(string).GetMethod(nameof(string.StartsWith), [typeof(string)])!; + private static readonly MethodInfo s_substringMethod = typeof(string).GetMethod(nameof(string.Substring), [typeof(int)])!; + private static readonly MethodInfo s_globMethod = typeof(SqliteDbFunctionsExtensions) + .GetMethod(nameof(SqliteDbFunctionsExtensions.Glob), [typeof(DbFunctions), typeof(string), typeof(string)])!; + + private readonly string? _filterAlphaKey; + private readonly bool _shouldIgnoreThePrefixForAlphaPicker; + + /// + /// Initializes a new instance of the class. + /// + /// The alpha key to filter by. A single ASCII letter, , or . + /// Whether the leading "The " prefix of a name should be ignored when computing the alpha key, or not. + public ArtistAlphaFilterSpecification(string? filterAlphaKey, bool shouldIgnoreThePrefixForAlphaPicker) + { + _filterAlphaKey = filterAlphaKey; + _shouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker; + } + + /// + /// Creates a LINQ expression that represents the predicate defined by the current specification. + /// + /// An expression tree that can be used to evaluate whether an satisfies the specification criteria. + public override Expression> ToExpression() + { + // When no alpha key was requested, every artist matches. + if (_filterAlphaKey is null) + return artist => true; + + ParameterExpression artist = Expression.Parameter(typeof(ArtistEntity), "artist"); + Expression effectiveName = BuildEffectiveName(artist); + + if (_filterAlphaKey == LibraryItemAlphaKeys.NUMBER) + return BuildGlobPredicate(artist, effectiveName, "[0-9]*"); + + if (_filterAlphaKey == LibraryItemAlphaKeys.SYMBOL) + return BuildSymbolPredicate(artist, effectiveName); + + // The alpha key is a single ASCII letter. + string globPattern = char.ToLowerInvariant(_filterAlphaKey[0]) + "*"; + return BuildGlobPredicate(artist, effectiveName, globPattern); + } + + /// + /// Builds the expression representing the lowercased name used to derive the alpha key, falling back to an empty string + /// when the name is or empty, and optionally stripped of a leading "the " prefix. + /// + /// The parameter representing the artist entity. + /// The expression of the effective name. + private Expression BuildEffectiveName(ParameterExpression artist) + { + Expression nameProperty = Expression.Property(artist, nameof(ArtistEntity.Name)); + + // The raw name is the name, unless it is null, in which case an empty string is used. + Expression rawName = Expression.Coalesce(nameProperty, Expression.Constant(string.Empty)); + + MethodCallExpression lowerName = Expression.Call(rawName, s_toLowerMethod); + + // When ignoring the "The " prefix, a leading "the " is stripped from the lowercased name. + Expression effectiveName = lowerName; + if (_shouldIgnoreThePrefixForAlphaPicker) + { + MethodCallExpression startsWithThe = Expression.Call(lowerName, s_startsWithMethod, Expression.Constant("the ")); + MethodCallExpression strippedName = Expression.Call(lowerName, s_substringMethod, Expression.Constant(4)); + effectiveName = Expression.Condition(startsWithThe, strippedName, lowerName); + } + + return effectiveName; + } + + /// + /// Builds a predicate that is satisfied when the effective name starts with a glob pattern. + /// + /// The parameter representing the artist entity. + /// The expression of the effective name. + /// The glob pattern the effective name must match. + /// The built predicate. + private static Expression> BuildGlobPredicate(ParameterExpression artist, Expression effectiveName, string globPattern) + { + MethodCallExpression glob = BuildGlobCall(effectiveName, globPattern); + return Expression.Lambda>(glob, artist); + } + + /// + /// Builds a predicate that is satisfied when the first character of the effective name is neither a letter nor a digit. + /// + /// The parameter representing the artist entity. + /// The expression of the effective name. + /// The built predicate. + private static Expression> BuildSymbolPredicate(ParameterExpression artist, Expression effectiveName) + { + Expression notLetter = Expression.Not(BuildGlobCall(effectiveName, "[a-z]*")); + Expression notDigit = Expression.Not(BuildGlobCall(effectiveName, "[0-9]*")); + return Expression.Lambda>(Expression.AndAlso(notLetter, notDigit), artist); + } + + /// + /// Builds the call to for the effective name and the provided glob pattern. + /// + /// The expression of the effective name. + /// The glob pattern the effective name must match. + /// The built method call. + private static MethodCallExpression BuildGlobCall(Expression effectiveName, string globPattern) + { + Expression functions = Expression.Property(null, typeof(EF), nameof(EF.Functions)); + return Expression.Call(s_globMethod, functions, effectiveName, Expression.Constant(globPattern)); + } +} diff --git a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/TrackRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/TrackRepository.cs index 4837ccf2..a4bbe4ad 100644 --- a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/TrackRepository.cs +++ b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/TrackRepository.cs @@ -242,7 +242,7 @@ internal sealed class TrackRepository : ITrackRepository .Include(track => track.Contributors) .AsSplitQuery() .Where(track => track.AlbumId == albumId) - .OrderBy(track => track.DiscNumber) + .OrderBy(track => track.DiscNumber ?? 1) // some releases don't have a disc number, assume 1 .ThenBy(track => track.TrackNumber) .ThenBy(track => track.Id) .ToListAsync(cancellationToken).ConfigureAwait(false); @@ -262,7 +262,7 @@ internal sealed class TrackRepository : ITrackRepository IQueryable liteRowsQuery = _luminaDbContext.Tracks .AsNoTracking() .Where(track => track.AlbumId == albumId) - .OrderBy(track => track.DiscNumber) + .OrderBy(track => track.DiscNumber ?? 1) // some releases don't have a disc number, assume 1 .ThenBy(track => track.TrackNumber) .ThenBy(track => track.Id) .Select(track => new TrackLiteRow @@ -270,7 +270,8 @@ internal sealed class TrackRepository : ITrackRepository Id = track.Id, Title = track.Title, TrackNumber = track.TrackNumber, - DiscNumber = track.DiscNumber + DiscNumber = track.DiscNumber, + DurationInSeconds = track.DurationInSeconds }); if (paginationData is null) diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/AddAlbum/AddAlbumEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/AddAlbum/AddAlbumEndpointSummary.cs index 0ad7ef8f..fedd2b40 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/AddAlbum/AddAlbumEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/AddAlbum/AddAlbumEndpointSummary.cs @@ -373,6 +373,8 @@ public class AddAlbumEndpointSummary : Summary(r => r.Metadata!.Genres, "The list of genres associated with the album."); ResponseParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album."); ResponseParam(r => r.Tracks, "The list of tracks of the album."); + ResponseParam(r => r.CoverPath, "The path of the image representing the album, if available."); + ResponseParam(r => r.Artwork, "The stored artwork of the album, in display order, if applicable."); Response(201, "The newly created album is returned.", example: new AlbumResponse( diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/UpdateAlbum/UpdateAlbumEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/UpdateAlbum/UpdateAlbumEndpointSummary.cs index c2a2d4a1..2bf29528 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/UpdateAlbum/UpdateAlbumEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/UpdateAlbum/UpdateAlbumEndpointSummary.cs @@ -177,6 +177,8 @@ public class UpdateAlbumEndpointSummary : Summary(r => r.Metadata!.Genres, "The list of genres associated with the album."); ResponseParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album."); ResponseParam(r => r.Tracks, "The list of tracks of the album."); + ResponseParam(r => r.CoverPath, "The path of the image representing the album, if available."); + ResponseParam(r => r.Artwork, "The stored artwork of the album, in display order, if applicable."); Response(200, "The updated album is returned.", example: new AlbumResponse( diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/AddArtist/AddArtistEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/AddArtist/AddArtistEndpointSummary.cs index 728d1333..33ce2af1 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/AddArtist/AddArtistEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/AddArtist/AddArtistEndpointSummary.cs @@ -455,6 +455,8 @@ public class AddArtistEndpointSummary : Summary(r => r.Albums![0].Contributors, "The list of references to the media contributors that performed on the album, each with the role they played."); ResponseParam(r => r.Albums![0].Ratings, "The list of ratings for the album."); ResponseParam(r => r.Albums![0].Tracks, "The list of tracks of the album."); + ResponseParam(r => r.Albums![0].CoverPath, "The path of the image representing the album, if available."); + ResponseParam(r => r.Albums![0].Artwork, "The stored artwork of the album, in display order, if applicable."); ResponseParam(r => r.Albums![0].Tracks![0].Id, "The Id of the track."); ResponseParam(r => r.Albums![0].Tracks![0].AlbumId, "The Id of the album the track belongs to."); ResponseParam(r => r.Albums![0].Tracks![0].LibraryId, "The Id of the media library this track belongs to."); @@ -503,6 +505,7 @@ public class AddArtistEndpointSummary : Summary(r => r.Albums![0].Tracks![0].Ratings, "The list of ratings for the track."); ResponseParam(r => r.CreatedOnUtc, "The date and time when the artist was created."); ResponseParam(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable."); + ResponseParam(r => r.CoverPath, "The path of the image representing the artist, if available."); Response(201, "The new artist is returned.", example: new ArtistResponse( diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtist/GetArtistEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtist/GetArtistEndpointSummary.cs index fb2d67a0..0a93393c 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtist/GetArtistEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtist/GetArtistEndpointSummary.cs @@ -39,6 +39,7 @@ public class GetArtistEndpointSummary : Summary ResponseParam(r => r.Albums, "The list of albums of the artist, each with its own list of tracks."); ResponseParam(r => r.CreatedOnUtc, "The date and time when the artist was created."); ResponseParam(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable."); + ResponseParam(r => r.CoverPath, "The path of the image representing the artist, if available."); Response(200, "The requested artist is returned.", example: new ArtistResponse( diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistAlbums/GetArtistAlbumsEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistAlbums/GetArtistAlbumsEndpointSummary.cs index 274c3421..4d4546b0 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistAlbums/GetArtistAlbumsEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistAlbums/GetArtistAlbumsEndpointSummary.cs @@ -65,6 +65,8 @@ public class GetArtistAlbumsEndpointSummary : Summary(r => r.Metadata!.Genres, "The list of genres associated with the album."); ResponseParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album."); ResponseParam(r => r.Tracks, "The list of tracks of the album."); + ResponseParam(r => r.CoverPath, "The path of the image representing the album, if available."); + ResponseParam(r => r.Artwork, "The stored artwork of the album, in display order, if applicable."); Response(200, "The list of albums of the artist is returned.", example: new AlbumResponse[] diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistAlbumsLite/GetArtistAlbumsLiteEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistAlbumsLite/GetArtistAlbumsLiteEndpointSummary.cs index 20c6f4b7..5db7a2b5 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistAlbumsLite/GetArtistAlbumsLiteEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistAlbumsLite/GetArtistAlbumsLiteEndpointSummary.cs @@ -36,6 +36,9 @@ public class GetArtistAlbumsLiteEndpointSummary : Summary(r => r.Id, "The Id of the album."); ResponseParam(r => r.Title, "The title of the album."); ResponseParam(r => r.TotalTracks, "The number of tracks of the release."); + ResponseParam(r => r.CoverPath, "The path of the image representing the album, if available."); + ResponseParam(r => r.ReleaseYear, "The release year of the album (the re-release year, if available, or the original release year), if known."); + ResponseParam(r => r.ReleaseTypes, "The set of types of the release."); Response(200, "The paginated list of the lightweight read models of the albums of the artist is returned.", example: new PaginatedResponse diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtists/GetArtistsEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtists/GetArtistsEndpointSummary.cs index 5b367e6c..237b933d 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtists/GetArtistsEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtists/GetArtistsEndpointSummary.cs @@ -51,6 +51,7 @@ public class GetArtistsEndpointSummary : Summary(r => r.Albums, "The list of albums of the artist, each with its own list of tracks."); ResponseParam(r => r.CreatedOnUtc, "The date and time when the artist was created."); ResponseParam(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable."); + ResponseParam(r => r.CoverPath, "The path of the image representing the artist, if available."); Response(200, "The paginated list of the artists of the media library is returned.", example: new PaginatedResponse diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistsLite/GetArtistsLiteEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistsLite/GetArtistsLiteEndpointSummary.cs index d59bf629..6fe50088 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistsLite/GetArtistsLiteEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistsLite/GetArtistsLiteEndpointSummary.cs @@ -39,12 +39,13 @@ public class GetArtistsLiteEndpointSummary : Summary 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."); RequestParam(r => r.FilterAlphaKey, "The alpha key used to filter the artists by the first character of their name, for the alpha picker. Optional."); - RequestParam(r => r.ShouldIgnoreThePrefixForAlphaPicker, "Whether the leading \"The \" prefix of a name is ignored when computing the alpha key, or not."); + RequestParam(r => r.ShouldIgnoreThePrefixForAlphaPicker, "Whether the leading \"The \" prefix of a name is ignored when computing the alpha key, or not. Optional."); RequestParam(r => r.SortBy, "The name of the field by which to sort the results. Optional."); RequestParam(r => r.SortOrder, "The direction in which to sort the results. Optional."); ResponseParam(r => r.Id, "The Id of the artist."); ResponseParam(r => r.Name, "The name of the artist."); + ResponseParam(r => r.CoverPath, "The path of the image representing the artist, if available."); Response(200, "The paginated list of the lightweight read models of the artists is returned.", example: new PaginatedResponse diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/UpdateArtist/UpdateArtistEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/UpdateArtist/UpdateArtistEndpointSummary.cs index 15272a36..07a978c1 100644 --- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/UpdateArtist/UpdateArtistEndpointSummary.cs +++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/UpdateArtist/UpdateArtistEndpointSummary.cs @@ -454,6 +454,8 @@ public class UpdateArtistEndpointSummary : Summary(r => r.Albums![0].Contributors, "The list of references to the media contributors that performed on the album, each with the role they played."); ResponseParam(r => r.Albums![0].Ratings, "The list of ratings for the album."); ResponseParam(r => r.Albums![0].Tracks, "The list of tracks of the album."); + ResponseParam(r => r.Albums![0].CoverPath, "The path of the image representing the album, if available."); + ResponseParam(r => r.Albums![0].Artwork, "The stored artwork of the album, in display order, if applicable."); ResponseParam(r => r.Albums![0].Tracks![0].Id, "The Id of the track."); ResponseParam(r => r.Albums![0].Tracks![0].AlbumId, "The Id of the album the track belongs to."); ResponseParam(r => r.Albums![0].Tracks![0].LibraryId, "The Id of the media library this track belongs to."); @@ -502,6 +504,7 @@ public class UpdateArtistEndpointSummary : Summary(r => r.Albums![0].Tracks![0].Ratings, "The list of ratings for the track."); ResponseParam(r => r.CreatedOnUtc, "The date and time when the artist was created."); ResponseParam(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable."); + ResponseParam(r => r.CoverPath, "The path of the image representing the artist, if available."); Guid artistId = Guid.NewGuid(); Guid libraryId = Guid.NewGuid(); diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRowFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRowFixture.cs index 1e717757..408dc94b 100644 --- a/tests/Common/Lumina.Application.Fixtures/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRowFixture.cs +++ b/tests/Common/Lumina.Application.Fixtures/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRowFixture.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Bogus; using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Albums; +using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -15,6 +16,9 @@ namespace Lumina.Application.Fixtures.Common.DTO.MediaLibrary.AudioLibrary.Music [ExcludeFromCodeCoverage] public class AlbumLiteRowFixture { + private const int MINIMUM_RELEASE_YEAR = 1900; + private const int MAXIMUM_RELEASE_YEAR = 2026; + private readonly Faker _faker = new(); /// @@ -23,17 +27,32 @@ public class AlbumLiteRowFixture /// Optional. The Id of the album. /// Optional. The title of the album. /// Optional. The number of tracks of the release. + /// Optional. The path of the image representing the album. + /// Optional. The release year of the album. + /// Optional. The set of types of the release. + /// Whether the cover path should be included, or forced to . + /// Whether the release year should be included, or forced to . + /// Whether the release types should be included, or forced to . /// The created . public AlbumLiteRow Create( Guid? id = null, string? title = null, - int? totalTracks = null) + int? totalTracks = null, + string? coverPath = null, + int? releaseYear = null, + List? releaseTypes = null, + bool includeCoverPath = true, + bool includeReleaseYear = true, + bool includeReleaseTypes = true) { return new AlbumLiteRow { Id = id ?? _faker.Random.Guid(), Title = title ?? _faker.Music.Genre(), - TotalTracks = totalTracks ?? _faker.Random.Int(1, 30) + TotalTracks = totalTracks ?? _faker.Random.Int(1, 30), + CoverPath = includeCoverPath ? (coverPath ?? _faker.System.FilePath()) : null, + ReleaseYear = includeReleaseYear ? (releaseYear ?? _faker.Random.Int(MINIMUM_RELEASE_YEAR, MAXIMUM_RELEASE_YEAR)) : null, + ReleaseTypes = includeReleaseTypes ? (releaseTypes ?? [.. Enumerable.Range(0, _faker.Random.Int(1, 3)).Select(index => _faker.PickRandom())]) : null }; } diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRowFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRowFixture.cs index 671ca538..708c4ac0 100644 --- a/tests/Common/Lumina.Application.Fixtures/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRowFixture.cs +++ b/tests/Common/Lumina.Application.Fixtures/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRowFixture.cs @@ -22,15 +22,20 @@ public class ArtistLiteRowFixture /// /// Optional. The Id of the artist. /// Optional. The name of the artist. + /// Optional. The path of the image representing the artist. + /// Whether the cover path should be included, or forced to . /// The created . public ArtistLiteRow Create( Guid? id = null, - string? name = null) + string? name = null, + string? coverPath = null, + bool includeCoverPath = true) { return new ArtistLiteRow { Id = id ?? _faker.Random.Guid(), - Name = name ?? _faker.Name.FullName() + Name = name ?? _faker.Name.FullName(), + CoverPath = includeCoverPath ? (coverPath ?? _faker.System.FilePath()) : null }; } diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRowFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRowFixture.cs index d7414256..d942eac7 100644 --- a/tests/Common/Lumina.Application.Fixtures/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRowFixture.cs +++ b/tests/Common/Lumina.Application.Fixtures/Common/DTO/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRowFixture.cs @@ -25,20 +25,23 @@ public class TrackLiteRowFixture /// Optional. The number of the track on its disc. /// Optional. The number of the disc the track belongs to. /// Whether the disc number should be included, or forced to . + /// Optional. The duration of the track in seconds. /// The created . public TrackLiteRow Create( Guid? id = null, string? title = null, int? trackNumber = null, int? discNumber = null, - bool includeDiscNumber = true) + bool includeDiscNumber = true, + int? durationInSeconds = null) { return new TrackLiteRow { Id = id ?? _faker.Random.Guid(), Title = title ?? _faker.Lorem.Sentence(), TrackNumber = trackNumber ?? _faker.Random.Int(1, 30), - DiscNumber = includeDiscNumber ? (discNumber ?? _faker.Random.Int(1, 3)) : null + DiscNumber = includeDiscNumber ? (discNumber ?? _faker.Random.Int(1, 3)) : null, + DurationInSeconds = durationInSeconds ?? _faker.Random.Int(1, 600) }; } diff --git a/tests/Common/Lumina.Application.Fixtures/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryFixture.cs b/tests/Common/Lumina.Application.Fixtures/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryFixture.cs index 7e6ddb02..265559df 100644 --- a/tests/Common/Lumina.Application.Fixtures/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryFixture.cs +++ b/tests/Common/Lumina.Application.Fixtures/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryFixture.cs @@ -3,6 +3,7 @@ using Bogus; using Lumina.Application.Common.DTO.Pagination; using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtistsLite; using Lumina.Application.Fixtures.Common.DTO.Pagination; +using Lumina.Domain.SharedKernel.Common.Enums.Common; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -26,6 +27,10 @@ public class GetArtistsLiteQueryFixture /// Optional. The Id of the media library whose artists are retrieved, taken from the route. /// Optional. The pagination data of the query. /// Optional. The search term used to filter the artists by name. + /// Optional. The alpha key used to filter the results by the first character of their name, for the alpha picker. + /// Optional. Whether the leading "The " prefix of a name should be ignored when computing the alpha key, or not. + /// Optional. The name of the field by which to sort the results. + /// Optional. The direction in which to sort the results. /// Whether the library Id should be included, or forced to . /// Whether the pagination data should be included, or forced to . /// Whether the search term should be included, or forced to . @@ -34,6 +39,10 @@ public class GetArtistsLiteQueryFixture string? libraryId = null, PaginationDataDto? paginationData = null, string? searchTerm = null, + string? filterAlphaKey = null, + bool shouldIgnoreThePrefixForAlphaPicker = false, + string? sortBy = null, + SortOrder? sortOrder = null, bool includeLibraryId = true, bool includePaginationData = true, bool includeSearchTerm = true) @@ -41,7 +50,11 @@ public class GetArtistsLiteQueryFixture return new GetArtistsLiteQuery( includeLibraryId ? (libraryId ?? Guid.NewGuid().ToString()) : null, includePaginationData ? (paginationData ?? _paginationDataDtoFixture.Create()) : null, - includeSearchTerm ? (searchTerm ?? _faker.Name.FullName()) : null); + includeSearchTerm ? (searchTerm ?? _faker.Name.FullName()) : null, + filterAlphaKey, + shouldIgnoreThePrefixForAlphaPicker, + sortBy ?? _faker.Lorem.Word(), + sortOrder ?? _faker.PickRandom()); } /// diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/DTO/Common/MediaArtworkDtoFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/DTO/Common/MediaArtworkDtoFixture.cs new file mode 100644 index 00000000..5fbe5a26 --- /dev/null +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/DTO/Common/MediaArtworkDtoFixture.cs @@ -0,0 +1,47 @@ +#region ========================================================================= USING ===================================================================================== +using Bogus; +using Lumina.Contracts.DTO.Common; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +#endregion + +namespace Lumina.Contracts.Fixtures.Core.DTO.Common; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class MediaArtworkDtoFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The type of the artwork. + /// Optional. The ordinal of the artwork within its type. + /// Optional. The relative path of the stored artwork file. + /// The created . + public MediaArtworkDto Create( + ArtworkType? type = null, + int? ordinal = null, + string? path = null) + { + return new MediaArtworkDto( + type ?? _faker.PickRandom(), + ordinal ?? _faker.Random.Int(0, 5), + path ?? _faker.System.FilePath()); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequestFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequestFixture.cs index c513da38..f672225c 100644 --- a/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequestFixture.cs +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequestFixture.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Bogus; using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists; +using Lumina.Domain.SharedKernel.Common.Enums.Common; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; @@ -22,22 +23,40 @@ public class GetArtistsLiteRequestFixture /// Optional. The page of results to retrieve. /// Optional. The maximum number of artists to retrieve per page. /// Optional. The search term used to filter the artists by name. + /// Optional. The alpha key used to filter the results by the first character of their name, for the alpha picker. + /// Optional. Whether the leading "The " prefix of a name should be ignored when computing the alpha key, or not. + /// Optional. The name of the field by which to sort the results. + /// Optional. The direction in which to sort the results. /// Whether the current page should be included, or forced to . /// Whether the per page count should be included, or forced to . /// Whether the search term should be included, or forced to . + /// Whether the filter alpha key should be included, or forced to . + /// Whether the sort field should be included, or forced to . + /// Whether the sort order should be included, or forced to . /// The created request to get the lightweight read models of the artists of a media library. public GetArtistsLiteRequest Create( int? currentPage = null, int? perPage = null, string? searchTerm = null, + string? filterAlphaKey = null, + bool shouldIgnoreThePrefixForAlphaPicker = false, + string? sortBy = null, + SortOrder? sortOrder = null, bool includeCurrentPage = true, bool includePerPage = true, - bool includeSearchTerm = true) + bool includeSearchTerm = true, + bool includeFilterAlphaKey = true, + bool includeSortBy = true, + bool includeSortOrder = true) { return new GetArtistsLiteRequest( includeCurrentPage ? (currentPage ?? _faker.Random.Number(1, 100)) : null, includePerPage ? (perPage ?? _faker.Random.Number(1, 200)) : null, - includeSearchTerm ? (searchTerm ?? _faker.Name.FullName()) : null); + includeSearchTerm ? (searchTerm ?? _faker.Name.FullName()) : null, + includeFilterAlphaKey ? (filterAlphaKey ?? CreateFilterAlphaKey()) : null, + shouldIgnoreThePrefixForAlphaPicker, + includeSortBy ? (sortBy ?? _faker.Lorem.Word()) : null, + includeSortOrder ? (sortOrder ?? _faker.PickRandom()) : null); } /// @@ -49,4 +68,15 @@ public class GetArtistsLiteRequestFixture { return [.. Enumerable.Range(0, count).Select(_ => Create())]; } + + /// + /// Creates a random valid alpha key: a single ASCII letter, "#" for names starting with a digit, or "*" for any other first character. + /// + /// The created alpha key. + private string CreateFilterAlphaKey() + { + return _faker.Random.Bool() + ? _faker.Random.Char('A', 'Z').ToString() + : _faker.Random.ListItem(new[] { "#", "*" }); + } } diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteResponseFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteResponseFixture.cs index 5fc48178..ff44ed55 100644 --- a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteResponseFixture.cs +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteResponseFixture.cs @@ -1,6 +1,7 @@ #region ========================================================================= USING ===================================================================================== using Bogus; using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums; +using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; @@ -23,16 +24,35 @@ public class AlbumLiteResponseFixture /// Optional. The Id of the album. /// Optional. The title of the album. /// Optional. The number of tracks of the release. + /// Optional. The path of the image representing the album. + /// Optional. The release year of the album. + /// Optional. The set of types of the release. + /// Whether the cover path should be included, or forced to . + /// Whether the release year should be included, or forced to . + /// Whether the release types should be included, or forced to . /// The created . public AlbumLiteResponse Create( Guid? id = null, string? title = null, - int? totalTracks = null) + int? totalTracks = null, + string? coverPath = null, + int? releaseYear = null, + List? releaseTypes = null, + bool includeCoverPath = true, + bool includeReleaseYear = true, + bool includeReleaseTypes = true) { + List? resolvedReleaseTypes = includeReleaseTypes + ? (releaseTypes ?? [.. Enumerable.Range(0, _faker.Random.Int(1, 3)).Select(_ => _faker.PickRandom())]) + : null; + return new AlbumLiteResponse( id ?? Guid.NewGuid(), title ?? _faker.Commerce.ProductName(), - totalTracks ?? _faker.Random.Int(1, 30)); + totalTracks ?? _faker.Random.Int(1, 30), + includeCoverPath ? (coverPath ?? _faker.System.FilePath()) : null, + includeReleaseYear ? (releaseYear ?? _faker.Random.Int(1900, 2026)) : null, + resolvedReleaseTypes); } /// diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumResponseFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumResponseFixture.cs index 653ec988..e66d1921 100644 --- a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumResponseFixture.cs +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumResponseFixture.cs @@ -1,8 +1,10 @@ #region ========================================================================= USING ===================================================================================== using Bogus; +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.Fixtures.Core.DTO.Common; using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors; using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary; using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary; @@ -29,6 +31,7 @@ public class AlbumResponseFixture private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new(); private readonly AudioRatingDtoFixture _audioRatingDtoFixture = new(); private readonly TrackResponseFixture _trackResponseFixture = new(); + private readonly MediaArtworkDtoFixture _mediaArtworkDtoFixture = new(); /// /// Creates a random valid . @@ -51,6 +54,8 @@ public class AlbumResponseFixture /// Optional. The list of contributor references of the album. /// Optional. The list of ratings of the album. /// Optional. The list of tracks of the album. + /// Optional. The path of the image representing the album. + /// Optional. The stored artwork of the album, in display order. /// Whether the media format should be included, or forced to . /// Whether the packaging should be included, or forced to . /// Whether the barcode should be included, or forced to . @@ -64,6 +69,8 @@ public class AlbumResponseFixture /// Whether the contributors should be included, or forced to . /// Whether the ratings should be included, or forced to . /// Whether the tracks should be included, or forced to . + /// Whether the cover path should be included, or forced to . + /// Whether the artwork should be included, or forced to an empty collection. /// The created . public AlbumResponse Create( Guid? id = null, @@ -84,6 +91,8 @@ public class AlbumResponseFixture List? contributors = null, List? ratings = null, List? tracks = null, + string? coverPath = null, + List? artwork = null, bool includeMediaFormat = true, bool includePackaging = true, bool includeBarcode = true, @@ -96,8 +105,14 @@ public class AlbumResponseFixture bool includeUpdatedOnUtc = true, bool includeContributors = true, bool includeRatings = true, - bool includeTracks = true) + bool includeTracks = true, + bool includeCoverPath = true, + bool includeArtwork = true) { + IReadOnlyList resolvedArtwork = includeArtwork + ? (artwork ?? _mediaArtworkDtoFixture.CreateMany(1)) + : []; + return new AlbumResponse( id ?? Guid.NewGuid(), artistId ?? Guid.NewGuid(), @@ -116,7 +131,9 @@ public class AlbumResponseFixture includeUpdatedOnUtc ? (updatedOnUtc ?? _faker.Date.Recent().ToUniversalTime()) : null, includeContributors ? (contributors ?? _mediaContributorReferenceDtoFixture.CreateMany(1)) : null, includeRatings ? (ratings ?? _audioRatingDtoFixture.CreateMany(1)) : null, - includeTracks ? (tracks ?? _trackResponseFixture.CreateMany(1)) : null); + includeTracks ? (tracks ?? _trackResponseFixture.CreateMany(1)) : null, + includeCoverPath ? (coverPath ?? _faker.System.FilePath()) : null, + resolvedArtwork); } /// diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteResponseFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteResponseFixture.cs index 5bbde1f8..d490c429 100644 --- a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteResponseFixture.cs +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteResponseFixture.cs @@ -22,14 +22,19 @@ public class ArtistLiteResponseFixture /// /// Optional. The Id of the artist. /// Optional. The name of the artist. + /// Optional. The path of the image representing the artist. + /// Whether the cover path should be included, or forced to . /// The created . public ArtistLiteResponse Create( Guid? id = null, - string? name = null) + string? name = null, + string? coverPath = null, + bool includeCoverPath = true) { return new ArtistLiteResponse( id ?? Guid.NewGuid(), - name ?? _faker.Name.FullName()); + name ?? _faker.Name.FullName(), + includeCoverPath ? (coverPath ?? _faker.System.FilePath()) : null); } /// diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistResponseFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistResponseFixture.cs index f22f8359..3f0d94aa 100644 --- a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistResponseFixture.cs +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistResponseFixture.cs @@ -44,6 +44,7 @@ public class ArtistResponseFixture /// Optional. The list of albums of the artist. /// Optional. The date and time when the artist was created. /// Optional. The date and time when the artist was updated. + /// Optional. The path of the image representing the artist. /// Whether the website should be included, or forced to . /// Whether the MusicBrainz artist Id should be included, or forced to . /// Whether the IPI codes should be included, or forced to . @@ -52,6 +53,7 @@ public class ArtistResponseFixture /// Whether the contributors should be included, or forced to . /// Whether the ratings should be included, or forced to . /// Whether the albums should be included, or forced to . + /// Whether the cover path should be included, or forced to . /// The created . public ArtistResponse Create( Guid? id = null, @@ -66,6 +68,7 @@ public class ArtistResponseFixture List? albums = null, DateTime? createdOnUtc = null, DateTime? updatedOnUtc = null, + string? coverPath = null, bool includeWebsite = true, bool includeMusicBrainzArtistId = true, bool includeIpis = true, @@ -73,7 +76,8 @@ public class ArtistResponseFixture bool includeUpdatedOnUtc = true, bool includeContributors = true, bool includeRatings = true, - bool includeAlbums = true) + bool includeAlbums = true, + bool includeCoverPath = true) { return new ArtistResponse( id ?? Guid.NewGuid(), @@ -87,7 +91,8 @@ public class ArtistResponseFixture includeUpdatedOnUtc ? (updatedOnUtc ?? _faker.Date.Recent().ToUniversalTime()) : null, includeContributors ? (contributors ?? _mediaContributorReferenceDtoFixture.CreateMany(1)) : null, includeRatings ? (ratings ?? _audioRatingDtoFixture.CreateMany(1)) : null, - includeAlbums ? (albums ?? _albumResponseFixture.CreateMany(1)) : null); + includeAlbums ? (albums ?? _albumResponseFixture.CreateMany(1)) : null, + includeCoverPath ? (coverPath ?? _faker.System.FilePath()) : null); } /// diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteResponseFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteResponseFixture.cs index 4118f4ec..d997e06d 100644 --- a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteResponseFixture.cs +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteResponseFixture.cs @@ -25,19 +25,22 @@ public class TrackLiteResponseFixture /// Optional. The number of the track on its disc. /// Optional. The number of the disc the track belongs to. /// Whether the disc number should be included, or forced to . + /// Optional. The duration of the track in seconds. /// The created . public TrackLiteResponse Create( Guid? id = null, string? title = null, int? trackNumber = null, int? discNumber = null, - bool includeDiscNumber = true) + bool includeDiscNumber = true, + int? durationInSeconds = null) { return new TrackLiteResponse( id ?? _faker.Random.Guid(), title ?? _faker.Lorem.Sentence(), trackNumber ?? _faker.Random.Int(1, 30), - includeDiscNumber ? (discNumber ?? _faker.Random.Int(1, 3)) : null); + includeDiscNumber ? (discNumber ?? _faker.Random.Int(1, 3)) : null, + durationInSeconds ?? _faker.Random.Int(1, 600)); } /// diff --git a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/AlbumRepositoryTests.cs b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/AlbumRepositoryTests.cs index a6cdd694..e65ef9a3 100644 --- a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/AlbumRepositoryTests.cs +++ b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/AlbumRepositoryTests.cs @@ -15,6 +15,7 @@ using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Primitives; using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using NSubstitute; @@ -44,6 +45,7 @@ public class AlbumRepositoryTests private readonly TagEntityFixture _tagEntityFixture = new(); private readonly GenreEntityFixture _genreEntityFixture = new(); private readonly ArtistEntityFixture _artistEntityFixture = new(); + private readonly MusicArtworkEntityFixture _musicArtworkEntityFixture = new(); private readonly PaginationDataDtoFixture _paginationDataDtoFixture = new(); [Fact] @@ -601,6 +603,112 @@ public class AlbumRepositoryTests Assert.Equal(expectedRowCount, result.Value.Data.Count); } + [Fact] + public async Task GetAlbumsLiteByArtistIdAsync_WhenReReleaseYearIsSet_ShouldProjectItAsReleaseYear() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-albumrepo-lite-releaseyear-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + AlbumRepository sut = CreateAlbumRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity artist = await SeedArtistAsync(context, libraryId); + AlbumEntity album = _albumEntityFixture.Create( + artistId: artist.Id, libraryId: libraryId, originalReleaseYear: 1975, reReleaseYear: 2011, includeTracks: false, includeMetadata: false); + context.Albums.Add(album); + await context.SaveChangesAsync(); + + // Act + Result> result = await sut.GetAlbumsLiteByArtistIdAsync(artist.Id, null, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + AlbumLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal(2011, row.ReleaseYear); + } + + [Fact] + public async Task GetAlbumsLiteByArtistIdAsync_WhenReReleaseYearIsNull_ShouldFallBackToOriginalReleaseYear() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-albumrepo-lite-originalyear-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + AlbumRepository sut = CreateAlbumRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity artist = await SeedArtistAsync(context, libraryId); + AlbumEntity album = _albumEntityFixture.Create( + artistId: artist.Id, libraryId: libraryId, originalReleaseYear: 1975, includeReReleaseYear: false, includeTracks: false, includeMetadata: false); + context.Albums.Add(album); + await context.SaveChangesAsync(); + + // Act + Result> result = await sut.GetAlbumsLiteByArtistIdAsync(artist.Id, null, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + AlbumLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal(1975, row.ReleaseYear); + } + + [Fact] + public async Task GetAlbumsLiteByArtistIdAsync_WhenTheReleaseHasTypes_ShouldProjectThem() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-albumrepo-lite-releasetypes-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + AlbumRepository sut = CreateAlbumRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity artist = await SeedArtistAsync(context, libraryId); + AlbumEntity album = _albumEntityFixture.Create( + artistId: artist.Id, libraryId: libraryId, releaseType: MusicReleaseType.Single, includeTracks: false, includeMetadata: false); + context.Albums.Add(album); + await context.SaveChangesAsync(); + + // Act + Result> result = await sut.GetAlbumsLiteByArtistIdAsync(artist.Id, null, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + AlbumLiteRow row = Assert.Single(result.Value.Data); + Assert.NotNull(row.ReleaseTypes); + Assert.Equal(MusicReleaseType.Single, Assert.Single(row.ReleaseTypes)); + } + + [Fact] + public async Task GetAlbumsLiteByArtistIdAsync_WhenCoverArtworkExists_ShouldProjectTheCoverPath() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-albumrepo-lite-cover-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + AlbumRepository sut = CreateAlbumRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity artist = await SeedArtistAsync(context, libraryId); + AlbumEntity album = _albumEntityFixture.Create(artistId: artist.Id, libraryId: libraryId, includeTracks: false, includeMetadata: false); + context.Albums.Add(album); + context.MusicArtwork.Add( + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: album.Id, artworkType: ArtworkType.Cover, fileName: "covers/opera.jpg")); + await context.SaveChangesAsync(); + + // Act + Result> result = await sut.GetAlbumsLiteByArtistIdAsync(artist.Id, null, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + AlbumLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal("covers/opera.jpg", row.CoverPath); + } + /// /// Creates an album repository backed by the provided context, wiring the real track repository. /// diff --git a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/ArtistRepositoryTests.cs b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/ArtistRepositoryTests.cs index 3aae0a38..7baeee66 100644 --- a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/ArtistRepositoryTests.cs +++ b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/ArtistRepositoryTests.cs @@ -17,6 +17,7 @@ using Lumina.Domain.Common.Errors; using Lumina.Domain.Common.Primitives; using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary; using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors; +using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; @@ -51,6 +52,7 @@ public class ArtistRepositoryTests private readonly GenreEntityFixture _genreEntityFixture = new(); private readonly PaginationDataDtoFixture _paginationDataDtoFixture = new(); private readonly LibraryFilterDtoFixture _libraryFilterDtoFixture = new(); + private readonly MusicArtworkEntityFixture _musicArtworkEntityFixture = new(); [Fact] public async Task InsertAsync_WhenCalledWithAValidArtist_ShouldPersistTheArtistAndItsAggregate() @@ -1079,6 +1081,257 @@ public class ArtistRepositoryTests Assert.Equal(keptTrackContributor.Id, Assert.Single(storedTrack.Contributors).Id); } + [Fact] + public async Task DeleteByLibraryIdAsync_WhenCalled_ShouldDeleteOnlyTheLibraryArtistsAndTheirChildren() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-deletebylibrary-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + ArtistRepository sut = CreateArtistRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity targetArtist = await SeedArtistAsync(context, libraryId, "Queen"); + AlbumEntity targetAlbum = await SeedAlbumAsync(context, libraryId, targetArtist.Id); + context.Tracks.Add(_trackEntityFixture.Create(albumId: targetAlbum.Id, libraryId: libraryId, includeMetadata: false)); + ArtistEntity artistOfAnotherLibrary = await SeedArtistAsync(context, Guid.NewGuid(), "Pink Floyd"); + await context.SaveChangesAsync(); + + // Act + Result result = await sut.DeleteByLibraryIdAsync(libraryId, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal(Result.Deleted, result.Value); + context.ChangeTracker.Clear(); + // Only the artists of the target library are deleted, and the database cascade removes their albums and tracks. + ArtistEntity survivor = Assert.Single(await context.Artists.AsNoTracking().ToListAsync()); + Assert.Equal(artistOfAnotherLibrary.Id, survivor.Id); + Assert.Empty(await context.Albums.AsNoTracking().Where(candidate => candidate.LibraryId == libraryId).ToListAsync()); + Assert.Empty(await context.Tracks.AsNoTracking().Where(candidate => candidate.LibraryId == libraryId).ToListAsync()); + } + + [Fact] + public async Task GetAllLiteAsync_WhenAlphaKeyIsTheNumberKey_ShouldMatchOnlyNamesStartingWithADigit() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-alpha-number-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + ArtistRepository sut = CreateArtistRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity numericArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "1984", includeAlbums: false, includeContributors: false); + ArtistEntity letterArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Alpha", includeAlbums: false, includeContributors: false); + ArtistEntity symbolArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "!Voyager", includeAlbums: false, includeContributors: false); + context.Artists.AddRange(numericArtist, letterArtist, symbolArtist); + await context.SaveChangesAsync(); + + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, filterAlphaKey: LibraryItemAlphaKeys.NUMBER); + + // Act + Result> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + ArtistLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal("1984", row.Name); + } + + [Fact] + public async Task GetAllLiteAsync_WhenAlphaKeyIsTheSymbolKey_ShouldMatchOnlyNamesStartingWithASymbol() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-alpha-symbol-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + ArtistRepository sut = CreateArtistRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity symbolArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "!Voyager", includeAlbums: false, includeContributors: false); + ArtistEntity numericArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "1984", includeAlbums: false, includeContributors: false); + ArtistEntity letterArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Alpha", includeAlbums: false, includeContributors: false); + context.Artists.AddRange(symbolArtist, numericArtist, letterArtist); + await context.SaveChangesAsync(); + + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, filterAlphaKey: LibraryItemAlphaKeys.SYMBOL); + + // Act + Result> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + ArtistLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal("!Voyager", row.Name); + } + + [Fact] + public async Task GetAllLiteAsync_WhenAlphaKeyIsALetter_ShouldMatchOnlyNamesStartingWithIt() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-alpha-letter-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + ArtistRepository sut = CreateArtistRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity alphaArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Alpha", includeAlbums: false, includeContributors: false); + ArtistEntity bravoArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Bravo", includeAlbums: false, includeContributors: false); + ArtistEntity charlieArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Charlie", includeAlbums: false, includeContributors: false); + context.Artists.AddRange(alphaArtist, bravoArtist, charlieArtist); + await context.SaveChangesAsync(); + + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, filterAlphaKey: "b"); + + // Act + Result> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + ArtistLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal("Bravo", row.Name); + } + + [Fact] + public async Task GetAllLiteAsync_WhenSearchTermAndAlphaKeyAreProvided_ShouldCombineThemWithAnd() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-search-alpha-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + ArtistRepository sut = CreateArtistRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity matchingArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Alpha Band", includeAlbums: false, includeContributors: false); + ArtistEntity artistMatchingOnlyTheAlphaKey = _artistEntityFixture.Create(libraryId: libraryId, name: "Adele", includeAlbums: false, includeContributors: false); + ArtistEntity artistMatchingOnlyTheSearchTerm = _artistEntityFixture.Create(libraryId: libraryId, name: "Beta Band", includeAlbums: false, includeContributors: false); + context.Artists.AddRange(matchingArtist, artistMatchingOnlyTheAlphaKey, artistMatchingOnlyTheSearchTerm); + await context.SaveChangesAsync(); + + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, searchTerm: "Band", filterAlphaKey: "a"); + + // Act + Result> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + ArtistLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal(matchingArtist.Id, row.Id); + } + + [Fact] + public async Task GetAllLiteAsync_WhenIgnoringThePrefix_ShouldFilterOnTheStrippedName() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-alpha-the-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + ArtistRepository sut = CreateArtistRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity beatlesArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "The Beatles", includeAlbums: false, includeContributors: false); + ArtistEntity adeleArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Adele", includeAlbums: false, includeContributors: false); + context.Artists.AddRange(beatlesArtist, adeleArtist); + await context.SaveChangesAsync(); + + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, filterAlphaKey: "b", shouldIgnoreThePrefixForAlphaPicker: true); + + // Act + Result> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + ArtistLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal("The Beatles", row.Name); + } + + [Fact] + public async Task GetAllLiteAsync_WhenNotIgnoringThePrefix_ShouldFilterOnTheFullName() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-alpha-the-off-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + ArtistRepository sut = CreateArtistRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity beatlesArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "The Beatles", includeAlbums: false, includeContributors: false); + ArtistEntity adeleArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Adele", includeAlbums: false, includeContributors: false); + context.Artists.AddRange(beatlesArtist, adeleArtist); + await context.SaveChangesAsync(); + + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, filterAlphaKey: "b", shouldIgnoreThePrefixForAlphaPicker: false); + + // Act + Result> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Empty(result.Value.Data); + } + + [Fact] + public async Task GetAllLiteAsync_WhenIgnoringThePrefixForSorting_ShouldSortByTheStrippedName() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-sort-the-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + ArtistRepository sut = CreateArtistRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity beneathArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Beneath the Surface", includeAlbums: false, includeContributors: false); + ArtistEntity beatlesArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "The Beatles", includeAlbums: false, includeContributors: false); + context.Artists.AddRange(beneathArtist, beatlesArtist); + await context.SaveChangesAsync(); + + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, shouldIgnoreThePrefixForAlphaPicker: true); + + // Act + Result> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + // With the prefix stripped, the sort key of "The Beatles" is "beatles", which sorts before "beneath". + Assert.Equal(["The Beatles", "Beneath the Surface"], result.Value.Data.Select(row => row.Name)); + } + + [Fact] + public async Task GetAllLiteAsync_WhenCoverArtworkExists_ShouldReturnItsPath() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-artistrepo-lite-cover-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + ArtistRepository sut = CreateArtistRepository(context); + + Guid libraryId = Guid.NewGuid(); + ArtistEntity artist = _artistEntityFixture.Create(libraryId: libraryId, name: "Queen", includeAlbums: false, includeContributors: false); + context.Artists.Add(artist); + context.MusicArtwork.Add( + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Artist, ownerId: artist.Id, artworkType: ArtworkType.Cover, fileName: "covers/queen.jpg")); + await context.SaveChangesAsync(); + + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId); + + // Act + Result> result = await sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + ArtistLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal("covers/queen.jpg", row.CoverPath); + } + /// /// Seeds an artist that owns the requested number of albums, each with the requested number of tracks, all of them with distinct shared reference names. /// diff --git a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/Specifications/ArtistAlphaFilterSpecificationTests.cs b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/Specifications/ArtistAlphaFilterSpecificationTests.cs new file mode 100644 index 00000000..52eaaf2d --- /dev/null +++ b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/Specifications/ArtistAlphaFilterSpecificationTests.cs @@ -0,0 +1,235 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.Application.Common.DTO.Filtering; +using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary; +using Lumina.DataAccess.Core.Repositories.MusicLibrary.Specifications; +using Lumina.DataAccess.Core.UoW; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +#endregion + +namespace Lumina.DataAccess.IntegrationTests.Core.Repositories.MusicLibrary.Specifications; + +/// +/// Contains integration tests for the class, exercising it against a real SQLite database. +/// +[ExcludeFromCodeCoverage] +public class ArtistAlphaFilterSpecificationTests : IDisposable +{ + private readonly SqliteConnection _connection; + private readonly LuminaDbContext _context; + private readonly ArtistEntityFixture _artistEntityFixture = new(); + + /// + /// Initializes a new instance of the class. + /// + public ArtistAlphaFilterSpecificationTests() + { + // The specification translates to the SQLite glob() function, so it can only be exercised against a real SQLite database. + _connection = new SqliteConnection("Data Source=:memory:"); + _connection.Open(); + _context = new LuminaDbContext(new DbContextOptionsBuilder().UseSqlite(_connection).Options); + _context.Database.EnsureCreated(); + } + + [Fact] + public void ToExpression_WhenAlphaKeyIsNull_ShouldMatchEveryArtist() + { + // Arrange + List artists = SeedArtists("Alpha", "Beta", "1984"); + ArtistAlphaFilterSpecification specification = new(null, false); + + // Act + List result = [.. _context.Artists.Where(specification.ToExpression())]; + + // Assert + Assert.Equal(artists.Count, result.Count); + } + + [Fact] + public void ToExpression_WhenAlphaKeyIsALowercaseLetter_ShouldMatchOnlyArtistsWhoseNameStartsWithIt() + { + // Arrange + SeedArtists("Foo Fighters", "Helloween", "The Beatles"); + ArtistAlphaFilterSpecification specification = new("f", false); + + // Act + List result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)]; + + // Assert + Assert.Equal(["Foo Fighters"], result); + } + + [Fact] + public void ToExpression_WhenAlphaKeyIsAnUppercaseLetter_ShouldMatchArtistsWhoseNameStartsWithItsLowercase() + { + // Arrange + SeedArtists("Foo Fighters", "Helloween"); + ArtistAlphaFilterSpecification specification = new("F", false); + + // Act + List result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)]; + + // Assert + Assert.Equal(["Foo Fighters"], result); + } + + [Fact] + public void ToExpression_WhenNoNameStartsWithTheAlphaKey_ShouldNotMatchAnyArtist() + { + // Arrange + SeedArtists("Foo Fighters", "Helloween"); + ArtistAlphaFilterSpecification specification = new("z", false); + + // Act + List result = [.. _context.Artists.Where(specification.ToExpression())]; + + // Assert + Assert.Empty(result); + } + + [Fact] + public void ToExpression_WhenAlphaKeyIsTheNumberKey_ShouldMatchOnlyArtistsWhoseNameStartsWithADigit() + { + // Arrange + SeedArtists("1984", "Alpha", "Beta"); + ArtistAlphaFilterSpecification specification = new(LibraryItemAlphaKeys.NUMBER, false); + + // Act + List result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)]; + + // Assert + Assert.Equal(["1984"], result); + } + + [Fact] + public void ToExpression_WhenAlphaKeyIsTheSymbolKey_ShouldMatchOnlyArtistsWhoseNameStartsWithASymbol() + { + // Arrange + SeedArtists("!Important", "1984", "Alpha"); + ArtistAlphaFilterSpecification specification = new(LibraryItemAlphaKeys.SYMBOL, false); + + // Act + List result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)]; + + // Assert + Assert.Equal(["!Important"], result); + } + + [Fact] + public void ToExpression_WhenIgnoringThePrefixAndNameStartsWithThe_ShouldMatchOnTheStrippedName() + { + // Arrange + SeedArtists("The Beatles", "Adele"); + ArtistAlphaFilterSpecification specification = new("b", true); + + // Act + List result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)]; + + // Assert + Assert.Equal(["The Beatles"], result); + } + + [Fact] + public void ToExpression_WhenNotIgnoringThePrefixAndNameStartsWithThe_ShouldNotMatchOnTheStrippedName() + { + // Arrange + SeedArtists("The Beatles", "Adele"); + ArtistAlphaFilterSpecification specification = new("b", false); + + // Act + List result = [.. _context.Artists.Where(specification.ToExpression())]; + + // Assert + Assert.Empty(result); + } + + [Fact] + public void ToExpression_WhenAlphaKeyIsTheNumberKeyAndNameStartsWithASymbol_ShouldNotMatchIt() + { + // Arrange + SeedArtists("!Voyager", "1984", "Alpha"); + ArtistAlphaFilterSpecification specification = new(LibraryItemAlphaKeys.NUMBER, false); + + // Act + List result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)]; + + // Assert + // Only the artist whose name starts with a digit matches; a symbol and a letter do not. + Assert.Equal(["1984"], result); + } + + [Fact] + public void ToExpression_WhenAlphaKeyIsTheSymbolKeyAndNameIsEmpty_ShouldMatchIt() + { + // Arrange + SeedArtists(string.Empty); + ArtistAlphaFilterSpecification specification = new(LibraryItemAlphaKeys.SYMBOL, false); + + // Act + List result = [.. _context.Artists.Where(specification.ToExpression())]; + + // Assert + // An empty effective name is neither a letter nor a digit, so it is categorized as a symbol. + Assert.Single(result); + } + + [Fact] + public void ToExpression_WhenAlphaKeyIsALetterAndNameIsEmpty_ShouldNotMatchAnyArtist() + { + // Arrange + SeedArtists(string.Empty); + ArtistAlphaFilterSpecification specification = new("a", false); + + // Act + List result = [.. _context.Artists.Where(specification.ToExpression())]; + + // Assert + Assert.Empty(result); + } + + [Theory] + [InlineData("a", "Alpha")] // the first letter of the alphabet + [InlineData("b", "Bravo")] // a letter in the middle of the alphabet + [InlineData("c", "Charlie")] // another letter in the middle of the alphabet + public void ToExpression_WhenAlphaKeyIsALetter_ShouldMatchOnlyTheNamesStartingWithIt(string alphaKey, string matchingName) + { + // Arrange + SeedArtists("Alpha", "Bravo", "Charlie"); + ArtistAlphaFilterSpecification specification = new(alphaKey, false); + + // Act + List result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)]; + + // Assert + Assert.Equal([matchingName], result); + } + + /// + /// Seeds artists with the provided names. + /// + /// The names of the artists to seed. + /// The seeded instances. + private List SeedArtists(params string[] names) + { + List entities = []; + foreach (string name in names) + entities.Add(_artistEntityFixture.Create(name: name, includeAlbums: false, includeContributors: false)); + _context.Artists.AddRange(entities); + _context.SaveChanges(); + return entities; + } + + /// + /// Disposes the database context and its underlying connection. + /// + public void Dispose() + { + _context.Dispose(); + _connection.Dispose(); + } +} diff --git a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/TrackRepositoryTests.cs b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/TrackRepositoryTests.cs index 0d0279c9..f329ae5d 100644 --- a/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/TrackRepositoryTests.cs +++ b/tests/IntegrationTests/Lumina.DataAccess.IntegrationTests/Core/Repositories/MusicLibrary/TrackRepositoryTests.cs @@ -567,7 +567,7 @@ public class TrackRepositoryTests List albumTracks = [firstDiscFirstTrack, firstDiscSecondTrack, secondDiscTrack]; Guid[] expectedOrder = [.. albumTracks - .OrderBy(track => track.DiscNumber) + .OrderBy(track => track.DiscNumber ?? 1) .ThenBy(track => track.TrackNumber) .ThenBy(track => track.Id) .Select(track => track.Id)]; @@ -634,6 +634,34 @@ public class TrackRepositoryTests Assert.Equal(3, page.PerPage); Assert.Equal(1, page.NumberOfPages); Assert.DoesNotContain(page.Data, row => row.Id == trackOfAnotherAlbum.Id); + Assert.Equal(tracks.Select(track => track.DurationInSeconds), page.Data.Select(row => row.DurationInSeconds)); + } + + [Fact] + public async Task GetTracksLiteByAlbumIdAsync_WhenATrackHasNoDiscNumber_ShouldTreatItAsTheFirstDisc() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-trackrepo-lite-nodisc-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + TrackRepository sut = new(context); + + Guid libraryId = Guid.NewGuid(); + AlbumEntity album = await SeedAlbumAsync(context, libraryId); + TrackEntity secondTrackWithoutDiscNumber = _trackEntityFixture.Create(albumId: album.Id, libraryId: libraryId, path: "/music/queen/second.flac", trackNumber: 2, includeMetadata: false); + secondTrackWithoutDiscNumber.DiscNumber = null; + TrackEntity thirdTrack = _trackEntityFixture.Create(albumId: album.Id, libraryId: libraryId, path: "/music/queen/third.flac", trackNumber: 3, includeMetadata: false); + thirdTrack.DiscNumber = 1; + context.Tracks.AddRange(secondTrackWithoutDiscNumber, thirdTrack); + await context.SaveChangesAsync(); + + // Act + Result> result = await sut.GetTracksLiteByAlbumIdAsync(album.Id, null, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal([secondTrackWithoutDiscNumber.Id, thirdTrack.Id], result.Value.Data.Select(row => row.Id)); } [Theory] @@ -686,6 +714,60 @@ public class TrackRepositoryTests Assert.Equal(expectedRowCount, page.Data.Count); } + [Fact] + public async Task GetByAlbumIdAsync_WhenATrackHasNoDiscNumber_ShouldTreatItAsTheFirstDisc() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-trackrepo-nodisc-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + TrackRepository sut = new(context); + + Guid libraryId = Guid.NewGuid(); + AlbumEntity album = await SeedAlbumAsync(context, libraryId); + TrackEntity secondDiscTrack = _trackEntityFixture.Create(albumId: album.Id, libraryId: libraryId, path: "/music/queen/second-disc.flac", trackNumber: 1, includeMetadata: false); + secondDiscTrack.DiscNumber = 2; + TrackEntity trackWithoutDiscNumber = _trackEntityFixture.Create(albumId: album.Id, libraryId: libraryId, path: "/music/queen/first-disc.flac", trackNumber: 2, includeMetadata: false); + trackWithoutDiscNumber.DiscNumber = null; + context.Tracks.AddRange(secondDiscTrack, trackWithoutDiscNumber); + await context.SaveChangesAsync(); + + // Act + Result> result = await sut.GetByAlbumIdAsync(album.Id, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + // A track without a disc number belongs to the first disc, so it is ordered before the tracks of disc 2. + Assert.Equal([trackWithoutDiscNumber.Id, secondDiscTrack.Id], result.Value.Select(track => track.Id)); + } + + [Fact] + public async Task GetTracksLiteByAlbumIdAsync_WhenCalled_ShouldProjectTheDurationInSeconds() + { + // Arrange + using SqliteConnection anchorConnection = new($"Data Source=luminadataccess-trackrepo-lite-duration-{Guid.NewGuid()};Mode=Memory;Cache=Shared"); + anchorConnection.Open(); + using LuminaDbContext context = new(new DbContextOptionsBuilder().UseSqlite(anchorConnection.ConnectionString).Options); + context.Database.EnsureCreated(); + TrackRepository sut = new(context); + + Guid libraryId = Guid.NewGuid(); + AlbumEntity album = await SeedAlbumAsync(context, libraryId); + TrackEntity track = _trackEntityFixture.Create(albumId: album.Id, libraryId: libraryId, path: "/music/queen/the-prophet-song.flac", includeMetadata: false); + track.DurationInSeconds = 367; + context.Tracks.Add(track); + await context.SaveChangesAsync(); + + // Act + Result> result = await sut.GetTracksLiteByAlbumIdAsync(album.Id, null, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + TrackLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal(367, row.DurationInSeconds); + } + /// /// Seeds an artist and the album that owns the tracks of the library identified by , so that the required foreign keys of a track are satisfied. /// diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLite/GetAlbumTracksLiteEndpointTests.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLite/GetAlbumTracksLiteEndpointTests.cs index bd61749b..3549457c 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLite/GetAlbumTracksLiteEndpointTests.cs +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Albums/GetAlbumTracksLite/GetAlbumTracksLiteEndpointTests.cs @@ -77,6 +77,7 @@ public class GetAlbumTracksLiteEndpointTests : IClassFixture 0); } [Fact] diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistAlbumsLite/GetArtistAlbumsLiteEndpointTests.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistAlbumsLite/GetArtistAlbumsLiteEndpointTests.cs index 43ae7fdc..4f29f269 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistAlbumsLite/GetArtistAlbumsLiteEndpointTests.cs +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistAlbumsLite/GetArtistAlbumsLiteEndpointTests.cs @@ -18,6 +18,7 @@ using System.Net; using System.Net.Http; using System.Net.Http.Json; using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; #endregion @@ -33,7 +34,8 @@ public class GetArtistAlbumsLiteEndpointTests : IClassFixture album.Title == "A Night at the Opera"); Assert.Contains(albums.Data, album => album.Title == "News of the World"); + // The release types and the release year are exposed by the read model, so the lite listing can group and order the releases of an artist. + Assert.All(albums.Data, album => Assert.NotEmpty(album.ReleaseTypes!)); } [Fact] diff --git a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistsLite/GetArtistsLiteEndpointTests.cs b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistsLite/GetArtistsLiteEndpointTests.cs index 418651dd..82ae0dd4 100644 --- a/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistsLite/GetArtistsLiteEndpointTests.cs +++ b/tests/IntegrationTests/Lumina.Presentation.Api.IntegrationTests/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Artists/GetArtistsLite/GetArtistsLiteEndpointTests.cs @@ -97,6 +97,155 @@ public class GetArtistsLiteEndpointTests : IClassFixture? paginatedArtists = await response.Content.ReadFromJsonAsync>(_jsonOptions); + Assert.NotNull(paginatedArtists); + ArtistLiteResponse artist = Assert.Single(paginatedArtists!.Data); + Assert.Equal("Queen", artist.Name); + Assert.Equal(1, paginatedArtists.Count); + } + + [Fact] + public async Task GetArtistsLite_WhenCalledWithFilterAlphaKeyLetterAndIgnoreThePrefix_ShouldIncludeThePrefixedNames() + { + // Arrange + Guid userId = GetCurrentUserId(); + Guid libraryId = await SeedLibraryAsync(userId); + await SeedArtistAsync(libraryId, "Queen"); + await SeedArtistAsync(libraryId, "The Queen"); + await SeedArtistAsync(libraryId, "Radiohead"); + + // Act + HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?filterAlphaKey=q&shouldIgnoreThePrefixForAlphaPicker=true"); + + // Assert + response.EnsureSuccessStatusCode(); + PaginatedResponse? paginatedArtists = await response.Content.ReadFromJsonAsync>(_jsonOptions); + Assert.NotNull(paginatedArtists); + Assert.Equal(2, paginatedArtists!.Count); + Assert.Contains(paginatedArtists.Data, artist => artist.Name == "Queen"); + Assert.Contains(paginatedArtists.Data, artist => artist.Name == "The Queen"); + } + + [Fact] + public async Task GetArtistsLite_WhenCalledWithFilterAlphaKeyNumber_ShouldReturnOnlyArtistsStartingWithADigit() + { + // Arrange + Guid userId = GetCurrentUserId(); + Guid libraryId = await SeedLibraryAsync(userId); + await SeedArtistAsync(libraryId, "1984"); + await SeedArtistAsync(libraryId, "7th Sense"); + await SeedArtistAsync(libraryId, "Adele"); + + // Act + HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?filterAlphaKey=%23"); + + // Assert + response.EnsureSuccessStatusCode(); + PaginatedResponse? paginatedArtists = await response.Content.ReadFromJsonAsync>(_jsonOptions); + Assert.NotNull(paginatedArtists); + Assert.Equal(2, paginatedArtists!.Count); + Assert.Contains(paginatedArtists.Data, artist => artist.Name == "1984"); + Assert.Contains(paginatedArtists.Data, artist => artist.Name == "7th Sense"); + } + + [Fact] + public async Task GetArtistsLite_WhenCalledWithFilterAlphaKeySymbol_ShouldReturnOnlyArtistsStartingWithASymbol() + { + // Arrange + Guid userId = GetCurrentUserId(); + Guid libraryId = await SeedLibraryAsync(userId); + await SeedArtistAsync(libraryId, "!Important"); + await SeedArtistAsync(libraryId, "1984"); + await SeedArtistAsync(libraryId, "Adele"); + + // Act + HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?filterAlphaKey=%2A"); + + // Assert + response.EnsureSuccessStatusCode(); + PaginatedResponse? paginatedArtists = await response.Content.ReadFromJsonAsync>(_jsonOptions); + Assert.NotNull(paginatedArtists); + ArtistLiteResponse artist = Assert.Single(paginatedArtists!.Data); + Assert.Equal("!Important", artist.Name); + Assert.Equal(1, paginatedArtists.Count); + } + + [Fact] + public async Task GetArtistsLite_WhenCalledWithSearchTermAndFilterAlphaKey_ShouldReturnOnlyArtistsSatisfyingBothFilters() + { + // Arrange + Guid userId = GetCurrentUserId(); + Guid libraryId = await SeedLibraryAsync(userId); + // The search term matches only one artist, while the alpha key matches only the other, so no artist satisfies both filters at once. + await SeedArtistAsync(libraryId, "The Fellowship Band"); + await SeedArtistAsync(libraryId, "Zoo"); + + // Act + HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?searchTerm={Uri.EscapeDataString("Fellowship")}&filterAlphaKey=z"); + + // Assert + response.EnsureSuccessStatusCode(); + PaginatedResponse? paginatedArtists = await response.Content.ReadFromJsonAsync>(_jsonOptions); + Assert.NotNull(paginatedArtists); + Assert.Empty(paginatedArtists!.Data); + Assert.Equal(0, paginatedArtists.Count); + } + + [Fact] + public async Task GetArtistsLite_WhenSortedByNameAscending_ShouldReturnArtistsInAscendingOrder() + { + // Arrange + Guid userId = GetCurrentUserId(); + Guid libraryId = await SeedLibraryAsync(userId); + await SeedArtistAsync(libraryId, "Zulu"); + await SeedArtistAsync(libraryId, "Mike"); + await SeedArtistAsync(libraryId, "Alpha"); + + // Act + HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?sortBy=name&sortOrder=Ascending"); + + // Assert + response.EnsureSuccessStatusCode(); + PaginatedResponse? paginatedArtists = await response.Content.ReadFromJsonAsync>(_jsonOptions); + Assert.NotNull(paginatedArtists); + Assert.Equal(new[] { "Alpha", "Mike", "Zulu" }, paginatedArtists!.Data.Select(artist => artist.Name)); + } + + [Fact] + public async Task GetArtistsLite_WhenSortedByNameDescending_ShouldReturnArtistsInDescendingOrder() + { + // Arrange + Guid userId = GetCurrentUserId(); + Guid libraryId = await SeedLibraryAsync(userId); + await SeedArtistAsync(libraryId, "Zulu"); + await SeedArtistAsync(libraryId, "Mike"); + await SeedArtistAsync(libraryId, "Alpha"); + + // Act + HttpResponseMessage response = await _client.GetAsync($"/api/v1/libraries/{libraryId}/artists/lite?sortBy=name&sortOrder=Descending"); + + // Assert + response.EnsureSuccessStatusCode(); + PaginatedResponse? paginatedArtists = await response.Content.ReadFromJsonAsync>(_jsonOptions); + Assert.NotNull(paginatedArtists); + Assert.Equal(new[] { "Zulu", "Mike", "Alpha" }, paginatedArtists!.Data.Select(artist => artist.Name)); + } + [Fact] public async Task GetArtistsLite_WhenLibraryBelongsToAnotherUser_ShouldReturnForbidden() { diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumEntityMappingTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumEntityMappingTests.cs index 7da1e576..35de8edf 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumEntityMappingTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumEntityMappingTests.cs @@ -261,6 +261,8 @@ public class AlbumEntityMappingTests Assert.Equal(entity.Id, result.Id); Assert.Equal(entity.ArtistId, result.ArtistId); Assert.Equal(entity.LibraryId, result.LibraryId); + // No cover path is supplied by default, so the response exposes none. + Assert.Null(result.CoverPath); Assert.Equal(entity.Title, result.Metadata.Title); Assert.Equal(entity.OriginalTitle, result.Metadata.OriginalTitle); Assert.Equal(entity.Description, result.Metadata.Description); @@ -346,4 +348,19 @@ public class AlbumEntityMappingTests Assert.Equal(entities[i].Title, results[i].Metadata.Title); } } + + [Fact] + public void ToResponse_WhenCoverPathIsProvided_ShouldMapIt() + { + // Arrange + AlbumEntity entity = _albumEntityFixture.Create(); + string coverPath = "/media/albums/cover.jpg"; + + // Act + AlbumResponse result = entity.ToResponse(coverPath); + + // Assert + Assert.NotNull(result); + Assert.Equal(coverPath, result.CoverPath); + } } diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRowMappingTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRowMappingTests.cs index eb0cc111..731b0cd2 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRowMappingTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Albums/AlbumLiteRowMappingTests.cs @@ -36,6 +36,9 @@ public class AlbumLiteRowMappingTests Assert.Equal(readModel.Id, result.Id); Assert.Equal(readModel.Title, result.Title); Assert.Equal(readModel.TotalTracks, result.TotalTracks); + Assert.Equal(readModel.CoverPath, result.CoverPath); + Assert.Equal(readModel.ReleaseYear, result.ReleaseYear); + Assert.Equal(readModel.ReleaseTypes, result.ReleaseTypes); } [Fact] @@ -53,6 +56,9 @@ public class AlbumLiteRowMappingTests Assert.Equal(readModels.Select(readModel => readModel.Id), results.Select(response => response.Id)); Assert.Equal(readModels.Select(readModel => readModel.Title), results.Select(response => response.Title)); Assert.Equal(readModels.Select(readModel => readModel.TotalTracks), results.Select(response => response.TotalTracks)); + Assert.Equal(readModels.Select(readModel => readModel.CoverPath), results.Select(response => response.CoverPath)); + Assert.Equal(readModels.Select(readModel => readModel.ReleaseYear), results.Select(response => response.ReleaseYear)); + Assert.Equal(readModels.Select(readModel => readModel.ReleaseTypes), results.Select(response => response.ReleaseTypes)); } [Fact] diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistEntityMappingTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistEntityMappingTests.cs index cec0e8fc..13b3da21 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistEntityMappingTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistEntityMappingTests.cs @@ -113,6 +113,8 @@ public class ArtistEntityMappingTests Assert.NotNull(result); Assert.Equal(entity.Id, result.Id); Assert.Equal(entity.LibraryId, result.LibraryId); + // No cover path is supplied by default, so the response exposes none. + Assert.Null(result.CoverPath); Assert.Equal(entity.Name, result.Metadata.Name); Assert.Equal(entity.Website, result.Website); Assert.Equal(entity.MusicBrainzArtistId, result.MusicBrainzArtistId); @@ -186,4 +188,19 @@ public class ArtistEntityMappingTests Assert.Equal(paginatedEntities.Count, result.Count); Assert.Equal(paginatedEntities.NumberOfPages, result.NumberOfPages); } + + [Fact] + public void ToResponse_WhenCoverPathIsProvided_ShouldMapIt() + { + // Arrange + ArtistEntity entity = _artistEntityFixture.Create(); + string coverPath = "/media/artists/cover.jpg"; + + // Act + ArtistResponse result = entity.ToResponse(coverPath); + + // Assert + Assert.NotNull(result); + Assert.Equal(coverPath, result.CoverPath); + } } diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRowMappingTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRowMappingTests.cs index e630aa00..01a3b36b 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRowMappingTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/ArtistLiteRowMappingTests.cs @@ -35,6 +35,7 @@ public class ArtistLiteRowMappingTests Assert.NotNull(result); Assert.Equal(readModel.Id, result.Id); Assert.Equal(readModel.Name, result.Name); + Assert.Equal(readModel.CoverPath, result.CoverPath); } [Fact] @@ -51,6 +52,7 @@ public class ArtistLiteRowMappingTests Assert.Equal(readModels.Count, results.Count); Assert.Equal(readModels.Select(readModel => readModel.Id), results.Select(response => response.Id)); Assert.Equal(readModels.Select(readModel => readModel.Name), results.Select(response => response.Name)); + Assert.Equal(readModels.Select(readModel => readModel.CoverPath), results.Select(response => response.CoverPath)); } [Fact] diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequestMappingTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequestMappingTests.cs index 9f8c28df..e390f115 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequestMappingTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Artists/GetArtistsLiteRequestMappingTests.cs @@ -3,6 +3,7 @@ using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.A using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtistsLite; using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists; using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists; +using Lumina.Domain.SharedKernel.Common.Enums.Common; using System.Diagnostics.CodeAnalysis; #endregion @@ -99,4 +100,24 @@ public class GetArtistsLiteRequestMappingTests Assert.Equal(2, result.PaginationData.CurrentPage); Assert.Equal(25, result.PaginationData.PerPage); } + + [Fact] + public void ToQuery_WhenAlphaAndSortingAreProvided_ShouldMapThem() + { + // Arrange + GetArtistsLiteRequest request = _getArtistsLiteRequestFixture.Create( + filterAlphaKey: "q", + shouldIgnoreThePrefixForAlphaPicker: true, + sortBy: "name", + sortOrder: SortOrder.Descending); + + // Act + GetArtistsLiteQuery result = request.ToQuery("library-route"); + + // Assert + Assert.Equal("q", result.FilterAlphaKey); + Assert.True(result.ShouldIgnoreThePrefixForAlphaPicker); + Assert.Equal("name", result.SortBy); + Assert.Equal(SortOrder.Descending, result.SortOrder); + } } diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRowMappingTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRowMappingTests.cs index b3f06a6f..56fd9ad8 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRowMappingTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackLiteRowMappingTests.cs @@ -37,6 +37,7 @@ public class TrackLiteRowMappingTests Assert.Equal(readModel.Title, result.Title); Assert.Equal(readModel.TrackNumber, result.TrackNumber); Assert.Equal(readModel.DiscNumber, result.DiscNumber); + Assert.Equal(readModel.DurationInSeconds, result.DurationInSeconds); } [Fact] diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryHandlerTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryHandlerTests.cs index 32e9b1a1..460f25ea 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryHandlerTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Albums/Queries/GetAlbum/GetAlbumQueryHandlerTests.cs @@ -12,8 +12,11 @@ using Lumina.Application.Fixtures.Core.MediaLibrary.AudioLibrary.MusicLibrary.Al 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 NSubstitute; using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; @@ -30,12 +33,14 @@ public class GetAlbumQueryHandlerTests { private readonly IUnitOfWork _mockUnitOfWork; private readonly IAlbumRepository _mockAlbumRepository; + private readonly IMusicArtworkRepository _mockMusicArtworkRepository; private readonly IAuthorizationService _mockAuthorizationService; private readonly ICurrentUserService _mockCurrentUserService; private readonly IValidator _mockValidator; private readonly GetAlbumQueryHandler _sut; private readonly Guid _userId; private readonly AlbumEntityFixture _albumEntityFixture = new(); + private readonly MusicArtworkEntityFixture _musicArtworkEntityFixture = new(); private readonly GetAlbumQueryFixture _getAlbumQueryFixture = new(); /// @@ -44,18 +49,22 @@ public class GetAlbumQueryHandlerTests public GetAlbumQueryHandlerTests() { _mockAlbumRepository = Substitute.For(); + _mockMusicArtworkRepository = Substitute.For(); _mockUnitOfWork = Substitute.For(); _mockUnitOfWork.AlbumRepository.Returns(_mockAlbumRepository); + _mockUnitOfWork.MusicArtworkRepository.Returns(_mockMusicArtworkRepository); _mockAuthorizationService = Substitute.For(); _mockCurrentUserService = Substitute.For(); _mockValidator = Substitute.For>(); _userId = Guid.NewGuid(); - // Default stubs: the current user is authenticated, the library ownership policy allows access and the validator passes. + // Default stubs: the current user is authenticated, the library ownership policy allows access, the validator passes, and the album has no stored artwork. _mockCurrentUserService.UserId.Returns(_userId); _mockAuthorizationService.EvaluatePolicyAsync(_userId, Arg.Any(), Arg.Any()) .Returns(true); _mockValidator.Validate(Arg.Any()).Returns([]); + _mockMusicArtworkRepository.GetByOwnerAsync(Arg.Any(), Arg.Any(), Arg.Any()) + .Returns(Result.From>([])); _sut = new GetAlbumQueryHandler(_mockUnitOfWork, _mockAuthorizationService, _mockCurrentUserService, _mockValidator); } @@ -70,6 +79,13 @@ public class GetAlbumQueryHandlerTests AlbumEntity album = _albumEntityFixture.Create(id: albumId, artistId: artistId, libraryId: libraryId, includeTracks: true, includeMetadata: true); _mockAlbumRepository.GetByIdAsync(albumId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: Arg.Any()) .Returns(Result.From(album)); + List artwork = [ + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: albumId, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "/media/cover.jpg"), + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: albumId, artworkType: ArtworkType.Back, ordinal: 0, fileName: "/media/back.jpg"), + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: albumId, artworkType: ArtworkType.Booklet, ordinal: 0, includeFileName: false) + ]; + _mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Album, albumId, Arg.Any()) + .Returns(Result.From>(artwork)); GetAlbumQuery query = _getAlbumQueryFixture.Create(libraryId: libraryId.ToString(), artistId: artistId.ToString(), albumId: albumId.ToString()); // Act @@ -83,6 +99,13 @@ public class GetAlbumQueryHandlerTests Assert.Equal(album.Title, result.Value.Metadata.Title); Assert.NotNull(result.Value.Tracks); Assert.Equal(album.Tracks.Count, result.Value.Tracks!.Count); + // The cover is exposed on its own, and every stored piece of artwork is exposed in order, while the ones whose file is not stored yet are left out. + Assert.Equal("/media/cover.jpg", result.Value.CoverPath); + Assert.Equal(2, result.Value.Artwork.Count); + Assert.Equal(ArtworkType.Cover, result.Value.Artwork[0].Type); + Assert.Equal("/media/cover.jpg", result.Value.Artwork[0].Path); + Assert.Equal(ArtworkType.Back, result.Value.Artwork[1].Type); + Assert.Equal("/media/back.jpg", result.Value.Artwork[1].Path); await _mockAlbumRepository.Received(1).GetByIdAsync(albumId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: Arg.Any()); await _mockAuthorizationService.Received(1).EvaluatePolicyAsync( _userId, Arg.Is(context => context.LibraryId == libraryId), Arg.Any()); @@ -220,4 +243,112 @@ public class GetAlbumQueryHandlerTests await _mockAlbumRepository.DidNotReceive().GetByIdAsync(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()); await _mockAuthorizationService.DidNotReceive().EvaluatePolicyAsync(Arg.Any(), Arg.Any(), Arg.Any()); } + + [Fact] + public async Task HandleAsync_WhenArtworkRepositoryFails_ShouldReturnFailureResult() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + Guid artistId = Guid.NewGuid(); + Guid albumId = Guid.NewGuid(); + AlbumEntity album = _albumEntityFixture.Create(id: albumId, artistId: artistId, libraryId: libraryId); + GetAlbumQuery query = _getAlbumQueryFixture.Create(libraryId: libraryId.ToString(), artistId: artistId.ToString(), albumId: albumId.ToString()); + _mockAlbumRepository.GetByIdAsync(albumId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: Arg.Any()) + .Returns(Result.From(album)); + _mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Album, albumId, Arg.Any()) + .Returns(ApplicationErrors.Persistence.UniqueConstraintViolation); + + // Act + Result result = await _sut.HandleAsync(query, CancellationToken.None); + + // Assert + Assert.True(result.IsFailure); + Assert.Equal(ApplicationErrors.Persistence.UniqueConstraintViolation, result.FirstError); + } + + [Fact] + public async Task HandleAsync_WhenAlbumHasNoArtwork_ShouldReturnNullCoverPathAndEmptyArtwork() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + Guid artistId = Guid.NewGuid(); + Guid albumId = Guid.NewGuid(); + AlbumEntity album = _albumEntityFixture.Create(id: albumId, artistId: artistId, libraryId: libraryId); + GetAlbumQuery query = _getAlbumQueryFixture.Create(libraryId: libraryId.ToString(), artistId: artistId.ToString(), albumId: albumId.ToString()); + _mockAlbumRepository.GetByIdAsync(albumId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: Arg.Any()) + .Returns(Result.From(album)); + _mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Album, albumId, Arg.Any()) + .Returns(Result.From>([])); + + // Act + Result result = await _sut.HandleAsync(query, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Null(result.Value.CoverPath); + Assert.Empty(result.Value.Artwork); + } + + [Fact] + public async Task HandleAsync_WhenMultipleArtworkExist_ShouldMapEveryStoredArtworkAndExcludeUnstoredOnes() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + Guid artistId = Guid.NewGuid(); + Guid albumId = Guid.NewGuid(); + AlbumEntity album = _albumEntityFixture.Create(id: albumId, artistId: artistId, libraryId: libraryId); + GetAlbumQuery query = _getAlbumQueryFixture.Create(libraryId: libraryId.ToString(), artistId: artistId.ToString(), albumId: albumId.ToString()); + _mockAlbumRepository.GetByIdAsync(albumId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: Arg.Any()) + .Returns(Result.From(album)); + List artwork = [ + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: albumId, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "/media/cover.jpg"), + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: albumId, artworkType: ArtworkType.Booklet, ordinal: 1, includeFileName: false), + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: albumId, artworkType: ArtworkType.Booklet, ordinal: 2, fileName: string.Empty), + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: albumId, artworkType: ArtworkType.Booklet, ordinal: 3, fileName: " "), + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: albumId, artworkType: ArtworkType.Back, ordinal: 0, fileName: "/media/back.jpg") + ]; + _mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Album, albumId, Arg.Any()) + .Returns(Result.From>(artwork)); + + // Act + Result result = await _sut.HandleAsync(query, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + // Artwork whose file has not been stored yet (null, empty or whitespace) is left out, and the stored ones keep their order, type and ordinal. + Assert.Equal(2, result.Value.Artwork.Count); + Assert.Equal(ArtworkType.Cover, result.Value.Artwork[0].Type); + Assert.Equal(0, result.Value.Artwork[0].Ordinal); + Assert.Equal("/media/cover.jpg", result.Value.Artwork[0].Path); + Assert.Equal(ArtworkType.Back, result.Value.Artwork[1].Type); + Assert.Equal(0, result.Value.Artwork[1].Ordinal); + Assert.Equal("/media/back.jpg", result.Value.Artwork[1].Path); + await _mockMusicArtworkRepository.Received(1).GetByOwnerAsync(MusicArtworkOwnerType.Album, albumId, Arg.Any()); + } + + [Fact] + public async Task HandleAsync_WhenMultipleCoversExist_ShouldUseTheFirstCoverFileName() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + Guid artistId = Guid.NewGuid(); + Guid albumId = Guid.NewGuid(); + AlbumEntity album = _albumEntityFixture.Create(id: albumId, artistId: artistId, libraryId: libraryId); + GetAlbumQuery query = _getAlbumQueryFixture.Create(libraryId: libraryId.ToString(), artistId: artistId.ToString(), albumId: albumId.ToString()); + _mockAlbumRepository.GetByIdAsync(albumId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: Arg.Any()) + .Returns(Result.From(album)); + List artwork = [ + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: albumId, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "/media/front.jpg"), + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: albumId, artworkType: ArtworkType.Cover, ordinal: 1, fileName: "/media/alternate.jpg") + ]; + _mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Album, albumId, Arg.Any()) + .Returns(Result.From>(artwork)); + + // Act + Result result = await _sut.HandleAsync(query, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal("/media/front.jpg", result.Value.CoverPath); + } } diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtist/GetArtistQueryHandlerTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtist/GetArtistQueryHandlerTests.cs index bde4ff41..678b69e1 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtist/GetArtistQueryHandlerTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtist/GetArtistQueryHandlerTests.cs @@ -12,8 +12,11 @@ using Lumina.Application.Fixtures.Core.MediaLibrary.AudioLibrary.MusicLibrary.Ar 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 NSubstitute; using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; @@ -30,12 +33,14 @@ public class GetArtistQueryHandlerTests { private readonly IUnitOfWork _mockUnitOfWork; private readonly IArtistRepository _mockArtistRepository; + private readonly IMusicArtworkRepository _mockMusicArtworkRepository; private readonly IAuthorizationService _mockAuthorizationService; private readonly ICurrentUserService _mockCurrentUserService; private readonly IValidator _mockValidator; private readonly GetArtistQueryHandler _sut; private readonly Guid _userId; private readonly ArtistEntityFixture _artistEntityFixture = new(); + private readonly MusicArtworkEntityFixture _musicArtworkEntityFixture = new(); private readonly GetArtistQueryFixture _getArtistQueryFixture = new(); /// @@ -44,18 +49,22 @@ public class GetArtistQueryHandlerTests public GetArtistQueryHandlerTests() { _mockArtistRepository = Substitute.For(); + _mockMusicArtworkRepository = Substitute.For(); _mockUnitOfWork = Substitute.For(); _mockUnitOfWork.ArtistRepository.Returns(_mockArtistRepository); + _mockUnitOfWork.MusicArtworkRepository.Returns(_mockMusicArtworkRepository); _mockAuthorizationService = Substitute.For(); _mockCurrentUserService = Substitute.For(); _mockValidator = Substitute.For>(); _userId = Guid.NewGuid(); - // Default stubs: the current user is authenticated, the library ownership policy allows access and the validator passes. + // Default stubs: the current user is authenticated, the library ownership policy allows access, the validator passes, and the artist has no stored artwork. _mockCurrentUserService.UserId.Returns(_userId); _mockAuthorizationService.EvaluatePolicyAsync(_userId, Arg.Any(), Arg.Any()) .Returns(true); _mockValidator.Validate(Arg.Any()).Returns([]); + _mockMusicArtworkRepository.GetByOwnerAsync(Arg.Any(), Arg.Any(), Arg.Any()) + .Returns(Result.From>([])); _sut = new GetArtistQueryHandler(_mockUnitOfWork, _mockAuthorizationService, _mockCurrentUserService, _mockValidator); } @@ -199,4 +208,97 @@ public class GetArtistQueryHandlerTests await _mockArtistRepository.DidNotReceive().GetByIdAsync(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()); await _mockAuthorizationService.DidNotReceive().EvaluatePolicyAsync(Arg.Any(), Arg.Any(), Arg.Any()); } + + [Fact] + public async Task HandleAsync_WhenArtworkRepositoryFails_ShouldReturnFailureResult() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + Guid artistId = Guid.NewGuid(); + ArtistEntity artist = _artistEntityFixture.Create(id: artistId, libraryId: libraryId); + GetArtistQuery query = _getArtistQueryFixture.Create(libraryId: libraryId.ToString(), artistId: artistId.ToString()); + _mockArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: Arg.Any()) + .Returns(Result.From(artist)); + _mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Artist, artistId, Arg.Any()) + .Returns(ApplicationErrors.Persistence.UniqueConstraintViolation); + + // Act + Result result = await _sut.HandleAsync(query, CancellationToken.None); + + // Assert + Assert.True(result.IsFailure); + Assert.Equal(ApplicationErrors.Persistence.UniqueConstraintViolation, result.FirstError); + } + + [Fact] + public async Task HandleAsync_WhenArtistHasNoArtwork_ShouldReturnNullCoverPath() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + Guid artistId = Guid.NewGuid(); + ArtistEntity artist = _artistEntityFixture.Create(id: artistId, libraryId: libraryId); + GetArtistQuery query = _getArtistQueryFixture.Create(libraryId: libraryId.ToString(), artistId: artistId.ToString()); + _mockArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: Arg.Any()) + .Returns(Result.From(artist)); + _mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Artist, artistId, Arg.Any()) + .Returns(Result.From>([])); + + // Act + Result result = await _sut.HandleAsync(query, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Null(result.Value.CoverPath); + } + + [Fact] + public async Task HandleAsync_WhenArtistHasCoverArtwork_ShouldMapCoverPathAndRequestArtistArtwork() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + Guid artistId = Guid.NewGuid(); + ArtistEntity artist = _artistEntityFixture.Create(id: artistId, libraryId: libraryId); + GetArtistQuery query = _getArtistQueryFixture.Create(libraryId: libraryId.ToString(), artistId: artistId.ToString()); + _mockArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: Arg.Any()) + .Returns(Result.From(artist)); + List artwork = [ + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Artist, ownerId: artistId, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "/media/artist.jpg") + ]; + _mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Artist, artistId, Arg.Any()) + .Returns(Result.From>(artwork)); + + // Act + Result result = await _sut.HandleAsync(query, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal("/media/artist.jpg", result.Value.CoverPath); + await _mockMusicArtworkRepository.Received(1).GetByOwnerAsync(MusicArtworkOwnerType.Artist, artistId, Arg.Any()); + } + + [Fact] + public async Task HandleAsync_WhenTheCoverHasNoStoredFileName_ShouldReturnNullCoverPath() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + Guid artistId = Guid.NewGuid(); + ArtistEntity artist = _artistEntityFixture.Create(id: artistId, libraryId: libraryId); + GetArtistQuery query = _getArtistQueryFixture.Create(libraryId: libraryId.ToString(), artistId: artistId.ToString()); + _mockArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: Arg.Any()) + .Returns(Result.From(artist)); + // A cover whose file has not been stored yet yields no cover path, even when another piece of artwork is already stored. + List artwork = [ + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Artist, ownerId: artistId, artworkType: ArtworkType.Cover, ordinal: 0, includeFileName: false), + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Artist, ownerId: artistId, artworkType: ArtworkType.Back, ordinal: 0, fileName: "/media/back.jpg") + ]; + _mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Artist, artistId, Arg.Any()) + .Returns(Result.From>(artwork)); + + // Act + Result result = await _sut.HandleAsync(query, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Null(result.Value.CoverPath); + } } diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryHandlerTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryHandlerTests.cs index 1b4f19bb..a95d1531 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryHandlerTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryHandlerTests.cs @@ -247,4 +247,41 @@ public class GetArtistsLiteQueryHandlerTests await _mockAuthorizationService.DidNotReceive().EvaluatePolicyAsync(Arg.Any(), Arg.Any(), Arg.Any()); await _mockArtistRepository.DidNotReceive().GetAllLiteAsync(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), cancellationToken: Arg.Any()); } + + [Fact] + public async Task HandleAsync_WhenQueryHasAlphaFilterAndSorting_ShouldPassThemToTheRepository() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + GetArtistsLiteQuery query = _getArtistsLiteQueryFixture.Create( + libraryId: libraryId.ToString(), + searchTerm: "Queen", + filterAlphaKey: "Q", + shouldIgnoreThePrefixForAlphaPicker: true, + sortBy: "name", + sortOrder: SortOrder.Descending); + PaginatedResultDto paginatedArtists = _paginatedResultDtoFixture.Create(data: [], currentPage: 1, perPage: 10, count: 0, numberOfPages: 0); + _mockArtistRepository.GetAllLiteAsync( + Arg.Any(), + Arg.Any(), + Arg.Any(), + Arg.Any(), + cancellationToken: Arg.Any()) + .Returns(Result.From(paginatedArtists)); + + // Act + await _sut.HandleAsync(query, CancellationToken.None); + + // Assert + await _mockArtistRepository.Received(1).GetAllLiteAsync( + Arg.Any(), + Arg.Is(sortBy => sortBy == "name"), + Arg.Is(sortOrder => sortOrder == SortOrder.Descending), + Arg.Is(filter => + filter.LibraryId == libraryId && + filter.SearchTerm == "Queen" && + filter.FilterAlphaKey == "Q" && + filter.ShouldIgnoreThePrefixForAlphaPicker), + cancellationToken: Arg.Any()); + } } diff --git a/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryValidatorTests.cs b/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryValidatorTests.cs index a2335d28..3fd9bc1c 100644 --- a/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryValidatorTests.cs +++ b/tests/UnitTests/Lumina.Application.UnitTests/Core/MediaLibrary/AudioLibrary/MusicLibrary/Artists/Queries/GetArtistsLite/GetArtistsLiteQueryValidatorTests.cs @@ -1,4 +1,5 @@ #region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.DTO.Filtering; using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtistsLite; using Lumina.Application.Fixtures.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtistsLite; using Lumina.Application.UnitTests.Common.Setup; @@ -63,4 +64,155 @@ public class GetArtistsLiteQueryValidatorTests // Assert result.ShouldNotHaveAnyValidationErrors(); } + + [Theory] + [InlineData("AB")] // more than one character + [InlineData("1")] // a digit, which is not a letter, the number bucket, or the symbol bucket + public void Validate_WhenFilterAlphaKeyIsNotASingleLetterOrSpecialKey_ShouldHaveValidationError(string filterAlphaKey) + { + // Arrange + GetArtistsLiteQuery query = _getArtistsLiteQueryFixture.Create(filterAlphaKey: filterAlphaKey); + + // Act + List result = _validator.TestValidate(query); + + // Assert + result.ShouldHaveValidationError(Errors.Library.InvalidFilterAlphaKey); + } + + [Theory] + [InlineData("Q")] // a single letter + [InlineData("q")] // a single lower case letter + [InlineData("#")] // the number bucket + [InlineData("*")] // the symbol bucket + public void Validate_WhenFilterAlphaKeyIsASingleLetterOrSpecialKey_ShouldNotHaveValidationError(string filterAlphaKey) + { + // Arrange + GetArtistsLiteQuery query = _getArtistsLiteQueryFixture.Create(filterAlphaKey: filterAlphaKey); + + // Act + List result = _validator.TestValidate(query); + + // Assert + result.ShouldNotHaveAnyValidationErrors(); + } + + [Fact] + public void Validate_WhenFilterAlphaKeyIsNull_ShouldNotHaveValidationError() + { + // Arrange + GetArtistsLiteQuery query = _getArtistsLiteQueryFixture.Create(filterAlphaKey: null); + + // Act + List result = _validator.TestValidate(query); + + // Assert + result.ShouldNotHaveAnyValidationErrors(); + } + + [Theory] + [InlineData(LibraryItemAlphaKeys.NUMBER)] // the number bucket constant + [InlineData(LibraryItemAlphaKeys.SYMBOL)] // the symbol bucket constant + public void Validate_WhenFilterAlphaKeyIsTheSpecialConstant_ShouldNotHaveValidationError(string filterAlphaKey) + { + // Arrange + GetArtistsLiteQuery query = _getArtistsLiteQueryFixture.Create(filterAlphaKey: filterAlphaKey); + + // Act + List result = _validator.TestValidate(query); + + // Assert + result.ShouldNotHaveAnyValidationErrors(); + } + + [Theory] + [InlineData("A")] // upper case A + [InlineData("B")] // upper case B + [InlineData("C")] // upper case C + [InlineData("D")] // upper case D + [InlineData("E")] // upper case E + [InlineData("F")] // upper case F + [InlineData("G")] // upper case G + [InlineData("H")] // upper case H + [InlineData("I")] // upper case I + [InlineData("J")] // upper case J + [InlineData("K")] // upper case K + [InlineData("L")] // upper case L + [InlineData("M")] // upper case M + [InlineData("N")] // upper case N + [InlineData("O")] // upper case O + [InlineData("P")] // upper case P + [InlineData("Q")] // upper case Q + [InlineData("R")] // upper case R + [InlineData("S")] // upper case S + [InlineData("T")] // upper case T + [InlineData("U")] // upper case U + [InlineData("V")] // upper case V + [InlineData("W")] // upper case W + [InlineData("X")] // upper case X + [InlineData("Y")] // upper case Y + [InlineData("Z")] // upper case Z + [InlineData("a")] // lower case a + [InlineData("b")] // lower case b + [InlineData("c")] // lower case c + [InlineData("d")] // lower case d + [InlineData("e")] // lower case e + [InlineData("f")] // lower case f + [InlineData("g")] // lower case g + [InlineData("h")] // lower case h + [InlineData("i")] // lower case i + [InlineData("j")] // lower case j + [InlineData("k")] // lower case k + [InlineData("l")] // lower case l + [InlineData("m")] // lower case m + [InlineData("n")] // lower case n + [InlineData("o")] // lower case o + [InlineData("p")] // lower case p + [InlineData("q")] // lower case q + [InlineData("r")] // lower case r + [InlineData("s")] // lower case s + [InlineData("t")] // lower case t + [InlineData("u")] // lower case u + [InlineData("v")] // lower case v + [InlineData("w")] // lower case w + [InlineData("x")] // lower case x + [InlineData("y")] // lower case y + [InlineData("z")] // lower case z + public void Validate_WhenFilterAlphaKeyIsAnySingleAsciiLetter_ShouldNotHaveValidationError(string filterAlphaKey) + { + // Arrange + GetArtistsLiteQuery query = _getArtistsLiteQueryFixture.Create(filterAlphaKey: filterAlphaKey); + + // Act + List result = _validator.TestValidate(query); + + // Assert + result.ShouldNotHaveAnyValidationErrors(); + } + + [Theory] + [InlineData("")] // empty string, which is not a single letter or a special key + [InlineData("AB")] // two letters + [InlineData("ABC")] // several letters + [InlineData("1")] // a digit, which is not a letter, a number bucket or a symbol bucket + [InlineData("9")] // another digit + [InlineData("_")] // an underscore, which is not an ASCII letter + [InlineData("é")] // a non-ASCII letter + [InlineData("#!")] // the number bucket followed by another character + [InlineData("**")] // two symbol buckets, which is not the exact symbol constant + [InlineData("#A")] // the number bucket followed by a letter + [InlineData("*A")] // the symbol bucket followed by a letter + [InlineData(" A")] // a leading space followed by a letter + [InlineData("A ")] // a letter followed by a trailing space + public void Validate_WhenFilterAlphaKeyIsNotAValidAlphaKey_ShouldHaveValidationError(string filterAlphaKey) + { + // Arrange + GetArtistsLiteQuery query = _getArtistsLiteQueryFixture.Create(filterAlphaKey: filterAlphaKey); + + // Act + List result = _validator.TestValidate(query); + + // Assert + result.ShouldHaveValidationError(Errors.Library.InvalidFilterAlphaKey); + } } diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/AlbumRepositoryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/AlbumRepositoryTests.cs index 0666fcf4..c015aae5 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/AlbumRepositoryTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/AlbumRepositoryTests.cs @@ -47,6 +47,7 @@ public class AlbumRepositoryTests private readonly TagEntityFixture _tagEntityFixture = new(); private readonly GenreEntityFixture _genreEntityFixture = new(); private readonly ArtistEntityFixture _artistEntityFixture = new(); + private readonly MusicArtworkEntityFixture _musicArtworkEntityFixture = new(); private readonly PaginationDataDtoFixture _paginationDataDtoFixture = new(); /// @@ -741,6 +742,112 @@ public class AlbumRepositoryTests Assert.Equal(12, row.TotalTracks); } + [Fact] + public async Task GetAlbumsLiteByArtistIdAsync_WhenReReleaseYearIsSet_ShouldProjectItAsReleaseYear() + { + // Arrange + Guid artistId = Guid.NewGuid(); + AlbumEntity album = _albumEntityFixture.Create( + artistId: artistId, originalReleaseYear: 1975, reReleaseYear: 2011, includeTracks: false, includeMetadata: false); + _mockContext.Albums.Add(album); + await _mockContext.SaveChangesAsync(); + + PaginationDataDto paginationData = _paginationDataDtoFixture.Create(currentPage: 1, perPage: 10); + + // Act + Result> result = await _sut.GetAlbumsLiteByArtistIdAsync(artistId, paginationData, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + AlbumLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal(2011, row.ReleaseYear); + } + + [Fact] + public async Task GetAlbumsLiteByArtistIdAsync_WhenReReleaseYearIsNull_ShouldFallBackToOriginalReleaseYear() + { + // Arrange + Guid artistId = Guid.NewGuid(); + AlbumEntity album = _albumEntityFixture.Create( + artistId: artistId, originalReleaseYear: 1975, includeReReleaseYear: false, includeTracks: false, includeMetadata: false); + _mockContext.Albums.Add(album); + await _mockContext.SaveChangesAsync(); + + PaginationDataDto paginationData = _paginationDataDtoFixture.Create(currentPage: 1, perPage: 10); + + // Act + Result> result = await _sut.GetAlbumsLiteByArtistIdAsync(artistId, paginationData, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + AlbumLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal(1975, row.ReleaseYear); + } + + [Fact] + public async Task GetAlbumsLiteByArtistIdAsync_WhenTheReleaseHasTypes_ShouldProjectThem() + { + // Arrange + Guid artistId = Guid.NewGuid(); + AlbumEntity album = _albumEntityFixture.Create( + artistId: artistId, releaseType: MusicReleaseType.Single, includeTracks: false, includeMetadata: false); + _mockContext.Albums.Add(album); + await _mockContext.SaveChangesAsync(); + + PaginationDataDto paginationData = _paginationDataDtoFixture.Create(currentPage: 1, perPage: 10); + + // Act + Result> result = await _sut.GetAlbumsLiteByArtistIdAsync(artistId, paginationData, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + AlbumLiteRow row = Assert.Single(result.Value.Data); + Assert.NotNull(row.ReleaseTypes); + Assert.Equal(MusicReleaseType.Single, Assert.Single(row.ReleaseTypes)); + } + + [Fact] + public async Task GetAlbumsLiteByArtistIdAsync_WhenCoverArtworkExists_ShouldProjectTheCoverPath() + { + // Arrange + Guid artistId = Guid.NewGuid(); + AlbumEntity album = _albumEntityFixture.Create(artistId: artistId, includeTracks: false, includeMetadata: false); + _mockContext.Albums.Add(album); + _mockContext.MusicArtwork.Add( + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Album, ownerId: album.Id, artworkType: ArtworkType.Cover, fileName: "covers/opera.jpg")); + await _mockContext.SaveChangesAsync(); + + PaginationDataDto paginationData = _paginationDataDtoFixture.Create(currentPage: 1, perPage: 10); + + // Act + Result> result = await _sut.GetAlbumsLiteByArtistIdAsync(artistId, paginationData, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + AlbumLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal("covers/opera.jpg", row.CoverPath); + } + + [Fact] + public async Task GetAlbumsLiteByArtistIdAsync_WhenNoCoverArtworkExists_ShouldProjectNullCoverPath() + { + // Arrange + Guid artistId = Guid.NewGuid(); + AlbumEntity album = _albumEntityFixture.Create(artistId: artistId, includeTracks: false, includeMetadata: false); + _mockContext.Albums.Add(album); + await _mockContext.SaveChangesAsync(); + + PaginationDataDto paginationData = _paginationDataDtoFixture.Create(currentPage: 1, perPage: 10); + + // Act + Result> result = await _sut.GetAlbumsLiteByArtistIdAsync(artistId, paginationData, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + AlbumLiteRow row = Assert.Single(result.Value.Data); + Assert.Null(row.CoverPath); + } + [Fact] public async Task GetAlbumsNeedingMetadataCountAsync_WhenAlbumsHaveMixedMetadataStatuses_ShouldCountOnlyTheNotEnrichedOnesOfTheLibrary() { diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/ArtistRepositoryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/ArtistRepositoryTests.cs index 38dd1bf3..6b22bd1f 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/ArtistRepositoryTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/ArtistRepositoryTests.cs @@ -53,6 +53,7 @@ public class ArtistRepositoryTests private readonly PaginationDataDtoFixture _paginationDataDtoFixture = new(); private readonly LibraryFilterDtoFixture _libraryFilterDtoFixture = new(); private readonly BaseFilterDtoFixture _baseFilterDtoFixture = new(); + private readonly MusicArtworkEntityFixture _musicArtworkEntityFixture = new(); /// /// Initializes a new instance of the class. @@ -1041,6 +1042,28 @@ public class ArtistRepositoryTests Assert.Equal([betaArtist.Id, alphaArtist.Id], result.Value.Data.Select(artist => artist.Id)); } + [Fact] + public async Task GetAllLiteAsync_WhenIgnoringTheNamePrefixForSorting_ShouldSortByNameStrippedOfItsPrefix() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + ArtistEntity beneathArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Beneath the Surface", includeAlbums: false, includeContributors: false); + ArtistEntity beatlesArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "The Beatles", includeAlbums: false, includeContributors: false); + _mockContext.Artists.AddRange(beneathArtist, beatlesArtist); + await _mockContext.SaveChangesAsync(); + + PaginationDataDto paginationData = _paginationDataDtoFixture.Create(currentPage: 1, perPage: 10); + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, shouldIgnoreThePrefixForAlphaPicker: true); + + // Act + Result> result = await _sut.GetAllLiteAsync(paginationData, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + // Without stripping the prefix, "The Beatles" would be sorted after "Beneath the Surface", since its sort key would start with "the" instead of "beatles". + Assert.Equal(["The Beatles", "Beneath the Surface"], result.Value.Data.Select(row => row.Name)); + } + [Fact] public async Task GetAllLiteAsync_WhenCalled_ShouldProjectOnlyTheIdAndTheName() { @@ -1202,6 +1225,92 @@ public class ArtistRepositoryTests Assert.Equal(1, result.Value); } + [Fact] + public async Task GetAllLiteAsync_WhenCoverArtworkExists_ShouldReturnItsPath() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + ArtistEntity artist = _artistEntityFixture.Create(libraryId: libraryId, name: "Queen", includeAlbums: false, includeContributors: false); + _mockContext.Artists.Add(artist); + _mockContext.MusicArtwork.Add( + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Artist, ownerId: artist.Id, artworkType: ArtworkType.Cover, fileName: "covers/queen.jpg")); + await _mockContext.SaveChangesAsync(); + + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId); + + // Act + Result> result = await _sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + ArtistLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal("covers/queen.jpg", row.CoverPath); + } + + [Fact] + public async Task GetAllLiteAsync_WhenOnlyNonCoverArtworkExists_ShouldReturnNullCoverPath() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + ArtistEntity artist = _artistEntityFixture.Create(libraryId: libraryId, name: "Queen", includeAlbums: false, includeContributors: false); + _mockContext.Artists.Add(artist); + _mockContext.MusicArtwork.Add( + _musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Artist, ownerId: artist.Id, artworkType: ArtworkType.Front, fileName: "front/queen.jpg")); + await _mockContext.SaveChangesAsync(); + + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId); + + // Act + Result> result = await _sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + ArtistLiteRow row = Assert.Single(result.Value.Data); + Assert.Null(row.CoverPath); + } + + [Fact] + public async Task GetAllLiteAsync_WhenNoCoverArtworkExists_ShouldReturnNullCoverPath() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + ArtistEntity artist = _artistEntityFixture.Create(libraryId: libraryId, name: "Queen", includeAlbums: false, includeContributors: false); + _mockContext.Artists.Add(artist); + await _mockContext.SaveChangesAsync(); + + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId); + + // Act + Result> result = await _sut.GetAllLiteAsync(null, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + ArtistLiteRow row = Assert.Single(result.Value.Data); + Assert.Null(row.CoverPath); + } + + [Fact] + public async Task GetAllLiteAsync_WhenNotIgnoringTheNamePrefixForSorting_ShouldKeepThePrefix() + { + // Arrange + Guid libraryId = Guid.NewGuid(); + ArtistEntity beneathArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "Beneath the Surface", includeAlbums: false, includeContributors: false); + ArtistEntity beatlesArtist = _artistEntityFixture.Create(libraryId: libraryId, name: "The Beatles", includeAlbums: false, includeContributors: false); + _mockContext.Artists.AddRange(beneathArtist, beatlesArtist); + await _mockContext.SaveChangesAsync(); + + PaginationDataDto paginationData = _paginationDataDtoFixture.Create(currentPage: 1, perPage: 10); + LibraryFilterDto filter = _libraryFilterDtoFixture.Create(libraryId: libraryId, shouldIgnoreThePrefixForAlphaPicker: false); + + // Act + Result> result = await _sut.GetAllLiteAsync(paginationData, null, null, filter, cancellationToken: CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + // The prefix is not stripped, so the sort key of "The Beatles" starts with "the" and it sorts after "Beneath the Surface". + Assert.Equal(["Beneath the Surface", "The Beatles"], result.Value.Data.Select(row => row.Name)); + } + /// /// Marks the provided artist, its albums and its tracks as enriched. /// diff --git a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/TrackRepositoryTests.cs b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/TrackRepositoryTests.cs index 71a4ab0d..441f9a8d 100644 --- a/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/TrackRepositoryTests.cs +++ b/tests/UnitTests/Lumina.DataAccess.UnitTests/Core/Repositories/MusicLibrary/TrackRepositoryTests.cs @@ -637,7 +637,7 @@ public class TrackRepositoryTests List albumTracks = [firstDiscFirstTrack, firstDiscFirstTieTrack, firstDiscSecondTrack, secondDiscTrack]; Guid[] expectedOrder = [.. albumTracks - .OrderBy(track => track.DiscNumber) + .OrderBy(track => track.DiscNumber ?? 1) .ThenBy(track => track.TrackNumber) .ThenBy(track => track.Id) .Select(track => track.Id)]; @@ -651,6 +651,27 @@ public class TrackRepositoryTests Assert.DoesNotContain(result.Value, track => track.Id == trackOfAnotherAlbum.Id); } + [Fact] + public async Task GetByAlbumIdAsync_WhenATrackHasNoDiscNumber_ShouldTreatItAsTheFirstDisc() + { + // Arrange + Guid albumId = Guid.NewGuid(); + TrackEntity secondDiscTrack = _trackEntityFixture.Create(albumId: albumId, path: "/music/queen/second-disc.flac", trackNumber: 1, includeMetadata: false); + secondDiscTrack.DiscNumber = 2; + TrackEntity firstDiscTrackWithoutDiscNumber = _trackEntityFixture.Create(albumId: albumId, path: "/music/queen/first-disc.flac", trackNumber: 2, includeMetadata: false); + firstDiscTrackWithoutDiscNumber.DiscNumber = null; + _mockContext.Tracks.AddRange(secondDiscTrack, firstDiscTrackWithoutDiscNumber); + await _mockContext.SaveChangesAsync(); + + // Act + Result> result = await _sut.GetByAlbumIdAsync(albumId, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + // A track without a disc number belongs to the first disc, so it is ordered before the tracks of disc 2. + Assert.Equal([firstDiscTrackWithoutDiscNumber.Id, secondDiscTrack.Id], result.Value.Select(track => track.Id)); + } + [Fact] public async Task GetByAlbumIdAsync_WhenCalled_ShouldIncludeTheRelatedCollections() { @@ -707,6 +728,26 @@ public class TrackRepositoryTests Assert.Equal([firstTrack.Id, secondTrack.Id], page.Data.Select(row => row.Id)); } + [Fact] + public async Task GetTracksLiteByAlbumIdAsync_WhenATrackHasNoDiscNumber_ShouldTreatItAsTheFirstDisc() + { + // Arrange + Guid albumId = Guid.NewGuid(); + TrackEntity thirdTrack = _trackEntityFixture.Create(albumId: albumId, path: "/music/queen/third.flac", trackNumber: 3, includeMetadata: false); + thirdTrack.DiscNumber = 1; + TrackEntity secondTrackWithoutDiscNumber = _trackEntityFixture.Create(albumId: albumId, path: "/music/queen/second.flac", trackNumber: 2, includeMetadata: false); + secondTrackWithoutDiscNumber.DiscNumber = null; + _mockContext.Tracks.AddRange(thirdTrack, secondTrackWithoutDiscNumber); + await _mockContext.SaveChangesAsync(); + + // Act + Result> result = await _sut.GetTracksLiteByAlbumIdAsync(albumId, null, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + Assert.Equal([secondTrackWithoutDiscNumber.Id, thirdTrack.Id], result.Value.Data.Select(row => row.Id)); + } + [Theory] [InlineData(1, 2, 1, 2)] // The first page is fully returned. [InlineData(2, 2, 2, 2)] // A middle page is fully returned. @@ -792,6 +833,28 @@ public class TrackRepositoryTests Assert.Equal("Killer Queen", row.Title); Assert.Equal(9, row.TrackNumber); Assert.Equal(3, row.DiscNumber); + Assert.Equal(track.DurationInSeconds, row.DurationInSeconds); + } + + [Fact] + public async Task GetTracksLiteByAlbumIdAsync_WhenCalled_ShouldProjectTheDurationInSeconds() + { + // Arrange + Guid albumId = Guid.NewGuid(); + TrackEntity track = _trackEntityFixture.Create(albumId: albumId, path: "/music/queen/the-prophet-song.flac", includeMetadata: false); + track.DurationInSeconds = 367; + _mockContext.Tracks.Add(track); + await _mockContext.SaveChangesAsync(); + + PaginationDataDto paginationData = _paginationDataDtoFixture.Create(currentPage: 1, perPage: 10); + + // Act + Result> result = await _sut.GetTracksLiteByAlbumIdAsync(albumId, paginationData, CancellationToken.None); + + // Assert + Assert.False(result.IsFailure); + TrackLiteRow row = Assert.Single(result.Value.Data); + Assert.Equal(367, row.DurationInSeconds); } [Fact]