mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Extends the music library listings with covers, sorting and alpha filtering.
This commit is contained in:
1 parent
0019821e87
commit
9d82f283e4
69 files changed
+3613
-268
No files matched your search
@@ -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,
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -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"
|
||||
|
||||
+1
-1
@@ -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}}
|
||||
+17
@@ -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.
|
||||
/// </summary>
|
||||
public int TotalTracks { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path of the image representing the album, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the release year of the album (the re-release year, if available, or the original release year), if known.
|
||||
/// </summary>
|
||||
public int? ReleaseYear { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set of types of the release.
|
||||
/// </summary>
|
||||
public List<MusicReleaseType>? ReleaseTypes { get; init; }
|
||||
}
|
||||
+5
@@ -18,4 +18,9 @@ public sealed record ArtistLiteRow
|
||||
/// Gets the name of the artist.
|
||||
/// </summary>
|
||||
public required string Name { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path of the image representing the artist, if available.
|
||||
/// </summary>
|
||||
public string? CoverPath { get; init; }
|
||||
}
|
||||
+5
@@ -28,4 +28,9 @@ public sealed record TrackLiteRow
|
||||
/// Gets the number of the disc the track belongs to, if applicable.
|
||||
/// </summary>
|
||||
public int? DiscNumber { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the duration of the track in seconds.
|
||||
/// </summary>
|
||||
public int DurationInSeconds { get; init; }
|
||||
}
|
||||
+6
-2
@@ -157,8 +157,10 @@ public static class AlbumEntityMapping
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="AlbumResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <param name="coverPath">The optional path of the image representing the album.</param>
|
||||
/// <param name="artwork">The optional stored artwork of the album, in display order.</param>
|
||||
/// <returns>The converted response entity.</returns>
|
||||
public static AlbumResponse ToResponse(this AlbumEntity repositoryEntity)
|
||||
public static AlbumResponse ToResponse(this AlbumEntity repositoryEntity, string? coverPath = null, IReadOnlyList<MediaArtworkDto>? 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 ?? []);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+4
-1
@@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+4
-2
@@ -147,8 +147,9 @@ public static class ArtistEntityMapping
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="ArtistResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <param name="coverPath">The optional path of the image representing the artist.</param>
|
||||
/// <returns>The converted response entity.</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+2
-1
@@ -23,7 +23,8 @@ public static class ArtistLiteRowMapping
|
||||
{
|
||||
return new ArtistLiteResponse(
|
||||
readModel.Id,
|
||||
readModel.Name);
|
||||
readModel.Name,
|
||||
readModel.CoverPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+5
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -25,7 +25,8 @@ public static class TrackLiteRowMapping
|
||||
readModel.Id,
|
||||
readModel.Title,
|
||||
readModel.TrackNumber,
|
||||
readModel.DiscNumber);
|
||||
readModel.DiscNumber,
|
||||
readModel.DurationInSeconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+20
-1
@@ -8,11 +8,15 @@ using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwn
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
@@ -88,6 +92,21 @@ public class GetAlbumQueryHandler : IQueryHandler<GetAlbumQuery, Result<AlbumRes
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
return existingAlbum.ToResponse();
|
||||
// The artwork of an album is stored in the MusicArtwork table, not on the album row, so it is loaded to expose the cover
|
||||
// and every other stored piece of artwork.
|
||||
Result<IReadOnlyList<MusicArtworkEntity>> getArtworkResult = await _unitOfWork.MusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Album, albumId, cancellationToken).ConfigureAwait(false);
|
||||
if (getArtworkResult.IsFailure)
|
||||
return getArtworkResult.Errors;
|
||||
string? coverPath = getArtworkResult.Value
|
||||
.Where(artwork => artwork.ArtworkType == ArtworkType.Cover)
|
||||
.Select(artwork => artwork.FileName)
|
||||
.FirstOrDefault();
|
||||
|
||||
// Only the artwork whose file has already been stored can be presented, so the ones that are still pending resolution are left out.
|
||||
List<MediaArtworkDto> artwork = [.. getArtworkResult.Value
|
||||
.Where(storedArtwork => !string.IsNullOrWhiteSpace(storedArtwork.FileName))
|
||||
.Select(storedArtwork => new MediaArtworkDto(storedArtwork.ArtworkType, storedArtwork.Ordinal, storedArtwork.FileName!))];
|
||||
|
||||
return existingAlbum.ToResponse(coverPath, artwork);
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -11,8 +11,11 @@ using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.A
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
@@ -87,6 +90,15 @@ public class GetArtistQueryHandler : IQueryHandler<GetArtistQuery, Result<Artist
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
return existingArtist.ToResponse();
|
||||
// The artwork of the artist is stored separately from the artist, so it is loaded to expose the cover of the artist in the response.
|
||||
Result<IReadOnlyList<MusicArtworkEntity>> getArtworkResult = await _unitOfWork.MusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Artist, artistId, cancellationToken).ConfigureAwait(false);
|
||||
if (getArtworkResult.IsFailure)
|
||||
return getArtworkResult.Errors;
|
||||
string? coverPath = getArtworkResult.Value
|
||||
.Where(artwork => artwork.ArtworkType == ArtworkType.Cover)
|
||||
.Select(artwork => artwork.FileName)
|
||||
.FirstOrDefault();
|
||||
|
||||
return existingArtist.ToResponse(coverPath);
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -12,9 +13,17 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists
|
||||
/// <param name="LibraryId">The unique identifier of the media library whose artists are retrieved, taken from the route.</param>
|
||||
/// <param name="PaginationData">The object containing the requested pagination data.</param>
|
||||
/// <param name="SearchTerm">The search term used to filter the artists by name.</param>
|
||||
/// <param name="FilterAlphaKey">The alpha key used to filter the artists by the first character of their name.</param>
|
||||
/// <param name="ShouldIgnoreThePrefixForAlphaPicker">Whether the leading "The " prefix of a name should be ignored when computing the alpha key, or not.</param>
|
||||
/// <param name="SortBy">The name of the field by which to sort the results.</param>
|
||||
/// <param name="SortOrder">The direction in which to sort the results.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
public record GetArtistsLiteQuery(
|
||||
string? LibraryId,
|
||||
PaginationDataDto? PaginationData,
|
||||
string? SearchTerm
|
||||
string? SearchTerm,
|
||||
string? FilterAlphaKey,
|
||||
bool ShouldIgnoreThePrefixForAlphaPicker,
|
||||
string? SortBy,
|
||||
SortOrder? SortOrder
|
||||
) : IQuery;
|
||||
+6
-2
@@ -78,12 +78,16 @@ public class GetArtistsLiteQueryHandler : IQueryHandler<GetArtistsLiteQuery, Res
|
||||
LibraryFilterDto filter = new()
|
||||
{
|
||||
LibraryId = libraryId,
|
||||
SearchTerm = query.SearchTerm
|
||||
SearchTerm = query.SearchTerm,
|
||||
FilterAlphaKey = query.FilterAlphaKey,
|
||||
ShouldIgnoreThePrefixForAlphaPicker = query.ShouldIgnoreThePrefixForAlphaPicker
|
||||
};
|
||||
|
||||
Result<PaginatedResultDto<ArtistLiteRow>> getArtistsResult = await _unitOfWork.ArtistRepository.GetAllLiteAsync(
|
||||
query.PaginationData,
|
||||
filterModel: filter,
|
||||
query.SortBy,
|
||||
query.SortOrder,
|
||||
filter,
|
||||
cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
return getArtistsResult.Match(value => Result.From(value.ToResponses()), errors => errors);
|
||||
}
|
||||
|
||||
+10
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
@@ -26,5 +27,14 @@ public class GetArtistsLiteQueryValidator : AbstractValidator<GetArtistsLiteQuer
|
||||
.Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty)
|
||||
.When(query => query.LibraryId is not null && query.LibraryId.Length > 0)
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
// The alpha key must be exactly one of the three picker bucket kinds, so that the filter specification can
|
||||
// derive the key of a name unambiguously: no filter, a number bucket, a symbol bucket, or a single ASCII letter.
|
||||
RuleFor(query => query.FilterAlphaKey)
|
||||
.Must(alphaKey => alphaKey is null
|
||||
|| alphaKey == LibraryItemAlphaKeys.NUMBER
|
||||
|| alphaKey == LibraryItemAlphaKeys.SYMBOL
|
||||
|| (alphaKey.Length == 1 && char.IsAsciiLetter(alphaKey[0])))
|
||||
.WithError(Errors.Library.InvalidFilterAlphaKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a stored piece of artwork of a media item.
|
||||
/// </summary>
|
||||
/// <param name="Type">The type of the artwork, like the cover or the back of the media item.</param>
|
||||
/// <param name="Ordinal">The ordinal of the artwork within its type, so that multiple artworks of the same type can be ordered.</param>
|
||||
/// <param name="Path">The relative path of the stored artwork file.</param>
|
||||
[DebuggerDisplay("Type: {Type}, Ordinal: {Ordinal}, Path: {Path}")]
|
||||
public sealed record MediaArtworkDto(
|
||||
ArtworkType Type,
|
||||
int Ordinal,
|
||||
string Path
|
||||
);
|
||||
+14
-1
@@ -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
|
||||
/// <param name="CurrentPage">The page of results to retrieve. Optional.</param>
|
||||
/// <param name="PerPage">The maximum number of artists to retrieve per page. Optional.</param>
|
||||
/// <param name="SearchTerm">The search term used to filter the artists by name. Optional.</param>
|
||||
/// <param name="FilterAlphaKey">
|
||||
/// The alpha key used to filter the results by the first character of their name, for the alpha picker. Optional.
|
||||
/// Can be <see langword="null"/> 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.
|
||||
/// </param>
|
||||
/// <param name="ShouldIgnoreThePrefixForAlphaPicker">Whether the leading "The " prefix of a name should be ignored when computing the alpha key, or not. Optional.</param>
|
||||
/// <param name="SortBy">The name of the field by which to sort the results. Optional.</param>
|
||||
/// <param name="SortOrder">The direction in which to sort the results. Optional.</param>
|
||||
[DebuggerDisplay("SearchTerm: {SearchTerm}")]
|
||||
public record GetArtistsLiteRequest(
|
||||
int? CurrentPage,
|
||||
int? PerPage,
|
||||
string? SearchTerm
|
||||
string? SearchTerm,
|
||||
string? FilterAlphaKey,
|
||||
bool ShouldIgnoreThePrefixForAlphaPicker,
|
||||
string? SortBy,
|
||||
SortOrder? SortOrder
|
||||
);
|
||||
+9
-1
@@ -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
|
||||
/// <param name="Id">The Id of the album.</param>
|
||||
/// <param name="Title">The title of the album.</param>
|
||||
/// <param name="TotalTracks">The number of tracks of the release.</param>
|
||||
/// <param name="CoverPath">The path of the image representing the album, if available.</param>
|
||||
/// <param name="ReleaseYear">The release year of the album (the re-release year, if available, or the original release year), if known.</param>
|
||||
/// <param name="ReleaseTypes">The set of types of the release.</param>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public record AlbumLiteResponse(
|
||||
Guid Id,
|
||||
string Title,
|
||||
int TotalTracks
|
||||
int TotalTracks,
|
||||
string? CoverPath,
|
||||
int? ReleaseYear,
|
||||
List<MusicReleaseType>? ReleaseTypes
|
||||
);
|
||||
+6
-1
@@ -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
|
||||
/// <param name="Contributors">The list of references to the media contributors that performed on the album, each with the role they played.</param>
|
||||
/// <param name="Ratings">The list of ratings for this album.</param>
|
||||
/// <param name="Tracks">The list of tracks of the album.</param>
|
||||
/// <param name="CoverPath">The path of the image representing the album, if available.</param>
|
||||
/// <param name="Artwork">The stored artwork of the album, in display order, so that all of its pieces can be presented, not just the cover.</param>
|
||||
[DebuggerDisplay("Title: {Metadata.Title}")]
|
||||
public record AlbumResponse(
|
||||
Guid Id,
|
||||
@@ -51,5 +54,7 @@ public record AlbumResponse(
|
||||
DateTime? UpdatedOnUtc,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AudioRatingDto>? Ratings,
|
||||
List<TrackResponse>? Tracks
|
||||
List<TrackResponse>? Tracks,
|
||||
string? CoverPath,
|
||||
IReadOnlyList<MediaArtworkDto> Artwork
|
||||
);
|
||||
+3
-1
@@ -10,8 +10,10 @@ namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Arti
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the artist.</param>
|
||||
/// <param name="Name">The name of the artist.</param>
|
||||
/// <param name="CoverPath">The path of the image representing the artist, if available.</param>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public record ArtistLiteResponse(
|
||||
Guid Id,
|
||||
string Name
|
||||
string Name,
|
||||
string? CoverPath
|
||||
);
|
||||
+3
-1
@@ -25,6 +25,7 @@ namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Arti
|
||||
/// <param name="Contributors">The list of references to the media contributors that make up the artist, each with the role they played.</param>
|
||||
/// <param name="Ratings">The list of ratings for this artist.</param>
|
||||
/// <param name="Albums">The list of albums of the artist, each with its own list of tracks.</param>
|
||||
/// <param name="CoverPath">The path of the image representing the artist, if available.</param>
|
||||
[DebuggerDisplay("Name: {Metadata.Name}")]
|
||||
public record ArtistResponse(
|
||||
Guid Id,
|
||||
@@ -38,5 +39,6 @@ public record ArtistResponse(
|
||||
DateTime? UpdatedOnUtc,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AudioRatingDto>? Ratings,
|
||||
List<AlbumResponse>? Albums
|
||||
List<AlbumResponse>? Albums,
|
||||
string? CoverPath
|
||||
);
|
||||
+3
-1
@@ -12,10 +12,12 @@ namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Trac
|
||||
/// <param name="Title">The title of the track.</param>
|
||||
/// <param name="TrackNumber">The number of the track on its disc.</param>
|
||||
/// <param name="DiscNumber">The number of the disc the track belongs to, if applicable.</param>
|
||||
/// <param name="DurationInSeconds">The duration of the track in seconds.</param>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public record TrackLiteResponse(
|
||||
Guid Id,
|
||||
string Title,
|
||||
int TrackNumber,
|
||||
int? DiscNumber
|
||||
int? DiscNumber,
|
||||
int DurationInSeconds
|
||||
);
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
/// </summary>
|
||||
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<ArtistEntity> orderedArtistsQuery = ApplySorting(artistsQuery, sortBy, sortOrder ?? SortOrder.Ascending);
|
||||
IQueryable<ArtistEntity> 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<ArtistLiteRow> liteRowsQuery = ApplySorting(artistsQuery, sortBy, sortOrder ?? SortOrder.Ascending)
|
||||
IQueryable<ArtistLiteRow> 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
|
||||
/// <returns>A filter specification that can be used to query artists matching the provided criteria.</returns>
|
||||
private static FilterSpecification<ArtistEntity>? BuildFilterSpecification(LibraryFilterDto libraryFilter)
|
||||
{
|
||||
FilterSpecification<ArtistEntity>? 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -620,8 +642,8 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
/// <param name="artistsQuery">The query to sort.</param>
|
||||
/// <param name="sortBy">The field to sort by (case-insensitive).</param>
|
||||
/// <param name="sortOrder">The direction of the sorting.</param>
|
||||
/// <returns>An ordered artists query.</returns>
|
||||
private static IOrderedQueryable<ArtistEntity> ApplySorting(IQueryable<ArtistEntity> artistsQuery, string? sortBy, SortOrder sortOrder)
|
||||
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether a leading "the " prefix of a name is ignored when deriving the name sort key, or not.</param>
|
||||
private static IOrderedQueryable<ArtistEntity> ApplySorting(IQueryable<ArtistEntity> 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),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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 <see langword="null"/>, and optionally
|
||||
/// stripped of a leading "the " prefix.
|
||||
/// </summary>
|
||||
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether a leading "the " prefix of a name is ignored when deriving the name sort key, or not.</param>
|
||||
/// <returns>An expression that evaluates to the name sort key of an artist.</returns>
|
||||
private static Expression<Func<ArtistEntity, string>> 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<Func<ArtistEntity, string>>(effectiveName, artist);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the artist of the library identified by <paramref name="libraryId"/> that has the provided <paramref name="name"/>.
|
||||
/// </summary>
|
||||
@@ -793,4 +845,19 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
.ExecuteUpdateAsync(setters => setters.SetProperty(artist => artist.MetadataStatus, MetadataStatus.Pending), cancellationToken).ConfigureAwait(false);
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all the artists of the media library identified by <paramref name="libraryId"/>, together with their albums and tracks and their related data.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose artists are deleted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Deleted>> 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;
|
||||
}
|
||||
}
|
||||
+127
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
internal sealed class ArtistAlphaFilterSpecification : FilterSpecification<ArtistEntity>
|
||||
{
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ArtistAlphaFilterSpecification"/> class.
|
||||
/// </summary>
|
||||
/// <param name="filterAlphaKey">The alpha key to filter by. A single ASCII letter, <see cref="LibraryItemAlphaKeys.NUMBER"/>, or <see cref="LibraryItemAlphaKeys.SYMBOL"/>.</param>
|
||||
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether the leading "The " prefix of a name should be ignored when computing the alpha key, or not.</param>
|
||||
public ArtistAlphaFilterSpecification(string? filterAlphaKey, bool shouldIgnoreThePrefixForAlphaPicker)
|
||||
{
|
||||
_filterAlphaKey = filterAlphaKey;
|
||||
_shouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a LINQ expression that represents the predicate defined by the current specification.
|
||||
/// </summary>
|
||||
/// <returns>An expression tree that can be used to evaluate whether an <see cref="ArtistEntity"/> satisfies the specification criteria.</returns>
|
||||
public override Expression<Func<ArtistEntity, bool>> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the expression representing the lowercased name used to derive the alpha key, falling back to an empty string
|
||||
/// when the name is <see langword="null"/> or empty, and optionally stripped of a leading "the " prefix.
|
||||
/// </summary>
|
||||
/// <param name="artist">The parameter representing the artist entity.</param>
|
||||
/// <returns>The expression of the effective name.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a predicate that is satisfied when the effective name starts with a glob pattern.
|
||||
/// </summary>
|
||||
/// <param name="artist">The parameter representing the artist entity.</param>
|
||||
/// <param name="effectiveName">The expression of the effective name.</param>
|
||||
/// <param name="globPattern">The glob pattern the effective name must match.</param>
|
||||
/// <returns>The built predicate.</returns>
|
||||
private static Expression<Func<ArtistEntity, bool>> BuildGlobPredicate(ParameterExpression artist, Expression effectiveName, string globPattern)
|
||||
{
|
||||
MethodCallExpression glob = BuildGlobCall(effectiveName, globPattern);
|
||||
return Expression.Lambda<Func<ArtistEntity, bool>>(glob, artist);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a predicate that is satisfied when the first character of the effective name is neither a letter nor a digit.
|
||||
/// </summary>
|
||||
/// <param name="artist">The parameter representing the artist entity.</param>
|
||||
/// <param name="effectiveName">The expression of the effective name.</param>
|
||||
/// <returns>The built predicate.</returns>
|
||||
private static Expression<Func<ArtistEntity, bool>> BuildSymbolPredicate(ParameterExpression artist, Expression effectiveName)
|
||||
{
|
||||
Expression notLetter = Expression.Not(BuildGlobCall(effectiveName, "[a-z]*"));
|
||||
Expression notDigit = Expression.Not(BuildGlobCall(effectiveName, "[0-9]*"));
|
||||
return Expression.Lambda<Func<ArtistEntity, bool>>(Expression.AndAlso(notLetter, notDigit), artist);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the call to <see cref="SqliteDbFunctionsExtensions.Glob"/> for the effective name and the provided glob pattern.
|
||||
/// </summary>
|
||||
/// <param name="effectiveName">The expression of the effective name.</param>
|
||||
/// <param name="globPattern">The glob pattern the effective name must match.</param>
|
||||
/// <returns>The built method call.</returns>
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -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<TrackLiteRow> 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)
|
||||
|
||||
+2
@@ -373,6 +373,8 @@ public class AddAlbumEndpointSummary : Summary<AddAlbumEndpoint, AddAlbumRequest
|
||||
ResponseParam<AlbumResponse>(r => r.Metadata!.Genres, "The list of genres associated with the album.");
|
||||
ResponseParam<AlbumResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album.");
|
||||
ResponseParam<AlbumResponse>(r => r.Tracks, "The list of tracks of the album.");
|
||||
ResponseParam<AlbumResponse>(r => r.CoverPath, "The path of the image representing the album, if available.");
|
||||
ResponseParam<AlbumResponse>(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(
|
||||
|
||||
+2
@@ -177,6 +177,8 @@ public class UpdateAlbumEndpointSummary : Summary<UpdateAlbumEndpoint, UpdateAlb
|
||||
ResponseParam<AlbumResponse>(r => r.Metadata!.Genres, "The list of genres associated with the album.");
|
||||
ResponseParam<AlbumResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album.");
|
||||
ResponseParam<AlbumResponse>(r => r.Tracks, "The list of tracks of the album.");
|
||||
ResponseParam<AlbumResponse>(r => r.CoverPath, "The path of the image representing the album, if available.");
|
||||
ResponseParam<AlbumResponse>(r => r.Artwork, "The stored artwork of the album, in display order, if applicable.");
|
||||
|
||||
Response(200, "The updated album is returned.",
|
||||
example: new AlbumResponse(
|
||||
|
||||
+3
@@ -455,6 +455,8 @@ public class AddArtistEndpointSummary : Summary<AddArtistEndpoint, AddArtistRequ
|
||||
ResponseParam<ArtistResponse>(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<ArtistResponse>(r => r.Albums![0].Ratings, "The list of ratings for the album.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks, "The list of tracks of the album.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].CoverPath, "The path of the image representing the album, if available.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Artwork, "The stored artwork of the album, in display order, if applicable.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Id, "The Id of the track.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].AlbumId, "The Id of the album the track belongs to.");
|
||||
ResponseParam<ArtistResponse>(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<AddArtistEndpoint, AddArtistRequ
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Ratings, "The list of ratings for the track.");
|
||||
ResponseParam<ArtistResponse>(r => r.CreatedOnUtc, "The date and time when the artist was created.");
|
||||
ResponseParam<ArtistResponse>(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable.");
|
||||
ResponseParam<ArtistResponse>(r => r.CoverPath, "The path of the image representing the artist, if available.");
|
||||
|
||||
Response(201, "The new artist is returned.",
|
||||
example: new ArtistResponse(
|
||||
|
||||
+1
@@ -39,6 +39,7 @@ public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, EmptyRequest>
|
||||
ResponseParam<ArtistResponse>(r => r.Albums, "The list of albums of the artist, each with its own list of tracks.");
|
||||
ResponseParam<ArtistResponse>(r => r.CreatedOnUtc, "The date and time when the artist was created.");
|
||||
ResponseParam<ArtistResponse>(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable.");
|
||||
ResponseParam<ArtistResponse>(r => r.CoverPath, "The path of the image representing the artist, if available.");
|
||||
|
||||
Response(200, "The requested artist is returned.",
|
||||
example: new ArtistResponse(
|
||||
|
||||
+2
@@ -65,6 +65,8 @@ public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, E
|
||||
ResponseParam<AlbumResponse>(r => r.Metadata!.Genres, "The list of genres associated with the album.");
|
||||
ResponseParam<AlbumResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album.");
|
||||
ResponseParam<AlbumResponse>(r => r.Tracks, "The list of tracks of the album.");
|
||||
ResponseParam<AlbumResponse>(r => r.CoverPath, "The path of the image representing the album, if available.");
|
||||
ResponseParam<AlbumResponse>(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[]
|
||||
|
||||
+3
@@ -36,6 +36,9 @@ public class GetArtistAlbumsLiteEndpointSummary : Summary<GetArtistAlbumsLiteEnd
|
||||
ResponseParam<AlbumLiteResponse>(r => r.Id, "The Id of the album.");
|
||||
ResponseParam<AlbumLiteResponse>(r => r.Title, "The title of the album.");
|
||||
ResponseParam<AlbumLiteResponse>(r => r.TotalTracks, "The number of tracks of the release.");
|
||||
ResponseParam<AlbumLiteResponse>(r => r.CoverPath, "The path of the image representing the album, if available.");
|
||||
ResponseParam<AlbumLiteResponse>(r => r.ReleaseYear, "The release year of the album (the re-release year, if available, or the original release year), if known.");
|
||||
ResponseParam<AlbumLiteResponse>(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<AlbumLiteResponse>
|
||||
|
||||
+1
@@ -51,6 +51,7 @@ public class GetArtistsEndpointSummary : Summary<GetArtistsEndpoint, GetArtistsR
|
||||
ResponseParam<ArtistResponse>(r => r.Albums, "The list of albums of the artist, each with its own list of tracks.");
|
||||
ResponseParam<ArtistResponse>(r => r.CreatedOnUtc, "The date and time when the artist was created.");
|
||||
ResponseParam<ArtistResponse>(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable.");
|
||||
ResponseParam<ArtistResponse>(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<ArtistResponse>
|
||||
|
||||
+2
-1
@@ -39,12 +39,13 @@ public class GetArtistsLiteEndpointSummary : Summary<GetArtistsLiteEndpoint, Get
|
||||
RequestParam(r => r.PerPage, "The maximum number of artists to retrieve per page. Optional.");
|
||||
RequestParam(r => r.SearchTerm, "The search term used to filter the artists by name. Optional.");
|
||||
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<ArtistLiteResponse>(r => r.Id, "The Id of the artist.");
|
||||
ResponseParam<ArtistLiteResponse>(r => r.Name, "The name of the artist.");
|
||||
ResponseParam<ArtistLiteResponse>(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<ArtistLiteResponse>
|
||||
|
||||
+3
@@ -454,6 +454,8 @@ public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateA
|
||||
ResponseParam<ArtistResponse>(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<ArtistResponse>(r => r.Albums![0].Ratings, "The list of ratings for the album.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks, "The list of tracks of the album.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].CoverPath, "The path of the image representing the album, if available.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Artwork, "The stored artwork of the album, in display order, if applicable.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Id, "The Id of the track.");
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].AlbumId, "The Id of the album the track belongs to.");
|
||||
ResponseParam<ArtistResponse>(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<UpdateArtistEndpoint, UpdateA
|
||||
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Ratings, "The list of ratings for the track.");
|
||||
ResponseParam<ArtistResponse>(r => r.CreatedOnUtc, "The date and time when the artist was created.");
|
||||
ResponseParam<ArtistResponse>(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable.");
|
||||
ResponseParam<ArtistResponse>(r => r.CoverPath, "The path of the image representing the artist, if available.");
|
||||
|
||||
Guid artistId = Guid.NewGuid();
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
|
||||
+21
-2
@@ -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();
|
||||
|
||||
/// <summary>
|
||||
@@ -23,17 +27,32 @@ public class AlbumLiteRowFixture
|
||||
/// <param name="id">Optional. The Id of the album.</param>
|
||||
/// <param name="title">Optional. The title of the album.</param>
|
||||
/// <param name="totalTracks">Optional. The number of tracks of the release.</param>
|
||||
/// <param name="coverPath">Optional. The path of the image representing the album.</param>
|
||||
/// <param name="releaseYear">Optional. The release year of the album.</param>
|
||||
/// <param name="releaseTypes">Optional. The set of types of the release.</param>
|
||||
/// <param name="includeCoverPath">Whether the cover path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeReleaseYear">Whether the release year should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeReleaseTypes">Whether the release types should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="AlbumLiteRow"/>.</returns>
|
||||
public AlbumLiteRow Create(
|
||||
Guid? id = null,
|
||||
string? title = null,
|
||||
int? totalTracks = null)
|
||||
int? totalTracks = null,
|
||||
string? coverPath = null,
|
||||
int? releaseYear = null,
|
||||
List<MusicReleaseType>? 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<MusicReleaseType>())]) : null
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -22,15 +22,20 @@ public class ArtistLiteRowFixture
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the artist.</param>
|
||||
/// <param name="name">Optional. The name of the artist.</param>
|
||||
/// <param name="coverPath">Optional. The path of the image representing the artist.</param>
|
||||
/// <param name="includeCoverPath">Whether the cover path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="ArtistLiteRow"/>.</returns>
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -25,20 +25,23 @@ public class TrackLiteRowFixture
|
||||
/// <param name="trackNumber">Optional. The number of the track on its disc.</param>
|
||||
/// <param name="discNumber">Optional. The number of the disc the track belongs to.</param>
|
||||
/// <param name="includeDiscNumber">Whether the disc number should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="durationInSeconds">Optional. The duration of the track in seconds.</param>
|
||||
/// <returns>The created <see cref="TrackLiteRow"/>.</returns>
|
||||
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)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+14
-1
@@ -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
|
||||
/// <param name="libraryId">Optional. The Id of the media library whose artists are retrieved, taken from the route.</param>
|
||||
/// <param name="paginationData">Optional. The pagination data of the query.</param>
|
||||
/// <param name="searchTerm">Optional. The search term used to filter the artists by name.</param>
|
||||
/// <param name="filterAlphaKey">Optional. The alpha key used to filter the results by the first character of their name, for the alpha picker.</param>
|
||||
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Optional. Whether the leading "The " prefix of a name should be ignored when computing the alpha key, or not.</param>
|
||||
/// <param name="sortBy">Optional. The name of the field by which to sort the results.</param>
|
||||
/// <param name="sortOrder">Optional. The direction in which to sort the results.</param>
|
||||
/// <param name="includeLibraryId">Whether the library Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includePaginationData">Whether the pagination data should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeSearchTerm">Whether the search term should be included, or forced to <see langword="null"/>.</param>
|
||||
@@ -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<SortOrder>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaArtworkDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaArtworkDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="MediaArtworkDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="type">Optional. The type of the artwork.</param>
|
||||
/// <param name="ordinal">Optional. The ordinal of the artwork within its type.</param>
|
||||
/// <param name="path">Optional. The relative path of the stored artwork file.</param>
|
||||
/// <returns>The created <see cref="MediaArtworkDto"/>.</returns>
|
||||
public MediaArtworkDto Create(
|
||||
ArtworkType? type = null,
|
||||
int? ordinal = null,
|
||||
string? path = null)
|
||||
{
|
||||
return new MediaArtworkDto(
|
||||
type ?? _faker.PickRandom<ArtworkType>(),
|
||||
ordinal ?? _faker.Random.Int(0, 5),
|
||||
path ?? _faker.System.FilePath());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="MediaArtworkDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<MediaArtworkDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+32
-2
@@ -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
|
||||
/// <param name="currentPage">Optional. The page of results to retrieve.</param>
|
||||
/// <param name="perPage">Optional. The maximum number of artists to retrieve per page.</param>
|
||||
/// <param name="searchTerm">Optional. The search term used to filter the artists by name.</param>
|
||||
/// <param name="filterAlphaKey">Optional. The alpha key used to filter the results by the first character of their name, for the alpha picker.</param>
|
||||
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Optional. Whether the leading "The " prefix of a name should be ignored when computing the alpha key, or not.</param>
|
||||
/// <param name="sortBy">Optional. The name of the field by which to sort the results.</param>
|
||||
/// <param name="sortOrder">Optional. The direction in which to sort the results.</param>
|
||||
/// <param name="includeCurrentPage">Whether the current page should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includePerPage">Whether the per page count should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeSearchTerm">Whether the search term should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeFilterAlphaKey">Whether the filter alpha key should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeSortBy">Whether the sort field should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeSortOrder">Whether the sort order should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created request to get the lightweight read models of the artists of a media library.</returns>
|
||||
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<SortOrder>()) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,4 +68,15 @@ public class GetArtistsLiteRequestFixture
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid alpha key: a single ASCII letter, "#" for names starting with a digit, or "*" for any other first character.
|
||||
/// </summary>
|
||||
/// <returns>The created alpha key.</returns>
|
||||
private string CreateFilterAlphaKey()
|
||||
{
|
||||
return _faker.Random.Bool()
|
||||
? _faker.Random.Char('A', 'Z').ToString()
|
||||
: _faker.Random.ListItem(new[] { "#", "*" });
|
||||
}
|
||||
}
|
||||
+22
-2
@@ -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
|
||||
/// <param name="id">Optional. The Id of the album.</param>
|
||||
/// <param name="title">Optional. The title of the album.</param>
|
||||
/// <param name="totalTracks">Optional. The number of tracks of the release.</param>
|
||||
/// <param name="coverPath">Optional. The path of the image representing the album.</param>
|
||||
/// <param name="releaseYear">Optional. The release year of the album.</param>
|
||||
/// <param name="releaseTypes">Optional. The set of types of the release.</param>
|
||||
/// <param name="includeCoverPath">Whether the cover path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeReleaseYear">Whether the release year should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeReleaseTypes">Whether the release types should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="AlbumLiteResponse"/>.</returns>
|
||||
public AlbumLiteResponse Create(
|
||||
Guid? id = null,
|
||||
string? title = null,
|
||||
int? totalTracks = null)
|
||||
int? totalTracks = null,
|
||||
string? coverPath = null,
|
||||
int? releaseYear = null,
|
||||
List<MusicReleaseType>? releaseTypes = null,
|
||||
bool includeCoverPath = true,
|
||||
bool includeReleaseYear = true,
|
||||
bool includeReleaseTypes = true)
|
||||
{
|
||||
List<MusicReleaseType>? resolvedReleaseTypes = includeReleaseTypes
|
||||
? (releaseTypes ?? [.. Enumerable.Range(0, _faker.Random.Int(1, 3)).Select(_ => _faker.PickRandom<MusicReleaseType>())])
|
||||
: 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+19
-2
@@ -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();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="AlbumResponse"/>.
|
||||
@@ -51,6 +54,8 @@ public class AlbumResponseFixture
|
||||
/// <param name="contributors">Optional. The list of contributor references of the album.</param>
|
||||
/// <param name="ratings">Optional. The list of ratings of the album.</param>
|
||||
/// <param name="tracks">Optional. The list of tracks of the album.</param>
|
||||
/// <param name="coverPath">Optional. The path of the image representing the album.</param>
|
||||
/// <param name="artwork">Optional. The stored artwork of the album, in display order.</param>
|
||||
/// <param name="includeMediaFormat">Whether the media format should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includePackaging">Whether the packaging should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeBarcode">Whether the barcode should be included, or forced to <see langword="null"/>.</param>
|
||||
@@ -64,6 +69,8 @@ public class AlbumResponseFixture
|
||||
/// <param name="includeContributors">Whether the contributors should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeRatings">Whether the ratings should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeTracks">Whether the tracks should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeCoverPath">Whether the cover path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeArtwork">Whether the artwork should be included, or forced to an empty collection.</param>
|
||||
/// <returns>The created <see cref="AlbumResponse"/>.</returns>
|
||||
public AlbumResponse Create(
|
||||
Guid? id = null,
|
||||
@@ -84,6 +91,8 @@ public class AlbumResponseFixture
|
||||
List<MediaContributorReferenceDto>? contributors = null,
|
||||
List<AudioRatingDto>? ratings = null,
|
||||
List<TrackResponse>? tracks = null,
|
||||
string? coverPath = null,
|
||||
List<MediaArtworkDto>? 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<MediaArtworkDto> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+7
-2
@@ -22,14 +22,19 @@ public class ArtistLiteResponseFixture
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the artist.</param>
|
||||
/// <param name="name">Optional. The name of the artist.</param>
|
||||
/// <param name="coverPath">Optional. The path of the image representing the artist.</param>
|
||||
/// <param name="includeCoverPath">Whether the cover path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="ArtistLiteResponse"/>.</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+7
-2
@@ -44,6 +44,7 @@ public class ArtistResponseFixture
|
||||
/// <param name="albums">Optional. The list of albums of the artist.</param>
|
||||
/// <param name="createdOnUtc">Optional. The date and time when the artist was created.</param>
|
||||
/// <param name="updatedOnUtc">Optional. The date and time when the artist was updated.</param>
|
||||
/// <param name="coverPath">Optional. The path of the image representing the artist.</param>
|
||||
/// <param name="includeWebsite">Whether the website should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeMusicBrainzArtistId">Whether the MusicBrainz artist Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeIpis">Whether the IPI codes should be included, or forced to <see langword="null"/>.</param>
|
||||
@@ -52,6 +53,7 @@ public class ArtistResponseFixture
|
||||
/// <param name="includeContributors">Whether the contributors should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeRatings">Whether the ratings should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeAlbums">Whether the albums should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeCoverPath">Whether the cover path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="ArtistResponse"/>.</returns>
|
||||
public ArtistResponse Create(
|
||||
Guid? id = null,
|
||||
@@ -66,6 +68,7 @@ public class ArtistResponseFixture
|
||||
List<AlbumResponse>? 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+5
-2
@@ -25,19 +25,22 @@ public class TrackLiteResponseFixture
|
||||
/// <param name="trackNumber">Optional. The number of the track on its disc.</param>
|
||||
/// <param name="discNumber">Optional. The number of the disc the track belongs to.</param>
|
||||
/// <param name="includeDiscNumber">Whether the disc number should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="durationInSeconds">Optional. The duration of the track in seconds.</param>
|
||||
/// <returns>The created <see cref="TrackLiteResponse"/>.</returns>
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+108
@@ -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<LuminaDbContext>().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<PaginatedResultDto<AlbumLiteRow>> 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<LuminaDbContext>().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<PaginatedResultDto<AlbumLiteRow>> 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<LuminaDbContext>().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<PaginatedResultDto<AlbumLiteRow>> 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<LuminaDbContext>().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<PaginatedResultDto<AlbumLiteRow>> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an album repository backed by the provided context, wiring the real track repository.
|
||||
/// </summary>
|
||||
|
||||
+253
@@ -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<LuminaDbContext>().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<Deleted> 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<LuminaDbContext>().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<PaginatedResultDto<ArtistLiteRow>> 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<LuminaDbContext>().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<PaginatedResultDto<ArtistLiteRow>> 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<LuminaDbContext>().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<PaginatedResultDto<ArtistLiteRow>> 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<LuminaDbContext>().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<PaginatedResultDto<ArtistLiteRow>> 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<LuminaDbContext>().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<PaginatedResultDto<ArtistLiteRow>> 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<LuminaDbContext>().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<PaginatedResultDto<ArtistLiteRow>> 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<LuminaDbContext>().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<PaginatedResultDto<ArtistLiteRow>> 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<LuminaDbContext>().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<PaginatedResultDto<ArtistLiteRow>> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
|
||||
+235
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Contains integration tests for the <see cref="ArtistAlphaFilterSpecification"/> class, exercising it against a real SQLite database.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ArtistAlphaFilterSpecificationTests : IDisposable
|
||||
{
|
||||
private readonly SqliteConnection _connection;
|
||||
private readonly LuminaDbContext _context;
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ArtistAlphaFilterSpecificationTests"/> class.
|
||||
/// </summary>
|
||||
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<LuminaDbContext>().UseSqlite(_connection).Options);
|
||||
_context.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToExpression_WhenAlphaKeyIsNull_ShouldMatchEveryArtist()
|
||||
{
|
||||
// Arrange
|
||||
List<ArtistEntity> artists = SeedArtists("Alpha", "Beta", "1984");
|
||||
ArtistAlphaFilterSpecification specification = new(null, false);
|
||||
|
||||
// Act
|
||||
List<ArtistEntity> 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<string> 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<string> 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<ArtistEntity> 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<string> 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<string> 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<string> 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<ArtistEntity> 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<string> 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<ArtistEntity> 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<ArtistEntity> 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<string> result = [.. _context.Artists.Where(specification.ToExpression()).Select(artist => artist.Name)];
|
||||
|
||||
// Assert
|
||||
Assert.Equal([matchingName], result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seeds artists with the provided names.
|
||||
/// </summary>
|
||||
/// <param name="names">The names of the artists to seed.</param>
|
||||
/// <returns>The seeded <see cref="ArtistEntity"/> instances.</returns>
|
||||
private List<ArtistEntity> SeedArtists(params string[] names)
|
||||
{
|
||||
List<ArtistEntity> entities = [];
|
||||
foreach (string name in names)
|
||||
entities.Add(_artistEntityFixture.Create(name: name, includeAlbums: false, includeContributors: false));
|
||||
_context.Artists.AddRange(entities);
|
||||
_context.SaveChanges();
|
||||
return entities;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the database context and its underlying connection.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_context.Dispose();
|
||||
_connection.Dispose();
|
||||
}
|
||||
}
|
||||
+83
-1
@@ -567,7 +567,7 @@ public class TrackRepositoryTests
|
||||
|
||||
List<TrackEntity> 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<LuminaDbContext>().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<PaginatedResultDto<TrackLiteRow>> 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<LuminaDbContext>().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<IReadOnlyList<TrackEntity>> 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<LuminaDbContext>().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<PaginatedResultDto<TrackLiteRow>> 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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seeds an artist and the album that owns the tracks of the library identified by <paramref name="libraryId"/>, so that the required foreign keys of a track are satisfied.
|
||||
/// </summary>
|
||||
|
||||
+1
@@ -77,6 +77,7 @@ public class GetAlbumTracksLiteEndpointTests : IClassFixture<AuthenticatedLumina
|
||||
Assert.Equal(1, tracks!.Count);
|
||||
TrackLiteResponse track = Assert.Single(tracks.Data);
|
||||
Assert.Equal("Bohemian Rhapsody", track.Title);
|
||||
Assert.True(track.DurationInSeconds > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+5
-1
@@ -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<AuthenticatedLumin
|
||||
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
@@ -79,6 +81,8 @@ public class GetArtistAlbumsLiteEndpointTests : IClassFixture<AuthenticatedLumin
|
||||
Assert.Equal(2, albums.Data.Count);
|
||||
Assert.Contains(albums.Data, album => 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]
|
||||
|
||||
+149
@@ -97,6 +97,155 @@ public class GetArtistsLiteEndpointTests : IClassFixture<AuthenticatedLuminaApiF
|
||||
Assert.Equal(0, paginatedArtists.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtistsLite_WhenCalledWithFilterAlphaKeyLetter_ShouldReturnOnlyArtistsStartingWithThatLetter()
|
||||
{
|
||||
// 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");
|
||||
|
||||
// Assert
|
||||
response.EnsureSuccessStatusCode();
|
||||
PaginatedResponse<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_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<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_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<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_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<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_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<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_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<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_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<ArtistLiteResponse>? paginatedArtists = await response.Content.ReadFromJsonAsync<PaginatedResponse<ArtistLiteResponse>>(_jsonOptions);
|
||||
Assert.NotNull(paginatedArtists);
|
||||
Assert.Equal(new[] { "Zulu", "Mike", "Alpha" }, paginatedArtists!.Data.Select(artist => artist.Name));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetArtistsLite_WhenLibraryBelongsToAnotherUser_ShouldReturnForbidden()
|
||||
{
|
||||
|
||||
+17
@@ -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);
|
||||
}
|
||||
}
|
||||
+6
@@ -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]
|
||||
|
||||
+17
@@ -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);
|
||||
}
|
||||
}
|
||||
+2
@@ -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]
|
||||
|
||||
+21
@@ -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);
|
||||
}
|
||||
}
|
||||
+1
@@ -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]
|
||||
|
||||
+132
-1
@@ -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<GetAlbumQuery> _mockValidator;
|
||||
private readonly GetAlbumQueryHandler _sut;
|
||||
private readonly Guid _userId;
|
||||
private readonly AlbumEntityFixture _albumEntityFixture = new();
|
||||
private readonly MusicArtworkEntityFixture _musicArtworkEntityFixture = new();
|
||||
private readonly GetAlbumQueryFixture _getAlbumQueryFixture = new();
|
||||
|
||||
/// <summary>
|
||||
@@ -44,18 +49,22 @@ public class GetAlbumQueryHandlerTests
|
||||
public GetAlbumQueryHandlerTests()
|
||||
{
|
||||
_mockAlbumRepository = Substitute.For<IAlbumRepository>();
|
||||
_mockMusicArtworkRepository = Substitute.For<IMusicArtworkRepository>();
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.AlbumRepository.Returns(_mockAlbumRepository);
|
||||
_mockUnitOfWork.MusicArtworkRepository.Returns(_mockMusicArtworkRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockValidator = Substitute.For<IValidator<GetAlbumQuery>>();
|
||||
_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<ILibraryOwnershipPolicy>(_userId, Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockValidator.Validate(Arg.Any<GetAlbumQuery>()).Returns([]);
|
||||
_mockMusicArtworkRepository.GetByOwnerAsync(Arg.Any<MusicArtworkOwnerType>(), Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<MusicArtworkEntity>>([]));
|
||||
|
||||
_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<CancellationToken>())
|
||||
.Returns(Result.From<AlbumEntity?>(album));
|
||||
List<MusicArtworkEntity> 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<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<MusicArtworkEntity>>(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<CancellationToken>());
|
||||
await _mockAuthorizationService.Received(1).EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
_userId, Arg.Is<LibraryOwnershipPolicyContext>(context => context.LibraryId == libraryId), Arg.Any<CancellationToken>());
|
||||
@@ -220,4 +243,112 @@ public class GetAlbumQueryHandlerTests
|
||||
await _mockAlbumRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<bool>(), Arg.Any<bool>(), Arg.Any<CancellationToken>());
|
||||
await _mockAuthorizationService.DidNotReceive().EvaluatePolicyAsync<ILibraryOwnershipPolicy>(Arg.Any<Guid>(), Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[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<CancellationToken>())
|
||||
.Returns(Result.From<AlbumEntity?>(album));
|
||||
_mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Album, albumId, Arg.Any<CancellationToken>())
|
||||
.Returns(ApplicationErrors.Persistence.UniqueConstraintViolation);
|
||||
|
||||
// Act
|
||||
Result<AlbumResponse> 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<CancellationToken>())
|
||||
.Returns(Result.From<AlbumEntity?>(album));
|
||||
_mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Album, albumId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<MusicArtworkEntity>>([]));
|
||||
|
||||
// Act
|
||||
Result<AlbumResponse> 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<CancellationToken>())
|
||||
.Returns(Result.From<AlbumEntity?>(album));
|
||||
List<MusicArtworkEntity> 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<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<MusicArtworkEntity>>(artwork));
|
||||
|
||||
// Act
|
||||
Result<AlbumResponse> 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<CancellationToken>());
|
||||
}
|
||||
|
||||
[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<CancellationToken>())
|
||||
.Returns(Result.From<AlbumEntity?>(album));
|
||||
List<MusicArtworkEntity> 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<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<MusicArtworkEntity>>(artwork));
|
||||
|
||||
// Act
|
||||
Result<AlbumResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("/media/front.jpg", result.Value.CoverPath);
|
||||
}
|
||||
}
|
||||
+103
-1
@@ -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<GetArtistQuery> _mockValidator;
|
||||
private readonly GetArtistQueryHandler _sut;
|
||||
private readonly Guid _userId;
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
private readonly MusicArtworkEntityFixture _musicArtworkEntityFixture = new();
|
||||
private readonly GetArtistQueryFixture _getArtistQueryFixture = new();
|
||||
|
||||
/// <summary>
|
||||
@@ -44,18 +49,22 @@ public class GetArtistQueryHandlerTests
|
||||
public GetArtistQueryHandlerTests()
|
||||
{
|
||||
_mockArtistRepository = Substitute.For<IArtistRepository>();
|
||||
_mockMusicArtworkRepository = Substitute.For<IMusicArtworkRepository>();
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockUnitOfWork.ArtistRepository.Returns(_mockArtistRepository);
|
||||
_mockUnitOfWork.MusicArtworkRepository.Returns(_mockMusicArtworkRepository);
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_mockValidator = Substitute.For<IValidator<GetArtistQuery>>();
|
||||
_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<ILibraryOwnershipPolicy>(_userId, Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
_mockValidator.Validate(Arg.Any<GetArtistQuery>()).Returns([]);
|
||||
_mockMusicArtworkRepository.GetByOwnerAsync(Arg.Any<MusicArtworkOwnerType>(), Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<MusicArtworkEntity>>([]));
|
||||
|
||||
_sut = new GetArtistQueryHandler(_mockUnitOfWork, _mockAuthorizationService, _mockCurrentUserService, _mockValidator);
|
||||
}
|
||||
@@ -199,4 +208,97 @@ public class GetArtistQueryHandlerTests
|
||||
await _mockArtistRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<bool>(), Arg.Any<bool>(), Arg.Any<CancellationToken>());
|
||||
await _mockAuthorizationService.DidNotReceive().EvaluatePolicyAsync<ILibraryOwnershipPolicy>(Arg.Any<Guid>(), Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[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<CancellationToken>())
|
||||
.Returns(Result.From<ArtistEntity?>(artist));
|
||||
_mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Artist, artistId, Arg.Any<CancellationToken>())
|
||||
.Returns(ApplicationErrors.Persistence.UniqueConstraintViolation);
|
||||
|
||||
// Act
|
||||
Result<ArtistResponse> 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<CancellationToken>())
|
||||
.Returns(Result.From<ArtistEntity?>(artist));
|
||||
_mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Artist, artistId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<MusicArtworkEntity>>([]));
|
||||
|
||||
// Act
|
||||
Result<ArtistResponse> 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<CancellationToken>())
|
||||
.Returns(Result.From<ArtistEntity?>(artist));
|
||||
List<MusicArtworkEntity> artwork = [
|
||||
_musicArtworkEntityFixture.Create(ownerType: MusicArtworkOwnerType.Artist, ownerId: artistId, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "/media/artist.jpg")
|
||||
];
|
||||
_mockMusicArtworkRepository.GetByOwnerAsync(MusicArtworkOwnerType.Artist, artistId, Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<MusicArtworkEntity>>(artwork));
|
||||
|
||||
// Act
|
||||
Result<ArtistResponse> 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<CancellationToken>());
|
||||
}
|
||||
|
||||
[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<CancellationToken>())
|
||||
.Returns(Result.From<ArtistEntity?>(artist));
|
||||
// A cover whose file has not been stored yet yields no cover path, even when another piece of artwork is already stored.
|
||||
List<MusicArtworkEntity> 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<CancellationToken>())
|
||||
.Returns(Result.From<IReadOnlyList<MusicArtworkEntity>>(artwork));
|
||||
|
||||
// Act
|
||||
Result<ArtistResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Null(result.Value.CoverPath);
|
||||
}
|
||||
}
|
||||
+37
@@ -247,4 +247,41 @@ public class GetArtistsLiteQueryHandlerTests
|
||||
await _mockAuthorizationService.DidNotReceive().EvaluatePolicyAsync<ILibraryOwnershipPolicy>(Arg.Any<Guid>(), Arg.Any<LibraryOwnershipPolicyContext>(), Arg.Any<CancellationToken>());
|
||||
await _mockArtistRepository.DidNotReceive().GetAllLiteAsync(Arg.Any<PaginationDataDto?>(), Arg.Any<string?>(), Arg.Any<SortOrder?>(), Arg.Any<LibraryFilterDto>(), cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[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<ArtistLiteRow> paginatedArtists = _paginatedResultDtoFixture.Create(data: [], currentPage: 1, perPage: 10, count: 0, numberOfPages: 0);
|
||||
_mockArtistRepository.GetAllLiteAsync(
|
||||
Arg.Any<PaginationDataDto?>(),
|
||||
Arg.Any<string?>(),
|
||||
Arg.Any<SortOrder?>(),
|
||||
Arg.Any<LibraryFilterDto>(),
|
||||
cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(paginatedArtists));
|
||||
|
||||
// Act
|
||||
await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
await _mockArtistRepository.Received(1).GetAllLiteAsync(
|
||||
Arg.Any<PaginationDataDto?>(),
|
||||
Arg.Is<string?>(sortBy => sortBy == "name"),
|
||||
Arg.Is<SortOrder?>(sortOrder => sortOrder == SortOrder.Descending),
|
||||
Arg.Is<LibraryFilterDto>(filter =>
|
||||
filter.LibraryId == libraryId &&
|
||||
filter.SearchTerm == "Queen" &&
|
||||
filter.FilterAlphaKey == "Q" &&
|
||||
filter.ShouldIgnoreThePrefixForAlphaPicker),
|
||||
cancellationToken: Arg.Any<CancellationToken>());
|
||||
}
|
||||
}
|
||||
+152
@@ -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<Error> 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<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenFilterAlphaKeyIsNull_ShouldNotHaveValidationError()
|
||||
{
|
||||
// Arrange
|
||||
GetArtistsLiteQuery query = _getArtistsLiteQueryFixture.Create(filterAlphaKey: null);
|
||||
|
||||
// Act
|
||||
List<Error> 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<Error> 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<Error> 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<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationError(Errors.Library.InvalidFilterAlphaKey);
|
||||
}
|
||||
}
|
||||
+107
@@ -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();
|
||||
|
||||
/// <summary>
|
||||
@@ -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<PaginatedResultDto<AlbumLiteRow>> 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<PaginatedResultDto<AlbumLiteRow>> 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<PaginatedResultDto<AlbumLiteRow>> 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<PaginatedResultDto<AlbumLiteRow>> 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<PaginatedResultDto<AlbumLiteRow>> 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()
|
||||
{
|
||||
|
||||
+109
@@ -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();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ArtistRepositoryTests"/> 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<PaginatedResultDto<ArtistLiteRow>> 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<PaginatedResultDto<ArtistLiteRow>> 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<PaginatedResultDto<ArtistLiteRow>> 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<PaginatedResultDto<ArtistLiteRow>> 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<PaginatedResultDto<ArtistLiteRow>> 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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks the provided artist, its albums and its tracks as enriched.
|
||||
/// </summary>
|
||||
|
||||
+64
-1
@@ -637,7 +637,7 @@ public class TrackRepositoryTests
|
||||
|
||||
List<TrackEntity> 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<IReadOnlyList<TrackEntity>> 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<PaginatedResultDto<TrackLiteRow>> 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<PaginatedResultDto<TrackLiteRow>> 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]
|
||||
|
||||
Reference in new issue
Block a user