mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 06:01:10 +00:00
Refactors the track slice across the stack
This commit is contained in:
1 parent
e842c7baaf
commit
6bd0cf6d42
37 files changed
+853
-403
No files matched your search
@@ -2,6 +2,9 @@
|
||||
|
||||
- [Lumina API](#lumina-api)
|
||||
- [Track](#track)
|
||||
- [Add Track](#add-track)
|
||||
- [Add Track Request](#add-track-request)
|
||||
- [Add Track Response](#add-track-response)
|
||||
- [Get Track](#get-track)
|
||||
- [Get Track Request](#get-track-request)
|
||||
- [Get Track Response](#get-track-response)
|
||||
@@ -12,6 +15,171 @@
|
||||
|
||||
## Track
|
||||
|
||||
### Add Track
|
||||
|
||||
#### Add Track Request
|
||||
|
||||
```js
|
||||
POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
|
||||
"metadata": {
|
||||
"title": "Bohemian Rhapsody",
|
||||
"originalTitle": "Bohemian Rhapsody",
|
||||
"description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
|
||||
"durationInSeconds": 354,
|
||||
"sampleRate": 44100,
|
||||
"channels": 2,
|
||||
"bitDepth": 16,
|
||||
"audioCodec": "FLAC",
|
||||
"bitrate": 980,
|
||||
"releaseInfo": {
|
||||
"originalReleaseDate": "1975-10-31",
|
||||
"originalReleaseYear": 1975,
|
||||
"reReleaseDate": null,
|
||||
"reReleaseYear": null,
|
||||
"releaseCountry": "GB",
|
||||
"releaseVersion": "Original"
|
||||
},
|
||||
"language": {
|
||||
"languageCode": "en",
|
||||
"languageName": "English",
|
||||
"nativeName": "English"
|
||||
},
|
||||
"originalLanguage": {
|
||||
"languageCode": "en",
|
||||
"languageName": "English",
|
||||
"nativeName": "English"
|
||||
},
|
||||
"genres": [
|
||||
{ "name": "Rock" },
|
||||
{ "name": "Progressive Rock" }
|
||||
],
|
||||
"tags": [
|
||||
{ "name": "classic" },
|
||||
{ "name": "epic" }
|
||||
]
|
||||
},
|
||||
"trackNumber": 1,
|
||||
"discNumber": 1,
|
||||
"script": "Latn",
|
||||
"key": "CMajor",
|
||||
"bpm": 72,
|
||||
"work": "Bohemian Rhapsody",
|
||||
"musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a",
|
||||
"musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b",
|
||||
"musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c",
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### Add Track Response
|
||||
|
||||
```js
|
||||
201 Created
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f",
|
||||
"albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f",
|
||||
"libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
||||
"path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
|
||||
"metadata": {
|
||||
"title": "Bohemian Rhapsody",
|
||||
"originalTitle": "Bohemian Rhapsody",
|
||||
"description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
|
||||
"releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": null, "reReleaseYear": null, "releaseCountry": "GB", "releaseVersion": "Original" },
|
||||
"language": { "languageCode": "en", "languageName": "English", "nativeName": "English" },
|
||||
"originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" },
|
||||
"tags": [ { "name": "classic" }, { "name": "epic" } ],
|
||||
"genres": [ { "name": "Rock" }, { "name": "Progressive Rock" } ],
|
||||
"durationInSeconds": 354,
|
||||
"sampleRate": 44100,
|
||||
"channels": 2,
|
||||
"bitDepth": 16,
|
||||
"audioCodec": "FLAC",
|
||||
"bitrate": 980
|
||||
},
|
||||
"trackNumber": 1,
|
||||
"discNumber": 1,
|
||||
"script": "Latn",
|
||||
"key": "CMajor",
|
||||
"bpm": 72,
|
||||
"work": "Bohemian Rhapsody",
|
||||
"musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a",
|
||||
"musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b",
|
||||
"musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c",
|
||||
"createdOnUtc": "2025-01-01T12:00:00.0000000Z",
|
||||
"updatedOnUtc": null,
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Get Track
|
||||
|
||||
#### Get Track Request
|
||||
@@ -59,6 +227,19 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
|
||||
"musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c",
|
||||
"createdOnUtc": "2025-01-01T12:00:00.0000000Z",
|
||||
"updatedOnUtc": null,
|
||||
"moods": [
|
||||
{
|
||||
"name": "dramatic"
|
||||
},
|
||||
{
|
||||
"name": "anxious"
|
||||
}
|
||||
],
|
||||
"isrcs": [
|
||||
{
|
||||
"value": "GBUM71029604"
|
||||
}
|
||||
],
|
||||
"contributors": [
|
||||
{
|
||||
"contributorId": "6a3f0c2d-1b4e-4f5a-8c6d-9e0f1a2b3c4d",
|
||||
@@ -82,19 +263,6 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
|
||||
"source": "LastFm",
|
||||
"voteCount": 1234
|
||||
}
|
||||
],
|
||||
"moods": [
|
||||
{
|
||||
"name": "dramatic"
|
||||
},
|
||||
{
|
||||
"name": "anxious"
|
||||
}
|
||||
],
|
||||
"isrcs": [
|
||||
{
|
||||
"value": "GBUM71029604"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
@@ -157,6 +325,13 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
|
||||
"musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a",
|
||||
"musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b",
|
||||
"musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c",
|
||||
"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" }
|
||||
@@ -174,13 +349,6 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
|
||||
"source": "LastFm",
|
||||
"voteCount": 1234
|
||||
}
|
||||
],
|
||||
"moods": [
|
||||
{ "name": "dramatic" },
|
||||
{ "name": "anxious" }
|
||||
],
|
||||
"isrcs": [
|
||||
{ "value": "GBUM71029604" }
|
||||
]
|
||||
}
|
||||
```
|
||||
@@ -191,7 +359,78 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
|
||||
200 Ok
|
||||
```
|
||||
|
||||
The response carries the full details of the updated track, using the same shape as the [Get Track Response](#get-track-response).
|
||||
```json
|
||||
{
|
||||
"id": "9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f",
|
||||
"albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f",
|
||||
"libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
||||
"path": "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
|
||||
"metadata": {
|
||||
"title": "Bohemian Rhapsody",
|
||||
"originalTitle": "Bohemian Rhapsody",
|
||||
"description": "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
|
||||
"releaseInfo": { "originalReleaseDate": "1975-10-31", "originalReleaseYear": 1975, "reReleaseDate": null, "reReleaseYear": null, "releaseCountry": "GB", "releaseVersion": "Original" },
|
||||
"language": { "languageCode": "en", "languageName": "English", "nativeName": "English" },
|
||||
"originalLanguage": { "languageCode": "en", "languageName": "English", "nativeName": "English" },
|
||||
"tags": [ { "name": "classic" }, { "name": "epic" } ],
|
||||
"genres": [ { "name": "Rock" }, { "name": "Progressive Rock" } ],
|
||||
"durationInSeconds": 354,
|
||||
"sampleRate": 44100,
|
||||
"channels": 2,
|
||||
"bitDepth": 16,
|
||||
"audioCodec": "FLAC",
|
||||
"bitrate": 980
|
||||
},
|
||||
"trackNumber": 1,
|
||||
"discNumber": 1,
|
||||
"script": "Latn",
|
||||
"key": "CMajor",
|
||||
"bpm": 72,
|
||||
"work": "Bohemian Rhapsody",
|
||||
"musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a",
|
||||
"musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b",
|
||||
"musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c",
|
||||
"createdOnUtc": "2025-01-01T12:00:00.0000000Z",
|
||||
"updatedOnUtc": null,
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Delete Track
|
||||
@@ -204,4 +443,4 @@ DELETE api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f
|
||||
200 Ok
|
||||
```
|
||||
|
||||
Deletes the track identified by the path.
|
||||
Deletes the track identified by the route.
|
||||
@@ -50,6 +50,13 @@ Content-Type: application/json
|
||||
"musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a",
|
||||
"musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b",
|
||||
"musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c",
|
||||
"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" }
|
||||
@@ -67,12 +74,5 @@ Content-Type: application/json
|
||||
"source": "LastFm",
|
||||
"voteCount": 1234
|
||||
}
|
||||
],
|
||||
"moods": [
|
||||
{ "name": "dramatic" },
|
||||
{ "name": "anxious" }
|
||||
],
|
||||
"isrcs": [
|
||||
{ "value": "GBUM71029604" }
|
||||
]
|
||||
}
|
||||
@@ -50,6 +50,13 @@ Content-Type: application/json
|
||||
"musicBrainzRecordingId": "d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a",
|
||||
"musicBrainzTrackId": "e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b",
|
||||
"musicBrainzWorkId": "f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c",
|
||||
"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" }
|
||||
@@ -67,12 +74,5 @@ Content-Type: application/json
|
||||
"source": "LastFm",
|
||||
"voteCount": 1234
|
||||
}
|
||||
],
|
||||
"moods": [
|
||||
{ "name": "dramatic" },
|
||||
{ "name": "anxious" }
|
||||
],
|
||||
"isrcs": [
|
||||
{ "value": "GBUM71029604" }
|
||||
]
|
||||
}
|
||||
+10
-10
@@ -190,16 +190,6 @@ public class TrackEntity : IStorageEntity, IAuditableEntity
|
||||
/// </summary>
|
||||
public AlbumEntity? Album { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ratings for this track.
|
||||
/// </summary>
|
||||
public List<AudioRatingEntity> Ratings { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of the media contributors of the track.
|
||||
/// </summary>
|
||||
public List<TrackContributorEntity> Contributors { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of moods of the track.
|
||||
/// </summary>
|
||||
@@ -210,6 +200,16 @@ public class TrackEntity : IStorageEntity, IAuditableEntity
|
||||
/// </summary>
|
||||
public List<TrackIsrcEntity> Isrcs { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of the media contributors of the track.
|
||||
/// </summary>
|
||||
public List<TrackContributorEntity> Contributors { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of ratings for this track.
|
||||
/// </summary>
|
||||
public List<AudioRatingEntity> Ratings { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the genres of the track.
|
||||
/// </summary>
|
||||
|
||||
@@ -21,6 +21,15 @@ public interface ITrackRepository : IRepository<TrackEntity>,
|
||||
IUpdateRepositoryAction<TrackEntity>,
|
||||
IGetByIdRepositoryAction<TrackEntity, Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the subset of <paramref name="paths"/> that is already used by a track of the library identified by <paramref name="libraryId"/>.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the library whose tracks are searched.</param>
|
||||
/// <param name="paths">The track paths to check.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the paths that are already used, or an error.</returns>
|
||||
Task<Result<IReadOnlyCollection<string>>> GetExistingPathsAsync(Guid libraryId, IReadOnlyCollection<string> paths, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the tracks of the album identified by <paramref name="albumId"/>.
|
||||
/// </summary>
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ public static class IsrcDtoMapping
|
||||
/// </returns>
|
||||
public static Result<Isrc> ToDomainEntity(this IsrcDto dto)
|
||||
{
|
||||
return Isrc.Create(dto.Value);
|
||||
return Isrc.Create(dto.Value!);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public static class IsrcEntityMapping
|
||||
/// </returns>
|
||||
public static Result<Isrc> ToDomainEntity(this TrackIsrcEntity repositoryEntity)
|
||||
{
|
||||
return Isrc.Create(repositoryEntity.Value);
|
||||
return Isrc.Create(repositoryEntity.Value!);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ public static class MoodDtoMapping
|
||||
/// </returns>
|
||||
public static Result<Mood> ToDomainEntity(this MoodDto dto)
|
||||
{
|
||||
return Mood.Create(dto.Name);
|
||||
return Mood.Create(dto.Name!);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ public static class MoodEntityMapping
|
||||
/// </returns>
|
||||
public static Result<Mood> ToDomainEntity(this TrackMoodEntity repositoryEntity)
|
||||
{
|
||||
return Mood.Create(repositoryEntity.Name);
|
||||
return Mood.Create(repositoryEntity.Name!);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+22
-34
@@ -8,6 +8,7 @@ using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.Value
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
@@ -32,53 +33,38 @@ public static class AddTrackCommandMapping
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
IEnumerable<Result<Isrc>> domainIsrcsResult = (command.Isrcs ?? []).ToDomainEntities();
|
||||
List<Error> errors = [.. domainIsrcsResult.Where(isrcResult => isrcResult.IsFailure).SelectMany(isrcResult => isrcResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Mood>> domainMoodsResult = (command.Moods ?? []).ToDomainEntities();
|
||||
errors = [.. domainMoodsResult.Where(moodResult => moodResult.IsFailure).SelectMany(moodResult => moodResult.Errors)];
|
||||
List<Error> errors = [.. domainMoodsResult.Where(moodResult => moodResult.IsFailure).SelectMany(moodResult => moodResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
|
||||
IEnumerable<Result<Isrc>> domainIsrcsResult = (command.Isrcs ?? []).ToDomainEntities();
|
||||
errors = [.. domainIsrcsResult.Where(isrcResult => isrcResult.IsFailure).SelectMany(isrcResult => isrcResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = (command.Ratings ?? []).ToDomainEntities();
|
||||
IEnumerable<Result<AudioRating>> domainRatingsResult = command.Ratings!.ToDomainEntities();
|
||||
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzRecordingId is not null)
|
||||
{
|
||||
Result<MusicBrainzId> musicBrainzRecordingIdResult = MusicBrainzId.Create(command.MusicBrainzRecordingId.Value);
|
||||
if (musicBrainzRecordingIdResult.IsFailure)
|
||||
return musicBrainzRecordingIdResult.Errors;
|
||||
musicBrainzRecordingId = musicBrainzRecordingIdResult.Value;
|
||||
}
|
||||
musicBrainzRecordingId = MusicBrainzId.Create(command.MusicBrainzRecordingId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzTrackId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzTrackId is not null)
|
||||
{
|
||||
Result<MusicBrainzId> musicBrainzTrackIdResult = MusicBrainzId.Create(command.MusicBrainzTrackId.Value);
|
||||
if (musicBrainzTrackIdResult.IsFailure)
|
||||
return musicBrainzTrackIdResult.Errors;
|
||||
musicBrainzTrackId = musicBrainzTrackIdResult.Value;
|
||||
}
|
||||
musicBrainzTrackId = MusicBrainzId.Create(command.MusicBrainzTrackId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzWorkId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzWorkId is not null)
|
||||
{
|
||||
Result<MusicBrainzId> musicBrainzWorkIdResult = MusicBrainzId.Create(command.MusicBrainzWorkId.Value);
|
||||
if (musicBrainzWorkIdResult.IsFailure)
|
||||
return musicBrainzWorkIdResult.Errors;
|
||||
musicBrainzWorkId = musicBrainzWorkIdResult.Value;
|
||||
}
|
||||
musicBrainzWorkId = MusicBrainzId.Create(command.MusicBrainzWorkId.Value);
|
||||
|
||||
List<Isrc> isrcs = [.. domainIsrcsResult.Select(isrcResult => isrcResult.Value)];
|
||||
List<Mood> moods = [.. domainMoodsResult.Select(moodResult => moodResult.Value)];
|
||||
List<Isrc> isrcs = [.. domainIsrcsResult.Select(isrcResult => isrcResult.Value)];
|
||||
List<MusicMediaContributor> contributors = [.. domainContributorsResult.Select(contributorResult => contributorResult.Value)];
|
||||
List<AudioRating> ratings = [.. domainRatingsResult.Select(ratingResult => ratingResult.Value)];
|
||||
|
||||
@@ -88,30 +74,32 @@ public static class AddTrackCommandMapping
|
||||
TrackId.Create(command.TrackId.Value),
|
||||
command.Path!,
|
||||
metadataResult.Value,
|
||||
command.TrackNumber ?? 1,
|
||||
command.TrackNumber!.Value,
|
||||
Optional<int>.FromNullable(command.DiscNumber),
|
||||
isrcs,
|
||||
moods,
|
||||
Optional<string>.FromNullable(command.Script),
|
||||
Optional<MusicKey>.FromNullable(command.Key),
|
||||
Optional<int>.FromNullable(command.Bpm),
|
||||
moods,
|
||||
isrcs,
|
||||
Optional<string>.FromNullable(command.Work),
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
contributors,
|
||||
ratings);
|
||||
ratings,
|
||||
DateTime.UtcNow,
|
||||
Optional<DateTime>.None());
|
||||
|
||||
return Track.Create(
|
||||
command.Path!,
|
||||
metadataResult.Value,
|
||||
command.TrackNumber ?? 1,
|
||||
command.TrackNumber!.Value,
|
||||
Optional<int>.FromNullable(command.DiscNumber),
|
||||
isrcs,
|
||||
moods,
|
||||
Optional<string>.FromNullable(command.Script),
|
||||
Optional<MusicKey>.FromNullable(command.Key),
|
||||
Optional<int>.FromNullable(command.Bpm),
|
||||
moods,
|
||||
isrcs,
|
||||
Optional<string>.FromNullable(command.Work),
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
|
||||
+17
-30
@@ -91,27 +91,20 @@ public static class TrackEntityMapping
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId = Optional<MusicBrainzId>.None();
|
||||
if (repositoryEntity.MusicBrainzRecordingId is not null)
|
||||
{
|
||||
Result<MusicBrainzId> musicBrainzRecordingIdResult = MusicBrainzId.Create(repositoryEntity.MusicBrainzRecordingId.Value);
|
||||
if (musicBrainzRecordingIdResult.IsFailure)
|
||||
return musicBrainzRecordingIdResult.Errors;
|
||||
musicBrainzRecordingId = musicBrainzRecordingIdResult.Value;
|
||||
}
|
||||
musicBrainzRecordingId = MusicBrainzId.Create(repositoryEntity.MusicBrainzRecordingId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzTrackId = Optional<MusicBrainzId>.None();
|
||||
if (repositoryEntity.MusicBrainzTrackId is not null)
|
||||
{
|
||||
Result<MusicBrainzId> musicBrainzTrackIdResult = MusicBrainzId.Create(repositoryEntity.MusicBrainzTrackId.Value);
|
||||
if (musicBrainzTrackIdResult.IsFailure)
|
||||
return musicBrainzTrackIdResult.Errors;
|
||||
musicBrainzTrackId = musicBrainzTrackIdResult.Value;
|
||||
}
|
||||
musicBrainzTrackId = MusicBrainzId.Create(repositoryEntity.MusicBrainzTrackId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzWorkId = Optional<MusicBrainzId>.None();
|
||||
if (repositoryEntity.MusicBrainzWorkId is not null)
|
||||
musicBrainzWorkId = MusicBrainzId.Create(repositoryEntity.MusicBrainzWorkId.Value);
|
||||
|
||||
List<Mood> domainMoods = [];
|
||||
foreach (Result<Mood> moodResult in repositoryEntity.Moods.ToDomainEntities())
|
||||
{
|
||||
Result<MusicBrainzId> musicBrainzWorkIdResult = MusicBrainzId.Create(repositoryEntity.MusicBrainzWorkId.Value);
|
||||
if (musicBrainzWorkIdResult.IsFailure)
|
||||
return musicBrainzWorkIdResult.Errors;
|
||||
musicBrainzWorkId = musicBrainzWorkIdResult.Value;
|
||||
if (moodResult.IsFailure)
|
||||
return moodResult.Errors;
|
||||
domainMoods.Add(moodResult.Value);
|
||||
}
|
||||
|
||||
List<Isrc> domainIsrcs = [];
|
||||
@@ -122,14 +115,6 @@ public static class TrackEntityMapping
|
||||
domainIsrcs.Add(isrcResult.Value);
|
||||
}
|
||||
|
||||
List<Mood> domainMoods = [];
|
||||
foreach (Result<Mood> moodResult in repositoryEntity.Moods.ToDomainEntities())
|
||||
{
|
||||
if (moodResult.IsFailure)
|
||||
return moodResult.Errors;
|
||||
domainMoods.Add(moodResult.Value);
|
||||
}
|
||||
|
||||
List<AudioRating> domainRatings = [];
|
||||
foreach (Result<AudioRating> ratingResult in repositoryEntity.Ratings.ToDomainEntities())
|
||||
{
|
||||
@@ -153,17 +138,19 @@ public static class TrackEntityMapping
|
||||
metadataResult.Value,
|
||||
repositoryEntity.TrackNumber,
|
||||
Optional<int>.FromNullable(repositoryEntity.DiscNumber),
|
||||
domainIsrcs,
|
||||
domainMoods,
|
||||
Optional<string>.FromNullable(repositoryEntity.Script),
|
||||
Optional<MusicKey>.FromNullable(repositoryEntity.Key),
|
||||
Optional<int>.FromNullable(repositoryEntity.Bpm),
|
||||
domainMoods,
|
||||
domainIsrcs,
|
||||
Optional<string>.FromNullable(repositoryEntity.Work),
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
domainContributors,
|
||||
domainRatings);
|
||||
domainRatings,
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
Optional<DateTime>.FromNullable(repositoryEntity.UpdatedOnUtc));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -231,10 +218,10 @@ public static class TrackEntityMapping
|
||||
repositoryEntity.MusicBrainzWorkId,
|
||||
repositoryEntity.CreatedOnUtc,
|
||||
repositoryEntity.UpdatedOnUtc,
|
||||
[.. repositoryEntity.Contributors.Select(contributor => new MediaContributorReferenceDto(contributor.MediaContributorId, contributor.Role))],
|
||||
[.. repositoryEntity.Ratings.ToResponses()],
|
||||
[.. repositoryEntity.Moods.ToResponses()],
|
||||
[.. repositoryEntity.Isrcs.ToResponses()]);
|
||||
[.. repositoryEntity.Isrcs.ToResponses()],
|
||||
[.. repositoryEntity.Contributors.Select(contributor => new MediaContributorReferenceDto(contributor.MediaContributorId, contributor.Role))],
|
||||
[.. repositoryEntity.Ratings.ToResponses()]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+8
-5
@@ -68,15 +68,18 @@ public static class TrackMapping
|
||||
TrackId = domainEntity.Id.Value,
|
||||
MediaContributorId = contributor.ContributorId.Value,
|
||||
Role = contributor.Role,
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
UpdatedBy = null
|
||||
})],
|
||||
Moods = [.. domainEntity.Moods.ToRepositoryEntities()],
|
||||
Isrcs = [.. domainEntity.Isrcs.ToRepositoryEntities()],
|
||||
Ratings = [.. domainEntity.Ratings.ToRepositoryEntities()],
|
||||
CreatedOnUtc = default,
|
||||
CreatedBy = default,
|
||||
UpdatedBy = default
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
// The audit columns are owned by the auditing interceptor, which stamps only the rows that actually changed, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
};
|
||||
}
|
||||
}
|
||||
+28
-44
@@ -2,8 +2,6 @@
|
||||
using Lumina.Application.Common.Mapping.MediaContributors;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.UpdateTrack;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.Common.ValueObjects;
|
||||
@@ -14,6 +12,7 @@ using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
@@ -37,8 +36,18 @@ public static class UpdateTrackCommandMapping
|
||||
if (metadataResult.IsFailure)
|
||||
return metadataResult.Errors;
|
||||
|
||||
IEnumerable<Result<Mood>> domainMoodsResult = (command.Moods ?? []).ToDomainEntities();
|
||||
List<Error> errors = [.. domainMoodsResult.Where(moodResult => moodResult.IsFailure).SelectMany(moodResult => moodResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<Isrc>> domainIsrcsResult = (command.Isrcs ?? []).ToDomainEntities();
|
||||
errors = [.. domainIsrcsResult.Where(isrcResult => isrcResult.IsFailure).SelectMany(isrcResult => isrcResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
IEnumerable<Result<MusicMediaContributor>> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
|
||||
List<Error> errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
|
||||
if (errors.Count > 0)
|
||||
return errors;
|
||||
|
||||
@@ -49,53 +58,28 @@ public static class UpdateTrackCommandMapping
|
||||
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzRecordingId is not null)
|
||||
{
|
||||
Result<MusicBrainzId> musicBrainzRecordingIdResult = MusicBrainzId.Create(command.MusicBrainzRecordingId.Value);
|
||||
if (musicBrainzRecordingIdResult.IsFailure)
|
||||
return musicBrainzRecordingIdResult.Errors;
|
||||
musicBrainzRecordingId = musicBrainzRecordingIdResult.Value;
|
||||
}
|
||||
musicBrainzRecordingId = MusicBrainzId.Create(command.MusicBrainzRecordingId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzTrackId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzTrackId is not null)
|
||||
{
|
||||
Result<MusicBrainzId> musicBrainzTrackIdResult = MusicBrainzId.Create(command.MusicBrainzTrackId.Value);
|
||||
if (musicBrainzTrackIdResult.IsFailure)
|
||||
return musicBrainzTrackIdResult.Errors;
|
||||
musicBrainzTrackId = musicBrainzTrackIdResult.Value;
|
||||
}
|
||||
musicBrainzTrackId = MusicBrainzId.Create(command.MusicBrainzTrackId.Value);
|
||||
Optional<MusicBrainzId> musicBrainzWorkId = Optional<MusicBrainzId>.None();
|
||||
if (command.MusicBrainzWorkId is not null)
|
||||
{
|
||||
Result<MusicBrainzId> musicBrainzWorkIdResult = MusicBrainzId.Create(command.MusicBrainzWorkId.Value);
|
||||
if (musicBrainzWorkIdResult.IsFailure)
|
||||
return musicBrainzWorkIdResult.Errors;
|
||||
musicBrainzWorkId = musicBrainzWorkIdResult.Value;
|
||||
}
|
||||
musicBrainzWorkId = MusicBrainzId.Create(command.MusicBrainzWorkId.Value);
|
||||
|
||||
List<Isrc> domainIsrcs = [];
|
||||
foreach (IsrcDto isrc in command.Isrcs ?? [])
|
||||
{
|
||||
Result<Isrc> isrcResult = isrc.ToDomainEntity();
|
||||
if (isrcResult.IsFailure)
|
||||
return isrcResult.Errors;
|
||||
domainIsrcs.Add(isrcResult.Value);
|
||||
}
|
||||
|
||||
List<Mood> domainMoods = [];
|
||||
foreach (MoodDto mood in command.Moods ?? [])
|
||||
{
|
||||
Result<Mood> moodResult = mood.ToDomainEntity();
|
||||
if (moodResult.IsFailure)
|
||||
return moodResult.Errors;
|
||||
domainMoods.Add(moodResult.Value);
|
||||
}
|
||||
// The album and the track are entities inside the artist aggregate, so they are referenced by object, not by id; the aggregate members are located here and passed through.
|
||||
Album? album = artist.Albums.FirstOrDefault(album => album.Id.Value == Guid.Parse(command.AlbumId!));
|
||||
if (album is null)
|
||||
return DomainErrors.Music.AlbumNotFound;
|
||||
Track? track = album.Tracks.FirstOrDefault(track => track.Id.Value == Guid.Parse(command.TrackId!));
|
||||
if (track is null)
|
||||
return DomainErrors.Music.TrackNotFound;
|
||||
|
||||
Result<Updated> updateResult = artist.UpdateTrackInAlbum(
|
||||
AlbumId.Create(Guid.Parse(command.AlbumId!)),
|
||||
TrackId.Create(Guid.Parse(command.TrackId!)),
|
||||
album,
|
||||
track,
|
||||
command.Path!,
|
||||
metadataResult.Value,
|
||||
command.TrackNumber ?? 1,
|
||||
command.TrackNumber!.Value,
|
||||
Optional<int>.FromNullable(command.DiscNumber),
|
||||
Optional<string>.FromNullable(command.Script),
|
||||
Optional<MusicKey>.FromNullable(command.Key),
|
||||
@@ -104,10 +88,10 @@ public static class UpdateTrackCommandMapping
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
[.. domainMoodsResult.Select(moodResult => moodResult.Value)],
|
||||
[.. domainIsrcsResult.Select(isrcResult => isrcResult.Value)],
|
||||
[.. domainContributorsResult.Select(contributorResult => contributorResult.Value)],
|
||||
[.. domainRatingsResult.Select(ratingResult => ratingResult.Value)],
|
||||
domainMoods,
|
||||
domainIsrcs);
|
||||
[.. domainRatingsResult.Select(ratingResult => ratingResult.Value)]);
|
||||
if (updateResult.IsFailure)
|
||||
return updateResult.Errors;
|
||||
|
||||
|
||||
+3
-3
@@ -37,9 +37,9 @@ public static class UpdateTrackRequestMapping
|
||||
request.MusicBrainzRecordingId,
|
||||
request.MusicBrainzTrackId,
|
||||
request.MusicBrainzWorkId,
|
||||
request.Contributors,
|
||||
request.Ratings,
|
||||
request.Moods,
|
||||
request.Isrcs);
|
||||
request.Isrcs,
|
||||
request.Contributors,
|
||||
request.Ratings);
|
||||
}
|
||||
}
|
||||
+16
-6
@@ -96,12 +96,14 @@ public class AddTrackCommandHandler : ICommandHandler<AddTrackCommand, Result<Tr
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetByIdAsync(artistId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getArtistResult.IsFailure)
|
||||
return getArtistResult.Errors;
|
||||
if (getArtistResult.Value is null || getArtistResult.Value.LibraryId != libraryId)
|
||||
return Errors.Music.AlbumNotFound;
|
||||
if (getArtistResult.Value is null)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
ArtistEntity existingArtist = getArtistResult.Value;
|
||||
AlbumEntity? existingAlbum = existingArtist.Albums.FirstOrDefault(album => album.Id == albumId);
|
||||
if (existingAlbum is null)
|
||||
return Errors.Music.AlbumNotFound;
|
||||
|
||||
// Resource scoping: the track must belong to an artist of the library named by the route, so that a track can never be added through
|
||||
// another library's route; the mismatch is reported as not found, without disclosing that the artist exists in another library.
|
||||
if (existingArtist.LibraryId != libraryId)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
|
||||
// Admins can add tracks to the albums of all libraries; for everyone else, only to the albums of the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
@@ -109,6 +111,10 @@ public class AddTrackCommandHandler : ICommandHandler<AddTrackCommand, Result<Tr
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
AlbumEntity? existingAlbum = existingArtist.Albums.FirstOrDefault(album => album.Id == albumId);
|
||||
if (existingAlbum is null)
|
||||
return Errors.Music.AlbumNotFound;
|
||||
|
||||
// A track can only belong to a library that exists, so a client can never register an entry that points to a library of the host that is not there.
|
||||
Result<LibraryEntity?> getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(libraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryResult.IsFailure)
|
||||
@@ -135,7 +141,11 @@ public class AddTrackCommandHandler : ICommandHandler<AddTrackCommand, Result<Tr
|
||||
Result<Track> createTrackResult = command.ToDomainEntity();
|
||||
if (createTrackResult.IsFailure)
|
||||
return createTrackResult.Errors;
|
||||
Result<Created> addTrackResult = artistResult.Value.AddTrackToAlbum(AlbumId.Create(albumId), createTrackResult.Value);
|
||||
// The album is an entity inside the artist aggregate, so it is referenced by object, not by id; the aggregate member is located here and passed through.
|
||||
Album? domainAlbum = artistResult.Value.Albums.FirstOrDefault(album => album.Id.Value == albumId);
|
||||
if (domainAlbum is null)
|
||||
return Errors.Music.AlbumNotFound;
|
||||
Result<Created> addTrackResult = artistResult.Value.AddTrackToAlbum(domainAlbum, createTrackResult.Value);
|
||||
if (addTrackResult.IsFailure)
|
||||
return addTrackResult.Errors;
|
||||
|
||||
|
||||
+18
@@ -192,6 +192,7 @@ public class AddTrackCommandValidator : AbstractValidator<AddTrackCommand>
|
||||
.When(m => m!.OriginalLanguage is not null);
|
||||
});
|
||||
|
||||
// Validates the MusicBrainz identifiers of the track.
|
||||
RuleFor(command => command.MusicBrainzRecordingId)
|
||||
.Must(musicBrainzRecordingId => musicBrainzRecordingId != Guid.Empty)
|
||||
.When(command => command.MusicBrainzRecordingId.HasValue)
|
||||
@@ -208,6 +209,10 @@ public class AddTrackCommandValidator : AbstractValidator<AddTrackCommand>
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the ordering and performance characteristics of the track.
|
||||
RuleFor(command => command.TrackNumber)
|
||||
.NotNull()
|
||||
.WithError(Errors.Music.TrackNumberMustBeGreaterThanZero);
|
||||
|
||||
RuleFor(command => command.TrackNumber)
|
||||
.GreaterThan(0)
|
||||
.When(command => command.TrackNumber.HasValue)
|
||||
@@ -238,6 +243,19 @@ public class AddTrackCommandValidator : AbstractValidator<AddTrackCommand>
|
||||
.When(command => command.Work is not null)
|
||||
.WithError(Errors.Music.WorkMustBeMaximum255CharactersLong);
|
||||
|
||||
// Validates the moods and the ISRC codes of the track.
|
||||
RuleForEach(command => command.Moods)
|
||||
.ChildRules(mood =>
|
||||
mood.RuleFor(m => m.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Metadata.MoodNameCannotBeEmpty));
|
||||
|
||||
RuleForEach(command => command.Isrcs)
|
||||
.ChildRules(isrc =>
|
||||
isrc.RuleFor(i => i.Value)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.IsrcValueCannotBeEmpty));
|
||||
|
||||
// Validates the media contributors that performed on the track.
|
||||
RuleFor(command => command.Contributors)
|
||||
.NotNull()
|
||||
|
||||
+20
-11
@@ -11,7 +11,6 @@ using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.A
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -81,14 +80,10 @@ public class DeleteTrackCommandHandler : ICommandHandler<DeleteTrackCommand, Res
|
||||
return DomainErrors.Music.ArtistNotFound;
|
||||
ArtistEntity existingArtist = getArtistResult.Value;
|
||||
|
||||
// Resource scoping: the track must belong to an album of the artist of the library named by the route, so that a track can never be
|
||||
// deleted through another library's, artist's or album's route; the mismatch is reported as not found.
|
||||
// Resource scoping: the track must belong to an artist of the library named by the route, so that a track can never be deleted through
|
||||
// another library's route; the mismatch is reported as not found, without disclosing that the artist exists in another library.
|
||||
if (existingArtist.LibraryId != libraryId)
|
||||
return DomainErrors.Music.TrackNotFound;
|
||||
AlbumEntity? existingAlbum = existingArtist.Albums.FirstOrDefault(album => album.Id == albumId);
|
||||
TrackEntity? existingTrack = existingAlbum?.Tracks.FirstOrDefault(track => track.Id == trackId);
|
||||
if (existingTrack is null)
|
||||
return DomainErrors.Music.TrackNotFound;
|
||||
return DomainErrors.Music.ArtistNotFound;
|
||||
|
||||
// Admins can delete the tracks of all libraries; for everyone else, only the tracks of the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
@@ -96,6 +91,13 @@ public class DeleteTrackCommandHandler : ICommandHandler<DeleteTrackCommand, Res
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
AlbumEntity? existingAlbum = existingArtist.Albums.FirstOrDefault(album => album.Id == albumId);
|
||||
if (existingAlbum is null)
|
||||
return DomainErrors.Music.AlbumNotFound;
|
||||
TrackEntity? existingTrack = existingAlbum.Tracks.FirstOrDefault(track => track.Id == trackId);
|
||||
if (existingTrack is null)
|
||||
return DomainErrors.Music.TrackNotFound;
|
||||
|
||||
// A track can only belong to a library that exists, so a client can never delete a track of a library of the host that is not there.
|
||||
Result<LibraryEntity?> getLibraryResult = await _unitOfWork.LibraryRepository
|
||||
.GetByIdAsync(libraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
@@ -109,14 +111,21 @@ public class DeleteTrackCommandHandler : ICommandHandler<DeleteTrackCommand, Res
|
||||
Result<Artist> artistResult = existingArtist.ToDomainEntity();
|
||||
if (artistResult.IsFailure)
|
||||
return artistResult.Errors;
|
||||
Result<Deleted> removeTrackResult = artistResult.Value.RemoveTrackFromAlbum(AlbumId.Create(albumId), TrackId.Create(trackId));
|
||||
// The album and the track are entities inside the artist aggregate, so they are referenced by object, not by id; the aggregate members are located here and passed through.
|
||||
Album? domainAlbum = artistResult.Value.Albums.FirstOrDefault(album => album.Id.Value == albumId);
|
||||
if (domainAlbum is null)
|
||||
return DomainErrors.Music.AlbumNotFound;
|
||||
Track? domainTrack = domainAlbum.Tracks.FirstOrDefault(track => track.Id.Value == trackId);
|
||||
if (domainTrack is null)
|
||||
return DomainErrors.Music.TrackNotFound;
|
||||
Result<Deleted> removeTrackResult = artistResult.Value.RemoveTrackFromAlbum(domainAlbum, domainTrack);
|
||||
if (removeTrackResult.IsFailure)
|
||||
return removeTrackResult.Errors;
|
||||
|
||||
Result<Updated> updateResult = await _unitOfWork.ArtistRepository
|
||||
.UpdateAsync(artistResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
|
||||
Result<Updated> updateResult = await _unitOfWork.ArtistRepository.UpdateAsync(artistResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsFailure)
|
||||
return updateResult.Errors;
|
||||
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
|
||||
+5
-5
@@ -30,10 +30,10 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.
|
||||
/// <param name="MusicBrainzRecordingId">The MusicBrainz identifier of the recording, if applicable.</param>
|
||||
/// <param name="MusicBrainzTrackId">The MusicBrainz identifier of the track, if applicable.</param>
|
||||
/// <param name="MusicBrainzWorkId">The MusicBrainz identifier of the work, if applicable.</param>
|
||||
/// <param name="Contributors">The list of media contributors that performed on the track.</param>
|
||||
/// <param name="Ratings">The list of ratings for this track.</param>
|
||||
/// <param name="Moods">The list of moods of the track.</param>
|
||||
/// <param name="Isrcs">The list of ISRC of the track.</param>
|
||||
/// <param name="Contributors">The list of media contributors that performed on the track.</param>
|
||||
/// <param name="Ratings">The list of ratings for this track.</param>
|
||||
[DebuggerDisplay("Title: {Metadata.Title}")]
|
||||
public record UpdateTrackCommand(
|
||||
string? LibraryId,
|
||||
@@ -51,8 +51,8 @@ public record UpdateTrackCommand(
|
||||
Guid? MusicBrainzRecordingId,
|
||||
Guid? MusicBrainzTrackId,
|
||||
Guid? MusicBrainzWorkId,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AudioRatingDto>? Ratings,
|
||||
List<MoodDto>? Moods,
|
||||
List<IsrcDto>? Isrcs
|
||||
List<IsrcDto>? Isrcs,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AudioRatingDto>? Ratings
|
||||
) : ICommand;
|
||||
+78
-11
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaContributors;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
@@ -13,6 +14,7 @@ using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.A
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Common;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
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.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
@@ -24,6 +26,7 @@ using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.ExternalIden
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Common;
|
||||
using System;
|
||||
@@ -45,6 +48,7 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<UpdateTrackCommand> _validator;
|
||||
private readonly IPathService _pathService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateTrackCommandHandler"/> class.
|
||||
@@ -53,12 +57,14 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public UpdateTrackCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<UpdateTrackCommand> validator)
|
||||
/// <param name="pathService">Injected service for file system path related functionality.</param>
|
||||
public UpdateTrackCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<UpdateTrackCommand> validator, IPathService pathService)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_validator = validator;
|
||||
_pathService = pathService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -92,15 +98,14 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
||||
if (getArtistResult.IsFailure)
|
||||
return getArtistResult.Errors;
|
||||
|
||||
// Resource scoping: the track must belong to the library, the artist and the album named by the route, so that a track can never be
|
||||
// edited through another library's, artist's or album's route; the mismatch is reported as not found.
|
||||
if (getArtistResult.Value is null || getArtistResult.Value.LibraryId != libraryId)
|
||||
return Errors.Music.TrackNotFound;
|
||||
if (getArtistResult.Value is null)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
ArtistEntity existingArtist = getArtistResult.Value;
|
||||
AlbumEntity? existingAlbum = existingArtist.Albums.FirstOrDefault(album => album.Id == albumId);
|
||||
TrackEntity? existingTrack = existingAlbum?.Tracks.FirstOrDefault(track => track.Id == trackId);
|
||||
if (existingTrack is null)
|
||||
return Errors.Music.TrackNotFound;
|
||||
|
||||
// Resource scoping: the track must belong to an artist of the library named by the route, so that a track can never be edited through
|
||||
// another library's route; the mismatch is reported as not found, without disclosing that the artist exists in another library.
|
||||
if (existingArtist.LibraryId != libraryId)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
|
||||
// Admins can update the tracks of all libraries; for everyone else, only the tracks of the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
@@ -108,6 +113,13 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
AlbumEntity? existingAlbum = existingArtist.Albums.FirstOrDefault(album => album.Id == albumId);
|
||||
if (existingAlbum is null)
|
||||
return Errors.Music.AlbumNotFound;
|
||||
TrackEntity? existingTrack = existingAlbum.Tracks.FirstOrDefault(track => track.Id == trackId);
|
||||
if (existingTrack is null)
|
||||
return Errors.Music.TrackNotFound;
|
||||
|
||||
// A track can only belong to a library that exists, so a client can never update a track of a library of the host that is not there.
|
||||
Result<LibraryEntity?> getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(libraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getLibraryResult.IsFailure)
|
||||
@@ -115,8 +127,18 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
||||
if (getLibraryResult.Value is null)
|
||||
return Errors.Library.LibraryNotFound;
|
||||
|
||||
// The write path goes through the aggregate root: a track is a child entity of the artist aggregate, unlike Book and Artist,
|
||||
// which are aggregate roots and are reconstituted directly with their own Create method. This difference is intentional.
|
||||
// A track is only readable if it is stored inside one of the content locations of its library, so a client can never edit an entry
|
||||
// that points the reading pipeline at an arbitrary file of the host.
|
||||
if (!AreTrackPathsWithinLibraryContentLocations(getLibraryResult.Value, command))
|
||||
return Errors.Music.TrackPathMustBeWithinLibraryContentLocations;
|
||||
|
||||
// Media contributors are referenced by Id and are never created implicitly by editing a track, so each one must already exist.
|
||||
Result<IReadOnlyList<MediaContributorEntity>> getContributorsResult = await GetExistingContributorsAsync(command, cancellationToken).ConfigureAwait(false);
|
||||
if (getContributorsResult.IsFailure)
|
||||
return getContributorsResult.Errors;
|
||||
|
||||
// The write path goes through the aggregate root: a track is a child entity of the artist aggregate, so it is mutated through its owning
|
||||
// artist. Book is itself an aggregate root, so its update flow reconstitutes it directly with its own Create method instead.
|
||||
Result<Artist> artistResult = existingArtist.ToDomainEntity();
|
||||
if (artistResult.IsFailure)
|
||||
return artistResult.Errors;
|
||||
@@ -141,4 +163,49 @@ public class UpdateTrackCommandHandler : ICommandHandler<UpdateTrackCommand, Res
|
||||
|
||||
return getPersistedTrackResult.Value.ToResponse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the track path referenced by <paramref name="command"/> is stored inside one of the content locations of <paramref name="library"/>.
|
||||
/// </summary>
|
||||
/// <param name="library">The media library that owns the track.</param>
|
||||
/// <param name="command">The command carrying the referenced track.</param>
|
||||
/// <returns><see langword="true"/> when the referenced track path is within a content location of the library; otherwise, <see langword="false"/>.</returns>
|
||||
private bool AreTrackPathsWithinLibraryContentLocations(LibraryEntity library, UpdateTrackCommand command)
|
||||
{
|
||||
return library.ContentLocations.Any(contentLocation => _pathService.IsPathWithin(command.Path!, contentLocation.Path));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media contributors referenced by <paramref name="command"/>, requiring each referenced Id to already exist.
|
||||
/// </summary>
|
||||
/// <param name="command">The command carrying the referenced media contributors.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the existing media contributors, or an error when at least one referenced contributor does not exist.
|
||||
/// </returns>
|
||||
private async Task<Result<IReadOnlyList<MediaContributorEntity>>> GetExistingContributorsAsync(UpdateTrackCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Guid> contributorIds = [.. CollectContributorIds(command).Distinct()];
|
||||
if (contributorIds.Count == 0)
|
||||
return Result.From<IReadOnlyList<MediaContributorEntity>>([]);
|
||||
|
||||
Result<IReadOnlyList<MediaContributorEntity>> getContributorsResult = await _unitOfWork.MediaContributorRepository
|
||||
.GetByIdsAsync(contributorIds, cancellationToken).ConfigureAwait(false);
|
||||
if (getContributorsResult.IsFailure)
|
||||
return getContributorsResult.Errors;
|
||||
if (getContributorsResult.Value.Count != contributorIds.Count)
|
||||
return Errors.MediaContributor.MediaContributorNotFound;
|
||||
return Result.From(getContributorsResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Collects the unique identifiers of every media contributor referenced by <paramref name="command"/>.
|
||||
/// </summary>
|
||||
/// <param name="command">The command carrying the referenced media contributors.</param>
|
||||
/// <returns>The collected media contributor identifiers.</returns>
|
||||
private static IEnumerable<Guid> CollectContributorIds(UpdateTrackCommand command)
|
||||
{
|
||||
foreach (MediaContributorReferenceDto contributor in command.Contributors!)
|
||||
yield return contributor.ContributorId;
|
||||
}
|
||||
}
|
||||
+18
@@ -202,6 +202,7 @@ public class UpdateTrackCommandValidator : AbstractValidator<UpdateTrackCommand>
|
||||
.When(m => m!.OriginalLanguage is not null);
|
||||
});
|
||||
|
||||
// Validates the MusicBrainz identifiers of the track.
|
||||
RuleFor(command => command.MusicBrainzRecordingId)
|
||||
.Must(musicBrainzRecordingId => musicBrainzRecordingId != Guid.Empty)
|
||||
.When(command => command.MusicBrainzRecordingId.HasValue)
|
||||
@@ -218,6 +219,10 @@ public class UpdateTrackCommandValidator : AbstractValidator<UpdateTrackCommand>
|
||||
.WithError(Errors.Music.MusicBrainzIdInvalidFormat);
|
||||
|
||||
// Validates the ordering and performance characteristics of the track.
|
||||
RuleFor(command => command.TrackNumber)
|
||||
.NotNull()
|
||||
.WithError(Errors.Music.TrackNumberMustBeGreaterThanZero);
|
||||
|
||||
RuleFor(command => command.TrackNumber)
|
||||
.GreaterThan(0)
|
||||
.When(command => command.TrackNumber.HasValue)
|
||||
@@ -248,6 +253,19 @@ public class UpdateTrackCommandValidator : AbstractValidator<UpdateTrackCommand>
|
||||
.When(command => command.Work is not null)
|
||||
.WithError(Errors.Music.WorkMustBeMaximum255CharactersLong);
|
||||
|
||||
// Validates the moods and the ISRC codes of the track.
|
||||
RuleForEach(command => command.Moods)
|
||||
.ChildRules(mood =>
|
||||
mood.RuleFor(m => m.Name)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Metadata.MoodNameCannotBeEmpty));
|
||||
|
||||
RuleForEach(command => command.Isrcs)
|
||||
.ChildRules(isrc =>
|
||||
isrc.RuleFor(i => i.Value)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.IsrcValueCannotBeEmpty));
|
||||
|
||||
// Validates the media contributors that performed on the track.
|
||||
RuleFor(command => command.Contributors)
|
||||
.NotNull()
|
||||
|
||||
+4
-5
@@ -6,7 +6,6 @@ using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
@@ -76,13 +75,13 @@ public class GetTrackQueryHandler : IQueryHandler<GetTrackQuery, Result<TrackRes
|
||||
if (getAlbumResult.IsFailure)
|
||||
return getAlbumResult.Errors;
|
||||
if (getAlbumResult.Value is null)
|
||||
return Errors.Music.TrackNotFound;
|
||||
return Errors.Music.AlbumNotFound;
|
||||
AlbumEntity existingAlbum = getAlbumResult.Value;
|
||||
|
||||
// Resource scoping: the album must belong to the library and the artist named by the route, so that a track can never be read through
|
||||
// another library's or artist's route; the mismatch is reported as not found, without disclosing that the track exists elsewhere.
|
||||
// Resource scoping: the album must belong to the artist and the library named by the route, so that a track can never be read through
|
||||
// another library's or artist's route; the mismatch is reported as not found, without disclosing that the album exists elsewhere.
|
||||
if (existingAlbum.LibraryId != libraryId || existingAlbum.ArtistId != artistId)
|
||||
return Errors.Music.TrackNotFound;
|
||||
return Errors.Music.AlbumNotFound;
|
||||
|
||||
Result<TrackEntity?> getTrackResult = await _unitOfWork.TrackRepository.GetByIdAsync(trackId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getTrackResult.IsFailure)
|
||||
|
||||
+5
-5
@@ -25,10 +25,10 @@ namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Track
|
||||
/// <param name="MusicBrainzRecordingId">The MusicBrainz identifier of the recording. Optional.</param>
|
||||
/// <param name="MusicBrainzTrackId">The MusicBrainz identifier of the track. Optional.</param>
|
||||
/// <param name="MusicBrainzWorkId">The MusicBrainz identifier of the work. Optional.</param>
|
||||
/// <param name="Contributors">The list of media contributors that performed on the track. Required.</param>
|
||||
/// <param name="Ratings">The list of ratings for this track. Required.</param>
|
||||
/// <param name="Moods">The list of moods of the track. Optional.</param>
|
||||
/// <param name="Isrcs">The list of ISRC (International Standard Recording Code) of the track. Optional.</param>
|
||||
/// <param name="Contributors">The list of media contributors that performed on the track. Required.</param>
|
||||
/// <param name="Ratings">The list of ratings for this track. Required.</param>
|
||||
[DebuggerDisplay("Title: {Metadata.Title}")]
|
||||
public record UpdateTrackRequest(
|
||||
string? Path,
|
||||
@@ -42,8 +42,8 @@ public record UpdateTrackRequest(
|
||||
Guid? MusicBrainzRecordingId,
|
||||
Guid? MusicBrainzTrackId,
|
||||
Guid? MusicBrainzWorkId,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AudioRatingDto>? Ratings,
|
||||
List<MoodDto>? Moods,
|
||||
List<IsrcDto>? Isrcs
|
||||
List<IsrcDto>? Isrcs,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AudioRatingDto>? Ratings
|
||||
);
|
||||
+5
-5
@@ -30,10 +30,10 @@ namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Trac
|
||||
/// <param name="MusicBrainzWorkId">The MusicBrainz identifier of the work, if applicable.</param>
|
||||
/// <param name="CreatedOnUtc">The date and time when the track was created.</param>
|
||||
/// <param name="UpdatedOnUtc">The optional date and time when the track was updated.</param>
|
||||
/// <param name="Contributors">The list of references to the media contributors that performed on the track, each with the role they played.</param>
|
||||
/// <param name="Ratings">The list of ratings for this track.</param>
|
||||
/// <param name="Moods">The list of moods of the track.</param>
|
||||
/// <param name="Isrcs">The list of ISRC (International Standard Recording Code) of the track.</param>
|
||||
/// <param name="Contributors">The list of references to the media contributors that performed on the track, each with the role they played.</param>
|
||||
/// <param name="Ratings">The list of ratings for this track.</param>
|
||||
[DebuggerDisplay("Title: {Metadata.Title}")]
|
||||
public record TrackResponse(
|
||||
Guid Id,
|
||||
@@ -52,8 +52,8 @@ public record TrackResponse(
|
||||
Guid? MusicBrainzWorkId,
|
||||
DateTime CreatedOnUtc,
|
||||
DateTime? UpdatedOnUtc,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AudioRatingDto>? Ratings,
|
||||
List<MoodDto>? Moods,
|
||||
List<IsrcDto>? Isrcs
|
||||
List<IsrcDto>? Isrcs,
|
||||
List<MediaContributorReferenceDto>? Contributors,
|
||||
List<AudioRatingDto>? Ratings
|
||||
);
|
||||
@@ -157,37 +157,6 @@ public class TrackConfiguration : IEntityTypeConfiguration<TrackEntity>
|
||||
j.ToTable("TrackGenres");
|
||||
});
|
||||
|
||||
builder.OwnsMany(track => track.Ratings, ratingBuilder =>
|
||||
{
|
||||
ratingBuilder.ToTable("TrackRatings");
|
||||
ratingBuilder.WithOwner()
|
||||
.HasForeignKey("TrackId");
|
||||
ratingBuilder.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
ratingBuilder.HasKey("Id");
|
||||
|
||||
ratingBuilder.Property(rating => rating.Value)
|
||||
.HasColumnType("decimal(3,2)")
|
||||
.IsRequired();
|
||||
|
||||
ratingBuilder.Property(rating => rating.MaxValue)
|
||||
.HasColumnType("decimal(3,2)")
|
||||
.IsRequired();
|
||||
|
||||
ratingBuilder.Property(rating => rating.VoteCount)
|
||||
.IsRequired(false);
|
||||
|
||||
ratingBuilder.Property(rating => rating.Source)
|
||||
.HasConversion<string>()
|
||||
.HasMaxLength(50)
|
||||
.IsRequired(false);
|
||||
});
|
||||
|
||||
builder.HasMany(track => track.Contributors)
|
||||
.WithOne()
|
||||
.HasForeignKey(contributor => contributor.TrackId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.OwnsMany(track => track.Moods, moodBuilder =>
|
||||
{
|
||||
moodBuilder.ToTable("TrackMoods");
|
||||
@@ -217,6 +186,37 @@ public class TrackConfiguration : IEntityTypeConfiguration<TrackEntity>
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
builder.HasMany(track => track.Contributors)
|
||||
.WithOne()
|
||||
.HasForeignKey(contributor => contributor.TrackId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.OwnsMany(track => track.Ratings, ratingBuilder =>
|
||||
{
|
||||
ratingBuilder.ToTable("TrackRatings");
|
||||
ratingBuilder.WithOwner()
|
||||
.HasForeignKey("TrackId");
|
||||
ratingBuilder.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
ratingBuilder.HasKey("Id");
|
||||
|
||||
ratingBuilder.Property(rating => rating.Value)
|
||||
.HasColumnType("decimal(3,2)")
|
||||
.IsRequired();
|
||||
|
||||
ratingBuilder.Property(rating => rating.MaxValue)
|
||||
.HasColumnType("decimal(3,2)")
|
||||
.IsRequired();
|
||||
|
||||
ratingBuilder.Property(rating => rating.VoteCount)
|
||||
.IsRequired(false);
|
||||
|
||||
ratingBuilder.Property(rating => rating.Source)
|
||||
.HasConversion<string>()
|
||||
.HasMaxLength(50)
|
||||
.IsRequired(false);
|
||||
});
|
||||
|
||||
builder.HasIndex(track => new { track.AlbumId, track.TrackNumber });
|
||||
builder.HasIndex(track => new { track.LibraryId, track.Path })
|
||||
.IsUnique(); // the same physical track file cannot appear twice in the same library
|
||||
|
||||
@@ -47,8 +47,10 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
return Errors.Music.TrackAlreadyExists;
|
||||
|
||||
// A track is unique within its library by its file system path, so the same file can never be registered twice in the same library.
|
||||
bool doesTrackPathExist = await _luminaDbContext.Tracks.AnyAsync(repositoryTrack => repositoryTrack.LibraryId == track.LibraryId && repositoryTrack.Path == track.Path, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (doesTrackPathExist)
|
||||
Result<IReadOnlyCollection<string>> getExistingPathsResult = await GetExistingPathsAsync(track.LibraryId, [track.Path], cancellationToken).ConfigureAwait(false);
|
||||
if (getExistingPathsResult.IsFailure)
|
||||
return getExistingPathsResult.Errors;
|
||||
if (getExistingPathsResult.Value.Count > 0)
|
||||
return Errors.Music.TrackAlreadyExists;
|
||||
|
||||
// Fetch existing tags and genres.
|
||||
@@ -67,6 +69,27 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
return Result.Created;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the subset of <paramref name="paths"/> that is already used by a track of the library identified by <paramref name="libraryId"/>.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the library whose tracks are searched.</param>
|
||||
/// <param name="paths">The track paths to check.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the paths that are already used, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyCollection<string>>> GetExistingPathsAsync(Guid libraryId, IReadOnlyCollection<string> paths, CancellationToken cancellationToken)
|
||||
{
|
||||
if (paths.Count == 0)
|
||||
return Result.From<IReadOnlyCollection<string>>([]);
|
||||
|
||||
// The stored paths are compared ordinally, matching the case sensitive comparison used by the unique index of the storage medium.
|
||||
List<string> distinctPaths = [.. paths.Distinct(StringComparer.Ordinal)];
|
||||
List<string> existingPaths = await _luminaDbContext.Tracks
|
||||
.Where(repositoryTrack => repositoryTrack.LibraryId == libraryId && distinctPaths.Contains(repositoryTrack.Path))
|
||||
.Select(repositoryTrack => repositoryTrack.Path)
|
||||
.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
return Result.From<IReadOnlyCollection<string>>(existingPaths);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing track, replacing only the editable data that actually changed, while preserving its identity, the identity of its children, and its audit columns.
|
||||
/// </summary>
|
||||
|
||||
+59
-45
@@ -19,8 +19,8 @@ namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLib
|
||||
[DebuggerDisplay("{Id}: {Metadata.Title}")]
|
||||
public sealed class Track : Entity<TrackId>
|
||||
{
|
||||
private readonly List<Isrc> _isrcs;
|
||||
private readonly List<Mood> _moods;
|
||||
private readonly List<Isrc> _isrcs;
|
||||
private readonly List<MusicMediaContributor> _contributors;
|
||||
private readonly List<AudioRating> _ratings;
|
||||
|
||||
@@ -107,42 +107,46 @@ public sealed class Track : Entity<TrackId>
|
||||
/// <param name="metadata">The audio metadata of the track.</param>
|
||||
/// <param name="trackNumber">The number of the track on its disc.</param>
|
||||
/// <param name="discNumber">The optional number of the disc the track belongs to.</param>
|
||||
/// <param name="isrcs">The list of ISRC of the track.</param>
|
||||
/// <param name="moods">The list of moods of the track.</param>
|
||||
/// <param name="script">The optional script used by the language of the track.</param>
|
||||
/// <param name="key">The optional musical key of the track.</param>
|
||||
/// <param name="bpm">The optional tempo of the track in beats per minute.</param>
|
||||
/// <param name="moods">The list of moods of the track.</param>
|
||||
/// <param name="isrcs">The list of ISRC of the track.</param>
|
||||
/// <param name="work">The optional title of the work the track is a recording of.</param>
|
||||
/// <param name="musicBrainzRecordingId">The optional MusicBrainz identifier of the recording.</param>
|
||||
/// <param name="musicBrainzTrackId">The optional MusicBrainz identifier of the track.</param>
|
||||
/// <param name="musicBrainzWorkId">The optional MusicBrainz identifier of the work.</param>
|
||||
/// <param name="contributors">The list of the media contributors of the track.</param>
|
||||
/// <param name="ratings">The list of ratings for the track.</param>
|
||||
/// <param name="createdOnUtc">The date and time when the entity was created.</param>
|
||||
/// <param name="updatedOnUtc">The date and time when the entity was last updated.</param>
|
||||
private Track(
|
||||
TrackId id,
|
||||
string path,
|
||||
AudioMetadata metadata,
|
||||
int trackNumber,
|
||||
Optional<int> discNumber,
|
||||
List<Isrc> isrcs,
|
||||
List<Mood> moods,
|
||||
Optional<string> script,
|
||||
Optional<MusicKey> key,
|
||||
Optional<int> bpm,
|
||||
List<Mood> moods,
|
||||
List<Isrc> isrcs,
|
||||
Optional<string> work,
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId,
|
||||
Optional<MusicBrainzId> musicBrainzTrackId,
|
||||
Optional<MusicBrainzId> musicBrainzWorkId,
|
||||
List<MusicMediaContributor> contributors,
|
||||
List<AudioRating> ratings) : base(id)
|
||||
List<AudioRating> ratings,
|
||||
DateTime createdOnUtc,
|
||||
Optional<DateTime> updatedOnUtc) : base(id)
|
||||
{
|
||||
Id = id;
|
||||
Path = path;
|
||||
Metadata = metadata;
|
||||
TrackNumber = trackNumber;
|
||||
DiscNumber = discNumber;
|
||||
_isrcs = isrcs;
|
||||
_moods = moods;
|
||||
_isrcs = isrcs;
|
||||
Script = script;
|
||||
Key = key;
|
||||
Bpm = bpm;
|
||||
@@ -152,6 +156,8 @@ public sealed class Track : Entity<TrackId>
|
||||
MusicBrainzWorkId = musicBrainzWorkId;
|
||||
_contributors = contributors;
|
||||
_ratings = ratings;
|
||||
CreatedOnUtc = createdOnUtc;
|
||||
UpdatedOnUtc = updatedOnUtc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -161,11 +167,11 @@ public sealed class Track : Entity<TrackId>
|
||||
/// <param name="metadata">The audio metadata of the track.</param>
|
||||
/// <param name="trackNumber">The number of the track on its disc.</param>
|
||||
/// <param name="discNumber">The optional number of the disc the track belongs to.</param>
|
||||
/// <param name="isrcs">The list of ISRC of the track.</param>
|
||||
/// <param name="moods">The list of moods of the track.</param>
|
||||
/// <param name="script">The optional script used by the language of the track.</param>
|
||||
/// <param name="key">The optional musical key of the track.</param>
|
||||
/// <param name="bpm">The optional tempo of the track in beats per minute.</param>
|
||||
/// <param name="moods">The list of moods of the track.</param>
|
||||
/// <param name="isrcs">The list of ISRC of the track.</param>
|
||||
/// <param name="work">The optional title of the work the track is a recording of.</param>
|
||||
/// <param name="musicBrainzRecordingId">The optional MusicBrainz identifier of the recording.</param>
|
||||
/// <param name="musicBrainzTrackId">The optional MusicBrainz identifier of the track.</param>
|
||||
@@ -180,11 +186,11 @@ public sealed class Track : Entity<TrackId>
|
||||
AudioMetadata metadata,
|
||||
int trackNumber,
|
||||
Optional<int> discNumber,
|
||||
List<Isrc> isrcs,
|
||||
List<Mood> moods,
|
||||
Optional<string> script,
|
||||
Optional<MusicKey> key,
|
||||
Optional<int> bpm,
|
||||
List<Mood> moods,
|
||||
List<Isrc> isrcs,
|
||||
Optional<string> work,
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId,
|
||||
Optional<MusicBrainzId> musicBrainzTrackId,
|
||||
@@ -198,17 +204,19 @@ public sealed class Track : Entity<TrackId>
|
||||
metadata,
|
||||
trackNumber,
|
||||
discNumber,
|
||||
isrcs,
|
||||
moods,
|
||||
script,
|
||||
key,
|
||||
bpm,
|
||||
moods,
|
||||
isrcs,
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
contributors,
|
||||
ratings);
|
||||
ratings,
|
||||
DateTime.UtcNow, // TODO: should be IDateTimeProvider
|
||||
Optional<DateTime>.None());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -219,17 +227,19 @@ public sealed class Track : Entity<TrackId>
|
||||
/// <param name="metadata">The audio metadata of the track.</param>
|
||||
/// <param name="trackNumber">The number of the track on its disc.</param>
|
||||
/// <param name="discNumber">The optional number of the disc the track belongs to.</param>
|
||||
/// <param name="isrcs">The list of ISRC of the track.</param>
|
||||
/// <param name="moods">The list of moods of the track.</param>
|
||||
/// <param name="script">The optional script used by the language of the track.</param>
|
||||
/// <param name="key">The optional musical key of the track.</param>
|
||||
/// <param name="bpm">The optional tempo of the track in beats per minute.</param>
|
||||
/// <param name="moods">The list of moods of the track.</param>
|
||||
/// <param name="isrcs">The list of ISRC of the track.</param>
|
||||
/// <param name="work">The optional title of the work the track is a recording of.</param>
|
||||
/// <param name="musicBrainzRecordingId">The optional MusicBrainz identifier of the recording.</param>
|
||||
/// <param name="musicBrainzTrackId">The optional MusicBrainz identifier of the track.</param>
|
||||
/// <param name="musicBrainzWorkId">The optional MusicBrainz identifier of the work.</param>
|
||||
/// <param name="contributors">The list of the media contributors of the track.</param>
|
||||
/// <param name="ratings">The list of ratings for the track.</param>
|
||||
/// <param name="createdOnUtc">The date and time when the entity was created.</param>
|
||||
/// <param name="updatedOnUtc">The date and time when the entity was last updated.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Track"/>, or an error message.
|
||||
/// </returns>
|
||||
@@ -239,17 +249,19 @@ public sealed class Track : Entity<TrackId>
|
||||
AudioMetadata metadata,
|
||||
int trackNumber,
|
||||
Optional<int> discNumber,
|
||||
List<Isrc> isrcs,
|
||||
List<Mood> moods,
|
||||
Optional<string> script,
|
||||
Optional<MusicKey> key,
|
||||
Optional<int> bpm,
|
||||
List<Mood> moods,
|
||||
List<Isrc> isrcs,
|
||||
Optional<string> work,
|
||||
Optional<MusicBrainzId> musicBrainzRecordingId,
|
||||
Optional<MusicBrainzId> musicBrainzTrackId,
|
||||
Optional<MusicBrainzId> musicBrainzWorkId,
|
||||
List<MusicMediaContributor> contributors,
|
||||
List<AudioRating> ratings)
|
||||
List<AudioRating> ratings,
|
||||
DateTime createdOnUtc,
|
||||
Optional<DateTime> updatedOnUtc)
|
||||
{
|
||||
return new Track(
|
||||
id,
|
||||
@@ -257,39 +269,19 @@ public sealed class Track : Entity<TrackId>
|
||||
metadata,
|
||||
trackNumber,
|
||||
discNumber,
|
||||
isrcs,
|
||||
moods,
|
||||
script,
|
||||
key,
|
||||
bpm,
|
||||
moods,
|
||||
isrcs,
|
||||
work,
|
||||
musicBrainzRecordingId,
|
||||
musicBrainzTrackId,
|
||||
musicBrainzWorkId,
|
||||
contributors,
|
||||
ratings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the media contributors of the track with the provided <paramref name="contributors"/>.
|
||||
/// </summary>
|
||||
/// <param name="contributors">The media contributors of the track.</param>
|
||||
internal void UpdateContributors(IReadOnlyCollection<MusicMediaContributor> contributors)
|
||||
{
|
||||
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
|
||||
_contributors.Clear();
|
||||
_contributors.AddRange(contributors);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the ratings of the track with the provided <paramref name="ratings"/>.
|
||||
/// </summary>
|
||||
/// <param name="ratings">The ratings of the track.</param>
|
||||
internal void UpdateRatings(IReadOnlyCollection<AudioRating> ratings)
|
||||
{
|
||||
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
|
||||
_ratings.Clear();
|
||||
_ratings.AddRange(ratings);
|
||||
ratings,
|
||||
createdOnUtc,
|
||||
updatedOnUtc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -314,6 +306,28 @@ public sealed class Track : Entity<TrackId>
|
||||
_isrcs.AddRange(isrcs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the media contributors of the track with the provided <paramref name="contributors"/>.
|
||||
/// </summary>
|
||||
/// <param name="contributors">The media contributors of the track.</param>
|
||||
internal void UpdateContributors(IReadOnlyCollection<MusicMediaContributor> contributors)
|
||||
{
|
||||
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
|
||||
_contributors.Clear();
|
||||
_contributors.AddRange(contributors);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the ratings of the track with the provided <paramref name="ratings"/>.
|
||||
/// </summary>
|
||||
/// <param name="ratings">The ratings of the track.</param>
|
||||
internal void UpdateRatings(IReadOnlyCollection<AudioRating> ratings)
|
||||
{
|
||||
// replace the contents of the collection in place, preserving the readonly reference invariants of the entity
|
||||
_ratings.Clear();
|
||||
_ratings.AddRange(ratings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the details of the track, without touching the moods, the ISRCs, the media contributors, and the ratings.
|
||||
/// </summary>
|
||||
@@ -353,7 +367,7 @@ public sealed class Track : Entity<TrackId>
|
||||
MusicBrainzRecordingId = musicBrainzRecordingId;
|
||||
MusicBrainzTrackId = musicBrainzTrackId;
|
||||
MusicBrainzWorkId = musicBrainzWorkId;
|
||||
UpdatedOnUtc = DateTime.UtcNow;
|
||||
UpdatedOnUtc = Optional<DateTime>.Some(DateTime.UtcNow);
|
||||
return Result.Updated;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -38,7 +38,7 @@ public sealed class Barcode : ValueObject
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Barcode"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Barcode> Create(string? value)
|
||||
public static Result<Barcode> Create(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return Errors.Music.BarcodeValueCannotBeEmpty;
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ public sealed class Isrc : ValueObject
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Isrc"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<Isrc> Create(string? value)
|
||||
public static Result<Isrc> Create(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return Errors.Music.IsrcValueCannotBeEmpty;
|
||||
|
||||
+1
-23
@@ -1,7 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -34,31 +32,11 @@ public sealed class MusicBrainzId : ValueObject
|
||||
/// </summary>
|
||||
/// <param name="value">The value used to create the <see cref="MusicBrainzId"/> instance.</param>
|
||||
/// <returns>The created <see cref="MusicBrainzId"/> instance.</returns>
|
||||
public static Result<MusicBrainzId> Create(Guid value)
|
||||
public static MusicBrainzId Create(Guid value)
|
||||
{
|
||||
if (value == Guid.Empty)
|
||||
return Errors.Music.MusicBrainzIdInvalidFormat;
|
||||
|
||||
return new MusicBrainzId(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="MusicBrainzId"/> class, from a <paramref name="value"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value used to create the <see cref="MusicBrainzId"/> instance.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="MusicBrainzId"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MusicBrainzId> Create(string? value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return Errors.Music.MusicBrainzIdInvalidFormat;
|
||||
if (!Guid.TryParse(value, out Guid parsedValue))
|
||||
return Errors.Music.MusicBrainzIdInvalidFormat;
|
||||
|
||||
return new MusicBrainzId(parsedValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of items that define equality of the object.
|
||||
/// </summary>
|
||||
|
||||
+1
@@ -10,6 +10,7 @@ public static partial class ApiRoutes
|
||||
/// </summary>
|
||||
public static class Tracks
|
||||
{
|
||||
public const string ADD_TRACK = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks";
|
||||
public const string GET_TRACK_BY_ID = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}";
|
||||
public const string UPDATE_TRACK = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}";
|
||||
public const string DELETE_TRACK = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}";
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.AddTrack;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{libraryId}/artists/{artistId}/albums/{albumId}/tracks</c> route.
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks</c> route.
|
||||
/// </summary>
|
||||
public class AddTrackEndpoint : BaseEndpoint<AddTrackRequest, IResult>
|
||||
{
|
||||
@@ -36,7 +36,7 @@ public class AddTrackEndpoint : BaseEndpoint<AddTrackRequest, IResult>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.Albums.ADD_TRACK);
|
||||
Routes(ApiRoutes.Tracks.ADD_TRACK);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
+42
-31
@@ -28,7 +28,7 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
public AddTrackEndpointSummary()
|
||||
{
|
||||
Summary = "Adds a new track to an album.";
|
||||
Description = "Adds a new track to the album identified by the request, returning the full details of the newly created track. The track is added by an Admin, who can add tracks to the albums of all libraries, or by the owner of the library of the album the track is added to.";
|
||||
Description = "Creates a new track in the album identified by the route and returns its details, including the location of the newly created resource. The request is handled by an Admin, who can add tracks to the albums of all libraries, or by the owner of the library.";
|
||||
|
||||
ExampleRequest = new AddTrackRequest(
|
||||
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
|
||||
@@ -80,6 +80,15 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
MusicBrainzRecordingId: Guid.NewGuid(),
|
||||
MusicBrainzTrackId: Guid.NewGuid(),
|
||||
MusicBrainzWorkId: Guid.NewGuid(),
|
||||
Moods:
|
||||
[
|
||||
new MoodDto(Name: "dramatic"),
|
||||
new MoodDto(Name: "anxious")
|
||||
],
|
||||
Isrcs:
|
||||
[
|
||||
new IsrcDto(Value: "GBUM71029604")
|
||||
],
|
||||
Contributors:
|
||||
[
|
||||
new MediaContributorReferenceDto(
|
||||
@@ -105,15 +114,6 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
Source: AudioRatingSource.LastFm,
|
||||
VoteCount: 1234
|
||||
)
|
||||
],
|
||||
Moods:
|
||||
[
|
||||
new MoodDto(Name: "dramatic"),
|
||||
new MoodDto(Name: "anxious")
|
||||
],
|
||||
Isrcs:
|
||||
[
|
||||
new IsrcDto(Value: "GBUM71029604")
|
||||
]
|
||||
);
|
||||
|
||||
@@ -128,7 +128,7 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
RequestParam(r => r.Metadata!.BitDepth, "The bit depth of the audio of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.AudioCodec, "The audio codec used by the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Bitrate, "The bitrate of the audio of the track in kbps. Optional.");
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Optional.");
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Required.");
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the track. Optional.");
|
||||
@@ -136,15 +136,15 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Language, "The language of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the track in English. Optional.");
|
||||
RequestParam(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the track. Required.");
|
||||
RequestParam(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the track in English. Required.");
|
||||
RequestParam(r => r.Metadata!.Language!.NativeName, "The native name of the language of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.OriginalLanguage, "The original language of the track, if it has been translated. Optional.");
|
||||
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the track in English. Optional.");
|
||||
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the track. Required.");
|
||||
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the track in English. Required.");
|
||||
RequestParam(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Genres, "The list of genres associated with the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Genres, "The list of genres associated with the track. Required.");
|
||||
RequestParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track. Required.");
|
||||
RequestParam(r => r.TrackNumber, "The number of the track on its disc. Required.");
|
||||
RequestParam(r => r.DiscNumber, "The number of the disc the track belongs to. Optional.");
|
||||
RequestParam(r => r.Script, "The script used by the language of the track. Optional.");
|
||||
@@ -154,10 +154,10 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
RequestParam(r => r.MusicBrainzRecordingId, "The MusicBrainz identifier of the recording. Optional.");
|
||||
RequestParam(r => r.MusicBrainzTrackId, "The MusicBrainz identifier of the track. Optional.");
|
||||
RequestParam(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work. Optional.");
|
||||
RequestParam(r => r.Contributors, "The list of media contributors that performed on the track. Optional.");
|
||||
RequestParam(r => r.Ratings, "The list of ratings for this track. Required.");
|
||||
RequestParam(r => r.Moods, "The list of moods of the track. Optional.");
|
||||
RequestParam(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track. Optional.");
|
||||
RequestParam(r => r.Contributors, "The list of media contributors that performed on the track. Required.");
|
||||
RequestParam(r => r.Ratings, "The list of ratings for this track. Required.");
|
||||
|
||||
ResponseParam<TrackResponse>(r => r.Id, "The Id of the track.");
|
||||
ResponseParam<TrackResponse>(r => r.AlbumId, "The Id of the album the track belongs to.");
|
||||
@@ -177,6 +177,8 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
ResponseParam<TrackResponse>(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
|
||||
ResponseParam<TrackResponse>(r => r.CreatedOnUtc, "The date and time when the track was created.");
|
||||
ResponseParam<TrackResponse>(r => r.UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
|
||||
ResponseParam<TrackResponse>(r => r.Moods, "The list of moods of the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
|
||||
ResponseParam<TrackResponse>(r => r.Ratings, "The list of ratings for this track.");
|
||||
ResponseParam<TrackResponse>(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
|
||||
@@ -199,8 +201,6 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track, if applicable.");
|
||||
ResponseParam<TrackResponse>(r => r.Metadata!.Genres, "The list of genres associated with the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Moods, "The list of moods of the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
|
||||
|
||||
Response(201, "The newly created track is returned.",
|
||||
example: new TrackResponse(
|
||||
@@ -256,6 +256,13 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
MusicBrainzWorkId: Guid.NewGuid(),
|
||||
CreatedOnUtc: DateTime.UtcNow,
|
||||
UpdatedOnUtc: default,
|
||||
Moods: [
|
||||
new MoodDto(Name: "dramatic"),
|
||||
new MoodDto(Name: "anxious")
|
||||
],
|
||||
Isrcs: [
|
||||
new IsrcDto(Value: "GBUM71029604")
|
||||
],
|
||||
Contributors: [
|
||||
new MediaContributorReferenceDto(
|
||||
ContributorId: Guid.NewGuid(),
|
||||
@@ -279,13 +286,6 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
Source: AudioRatingSource.LastFm,
|
||||
VoteCount: 1234
|
||||
)
|
||||
],
|
||||
Moods: [
|
||||
new MoodDto(Name: "dramatic"),
|
||||
new MoodDto(Name: "anxious")
|
||||
],
|
||||
Isrcs: [
|
||||
new IsrcDto(Value: "GBUM71029604")
|
||||
]
|
||||
)
|
||||
);
|
||||
@@ -298,7 +298,7 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks"
|
||||
},
|
||||
new
|
||||
@@ -306,7 +306,7 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
detail = "The token has expired",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks"
|
||||
},
|
||||
new
|
||||
@@ -332,9 +332,18 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the requested album, its media library, or one of the referenced media contributors does not exist.", "application/problem+json",
|
||||
Response(404, "The request failed because the requested artist or album, its media library, or one of the referenced media contributors does not exist.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "ArtistNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
@@ -438,6 +447,8 @@ public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest
|
||||
"UnknownMusicKey",
|
||||
"BpmMustBeGreaterThanZero",
|
||||
"WorkMustBeMaximum255CharactersLong",
|
||||
"MoodNameCannotBeEmpty",
|
||||
"IsrcValueCannotBeEmpty",
|
||||
"ContributorsListCannotBeNull",
|
||||
"MediaContributorIdCannotBeEmpty",
|
||||
"UnknownMediaContributorRole",
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ public class DeleteTrackEndpointSummary : Summary<DeleteTrackEndpoint, EmptyRequ
|
||||
public DeleteTrackEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes an existing track.";
|
||||
Description = "Deletes the track identified by the request. The track is deleted by an Admin, who can delete the tracks of all libraries, or by the owner of the library of the track.";
|
||||
Description = "Deletes the track identified by the route. The track is deleted by an Admin, who can delete the tracks of all libraries, or by the owner of the library of the track.";
|
||||
|
||||
Response(200, "The track was successfully deleted.");
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.GetTrack;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/artists/{artistId}/albums/{albumId}/tracks/{trackId}</c> route.
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}</c> route.
|
||||
/// </summary>
|
||||
public class GetTrackEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
|
||||
+34
-19
@@ -47,6 +47,8 @@ public class GetTrackEndpointSummary : Summary<GetTrackEndpoint, EmptyRequest>
|
||||
ResponseParam<TrackResponse>(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
|
||||
ResponseParam<TrackResponse>(r => r.CreatedOnUtc, "The date and time when the track was created.");
|
||||
ResponseParam<TrackResponse>(r => r.UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
|
||||
ResponseParam<TrackResponse>(r => r.Moods, "The list of moods of the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
|
||||
ResponseParam<TrackResponse>(r => r.Ratings, "The list of ratings for this track.");
|
||||
ResponseParam<TrackResponse>(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
|
||||
@@ -69,8 +71,6 @@ public class GetTrackEndpointSummary : Summary<GetTrackEndpoint, EmptyRequest>
|
||||
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track, if applicable.");
|
||||
ResponseParam<TrackResponse>(r => r.Metadata!.Genres, "The list of genres associated with the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Moods, "The list of moods of the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
|
||||
|
||||
Response(200, "The requested track is returned.",
|
||||
example: new TrackResponse(
|
||||
@@ -126,6 +126,13 @@ public class GetTrackEndpointSummary : Summary<GetTrackEndpoint, EmptyRequest>
|
||||
MusicBrainzWorkId: Guid.NewGuid(),
|
||||
CreatedOnUtc: DateTime.UtcNow,
|
||||
UpdatedOnUtc: DateTime.UtcNow,
|
||||
Moods: [
|
||||
new MoodDto(Name: "dramatic"),
|
||||
new MoodDto(Name: "anxious")
|
||||
],
|
||||
Isrcs: [
|
||||
new IsrcDto(Value: "GBUM71029604")
|
||||
],
|
||||
Contributors: [
|
||||
new MediaContributorReferenceDto(
|
||||
ContributorId: Guid.NewGuid(),
|
||||
@@ -149,13 +156,6 @@ public class GetTrackEndpointSummary : Summary<GetTrackEndpoint, EmptyRequest>
|
||||
Source: AudioRatingSource.LastFm,
|
||||
VoteCount: 1234
|
||||
)
|
||||
],
|
||||
Moods: [
|
||||
new MoodDto(Name: "dramatic"),
|
||||
new MoodDto(Name: "anxious")
|
||||
],
|
||||
Isrcs: [
|
||||
new IsrcDto(Value: "GBUM71029604")
|
||||
]
|
||||
)
|
||||
);
|
||||
@@ -168,7 +168,7 @@ public class GetTrackEndpointSummary : Summary<GetTrackEndpoint, EmptyRequest>
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "You are not authorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}"
|
||||
},
|
||||
new
|
||||
@@ -176,7 +176,7 @@ public class GetTrackEndpointSummary : Summary<GetTrackEndpoint, EmptyRequest>
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
|
||||
detail = "The token has expired",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}"
|
||||
},
|
||||
new
|
||||
@@ -202,15 +202,27 @@ public class GetTrackEndpointSummary : Summary<GetTrackEndpoint, EmptyRequest>
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the requested track does not exist.", "application/problem+json",
|
||||
example: new
|
||||
Response(404, "The request failed because the requested album or track does not exist.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "TrackNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "AlbumNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "TrackNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -227,6 +239,9 @@ public class GetTrackEndpointSummary : Summary<GetTrackEndpoint, EmptyRequest>
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty",
|
||||
"ArtistIdCannotBeEmpty",
|
||||
"AlbumIdCannotBeEmpty",
|
||||
"TrackIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.UpdateTrack;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}</c> route.
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}</c> route.
|
||||
/// </summary>
|
||||
public class UpdateTrackEndpoint : BaseEndpoint<UpdateTrackRequest, IResult>
|
||||
{
|
||||
|
||||
+108
-31
@@ -1,4 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
@@ -28,7 +28,7 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
public UpdateTrackEndpointSummary()
|
||||
{
|
||||
Summary = "Updates an existing track.";
|
||||
Description = "Updates the details of the track identified by the request, returning the full details of the updated track. The track is updated by an Admin, who can update the tracks of all libraries, or by the owner of the library of the track.";
|
||||
Description = "Updates the details of the track identified by the route, returning the full details of the updated track. The track is updated by an Admin, who can update the tracks of all libraries, or by the owner of the library of the track.";
|
||||
|
||||
ExampleRequest = new UpdateTrackRequest(
|
||||
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
|
||||
@@ -80,6 +80,15 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
MusicBrainzRecordingId: Guid.NewGuid(),
|
||||
MusicBrainzTrackId: Guid.NewGuid(),
|
||||
MusicBrainzWorkId: Guid.NewGuid(),
|
||||
Moods:
|
||||
[
|
||||
new MoodDto(Name: "dramatic"),
|
||||
new MoodDto(Name: "anxious")
|
||||
],
|
||||
Isrcs:
|
||||
[
|
||||
new IsrcDto(Value: "GBUM71029604")
|
||||
],
|
||||
Contributors:
|
||||
[
|
||||
new MediaContributorReferenceDto(
|
||||
@@ -105,15 +114,6 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
Source: AudioRatingSource.LastFm,
|
||||
VoteCount: 1234
|
||||
)
|
||||
],
|
||||
Moods:
|
||||
[
|
||||
new MoodDto(Name: "dramatic"),
|
||||
new MoodDto(Name: "anxious")
|
||||
],
|
||||
Isrcs:
|
||||
[
|
||||
new IsrcDto(Value: "GBUM71029604")
|
||||
]
|
||||
);
|
||||
|
||||
@@ -128,7 +128,7 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
RequestParam(r => r.Metadata!.BitDepth, "The bit depth of the audio of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.AudioCodec, "The audio codec used by the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Bitrate, "The bitrate of the audio of the track in kbps. Optional.");
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Optional.");
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Required.");
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the track. Optional.");
|
||||
@@ -136,15 +136,15 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Language, "The language of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the track in English. Optional.");
|
||||
RequestParam(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the track. Required.");
|
||||
RequestParam(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the track in English. Required.");
|
||||
RequestParam(r => r.Metadata!.Language!.NativeName, "The native name of the language of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.OriginalLanguage, "The original language of the track, if it has been translated. Optional.");
|
||||
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the track in English. Optional.");
|
||||
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the track. Required.");
|
||||
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the track in English. Required.");
|
||||
RequestParam(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Genres, "The list of genres associated with the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track. Optional.");
|
||||
RequestParam(r => r.Metadata!.Genres, "The list of genres associated with the track. Required.");
|
||||
RequestParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track. Required.");
|
||||
RequestParam(r => r.TrackNumber, "The number of the track on its disc. Required.");
|
||||
RequestParam(r => r.DiscNumber, "The number of the disc the track belongs to. Optional.");
|
||||
RequestParam(r => r.Script, "The script used by the language of the track. Optional.");
|
||||
@@ -154,10 +154,10 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
RequestParam(r => r.MusicBrainzRecordingId, "The MusicBrainz identifier of the recording. Optional.");
|
||||
RequestParam(r => r.MusicBrainzTrackId, "The MusicBrainz identifier of the track. Optional.");
|
||||
RequestParam(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work. Optional.");
|
||||
RequestParam(r => r.Contributors, "The list of media contributors that performed on the track. Required.");
|
||||
RequestParam(r => r.Ratings, "The list of ratings for this track. Required.");
|
||||
RequestParam(r => r.Moods, "The list of moods of the track. Optional.");
|
||||
RequestParam(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track. Optional.");
|
||||
RequestParam(r => r.Contributors, "The list of media contributors that performed on the track. Required.");
|
||||
RequestParam(r => r.Ratings, "The list of ratings for this track. Required.");
|
||||
|
||||
ResponseParam<TrackResponse>(r => r.Id, "The Id of the track.");
|
||||
ResponseParam<TrackResponse>(r => r.AlbumId, "The Id of the album the track belongs to.");
|
||||
@@ -177,6 +177,8 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
ResponseParam<TrackResponse>(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
|
||||
ResponseParam<TrackResponse>(r => r.CreatedOnUtc, "The date and time when the track was created.");
|
||||
ResponseParam<TrackResponse>(r => r.UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
|
||||
ResponseParam<TrackResponse>(r => r.Moods, "The list of moods of the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
|
||||
ResponseParam<TrackResponse>(r => r.Ratings, "The list of ratings for this track.");
|
||||
ResponseParam<TrackResponse>(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
|
||||
@@ -199,8 +201,6 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track, if applicable.");
|
||||
ResponseParam<TrackResponse>(r => r.Metadata!.Genres, "The list of genres associated with the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Moods, "The list of moods of the track.");
|
||||
ResponseParam<TrackResponse>(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
|
||||
|
||||
Response(200, "The updated track is returned.",
|
||||
example: new TrackResponse(
|
||||
@@ -256,6 +256,13 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
MusicBrainzWorkId: Guid.NewGuid(),
|
||||
CreatedOnUtc: DateTime.UtcNow,
|
||||
UpdatedOnUtc: DateTime.UtcNow,
|
||||
Moods: [
|
||||
new MoodDto(Name: "dramatic"),
|
||||
new MoodDto(Name: "anxious")
|
||||
],
|
||||
Isrcs: [
|
||||
new IsrcDto(Value: "GBUM71029604")
|
||||
],
|
||||
Contributors: [
|
||||
new MediaContributorReferenceDto(
|
||||
ContributorId: Guid.NewGuid(),
|
||||
@@ -279,13 +286,6 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
Source: AudioRatingSource.LastFm,
|
||||
VoteCount: 1234
|
||||
)
|
||||
],
|
||||
Moods: [
|
||||
new MoodDto(Name: "dramatic"),
|
||||
new MoodDto(Name: "anxious")
|
||||
],
|
||||
Isrcs: [
|
||||
new IsrcDto(Value: "GBUM71029604")
|
||||
]
|
||||
)
|
||||
);
|
||||
@@ -332,9 +332,27 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the requested track or its media library does not exist.", "application/problem+json",
|
||||
Response(404, "The request failed because the requested artist, album, track, their media library, or one of the referenced media contributors does not exist.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "ArtistNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "AlbumNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
@@ -352,10 +370,31 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
detail = "LibraryNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "MediaContributorNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because the new file system path already belongs to another track in the library, or because a unique constraint was violated.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "UniqueConstraintViolation",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
@@ -374,11 +413,49 @@ public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTra
|
||||
"AlbumIdCannotBeEmpty",
|
||||
"TrackIdCannotBeEmpty",
|
||||
"TrackPathCannotBeEmpty",
|
||||
"TrackPathMustBeMaximum2048CharactersLong",
|
||||
"MetadataCannotBeNull",
|
||||
"TitleCannotBeEmpty",
|
||||
"TitleMustBeMaximum255CharactersLong",
|
||||
"OriginalTitleMustBeMaximum255CharactersLong",
|
||||
"DescriptionMustBeMaximum2000CharactersLong",
|
||||
"ReleaseInfoCannotBeNull",
|
||||
"OriginalReleaseYearMustBeBetween1And9999",
|
||||
"ReReleaseYearMustBeBetween1And9999",
|
||||
"ReleaseVersionMustBeMaximum50CharactersLong",
|
||||
"OriginalReleaseDateAndYearMustMatch",
|
||||
"ReReleaseDateAndYearMustMatch",
|
||||
"ReReleaseYearCannotBeEarlierThanOriginalReleaseYear",
|
||||
"ReReleaseDateCannotBeEarlierThanOriginalReleaseDate",
|
||||
"GenresListCannotBeNull",
|
||||
"GenreNameCannotBeEmpty",
|
||||
"GenreNameMustBeMaximum50CharactersLong",
|
||||
"TagsListCannotBeNull",
|
||||
"TagNameCannotBeEmpty",
|
||||
"TagNameMustBeMaximum50CharactersLong",
|
||||
"LanguageCodeCannotBeEmpty",
|
||||
"LanguageCodeMustBe2CharactersLong",
|
||||
"LanguageNameCannotBeEmpty",
|
||||
"LanguageNameMustBeMaximum50CharactersLong",
|
||||
"LanguageNativeNameMustBeMaximum50CharactersLong",
|
||||
"MusicBrainzIdInvalidFormat",
|
||||
"TrackNumberMustBeGreaterThanZero",
|
||||
"DiscNumberMustBeGreaterThanZero",
|
||||
"ScriptMustBeMaximum50CharactersLong",
|
||||
"UnknownMusicKey",
|
||||
"BpmMustBeGreaterThanZero",
|
||||
"WorkMustBeMaximum255CharactersLong",
|
||||
"MoodNameCannotBeEmpty",
|
||||
"IsrcValueCannotBeEmpty",
|
||||
"ContributorsListCannotBeNull",
|
||||
"MediaContributorIdCannotBeEmpty",
|
||||
"UnknownMediaContributorRole",
|
||||
"MusicBrainzIdInvalidFormat"
|
||||
"RatingsListCannotBeNull",
|
||||
"RatingValueMustBePositive",
|
||||
"RatingValueCannotBeGreaterThanMaxValue",
|
||||
"RatingMaxValueMustBePositive",
|
||||
"RatingVoteCountMustBePositive",
|
||||
"TrackPathMustBeWithinLibraryContentLocations"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user