diff --git a/docs/technical/api/library/audio-library/music-library/Api.Tracks.md b/docs/technical/api/library/audio-library/music-library/Api.Tracks.md
index a67c0a7f..d578a1a1 100644
--- a/docs/technical/api/library/audio-library/music-library/Api.Tracks.md
+++ b/docs/technical/api/library/audio-library/music-library/Api.Tracks.md
@@ -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.
diff --git a/docs/technical/requests/library/audio-library/music-library/tracks/AddTrack.http b/docs/technical/requests/library/audio-library/music-library/tracks/AddTrack.http
index f9451ec8..2bbfabe7 100644
--- a/docs/technical/requests/library/audio-library/music-library/tracks/AddTrack.http
+++ b/docs/technical/requests/library/audio-library/music-library/tracks/AddTrack.http
@@ -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" }
]
}
diff --git a/docs/technical/requests/library/audio-library/music-library/tracks/UpdateTrack.http b/docs/technical/requests/library/audio-library/music-library/tracks/UpdateTrack.http
index a6fc09d9..f7ae653d 100644
--- a/docs/technical/requests/library/audio-library/music-library/tracks/UpdateTrack.http
+++ b/docs/technical/requests/library/audio-library/music-library/tracks/UpdateTrack.http
@@ -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" }
]
}
diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackEntity.cs
index 1fb5fd5a..8ea83524 100644
--- a/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackEntity.cs
+++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaLibrary/AudioLibrary/MusicLibrary/TrackEntity.cs
@@ -190,16 +190,6 @@ public class TrackEntity : IStorageEntity, IAuditableEntity
///
public AlbumEntity? Album { get; set; }
- ///
- /// Gets or sets the list of ratings for this track.
- ///
- public List Ratings { get; set; } = [];
-
- ///
- /// Gets or sets the list of the media contributors of the track.
- ///
- public List Contributors { get; set; } = [];
-
///
/// Gets or sets the list of moods of the track.
///
@@ -210,6 +200,16 @@ public class TrackEntity : IStorageEntity, IAuditableEntity
///
public List Isrcs { get; set; } = [];
+ ///
+ /// Gets or sets the list of the media contributors of the track.
+ ///
+ public List Contributors { get; set; } = [];
+
+ ///
+ /// Gets or sets the list of ratings for this track.
+ ///
+ public List Ratings { get; set; } = [];
+
///
/// Gets or sets the genres of the track.
///
diff --git a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/ITrackRepository.cs b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/ITrackRepository.cs
index 84b961b5..a3d09249 100644
--- a/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/ITrackRepository.cs
+++ b/src/Lumina.Application/Common/DataAccess/Repositories/MusicLibrary/ITrackRepository.cs
@@ -21,6 +21,15 @@ public interface ITrackRepository : IRepository,
IUpdateRepositoryAction,
IGetByIdRepositoryAction
{
+ ///
+ /// Gets the subset of that is already used by a track of the library identified by .
+ ///
+ /// The Id of the library whose tracks are searched.
+ /// The track paths to check.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the paths that are already used, or an error.
+ Task>> GetExistingPathsAsync(Guid libraryId, IReadOnlyCollection paths, CancellationToken cancellationToken);
+
///
/// Gets all the tracks of the album identified by .
///
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/IsrcDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/IsrcDtoMapping.cs
index 4674d1f2..ee7951b6 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/IsrcDtoMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/IsrcDtoMapping.cs
@@ -22,7 +22,7 @@ public static class IsrcDtoMapping
///
public static Result ToDomainEntity(this IsrcDto dto)
{
- return Isrc.Create(dto.Value);
+ return Isrc.Create(dto.Value!);
}
///
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/IsrcEntityMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/IsrcEntityMapping.cs
index d98cb0fb..4499e159 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/IsrcEntityMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/IsrcEntityMapping.cs
@@ -45,7 +45,7 @@ public static class IsrcEntityMapping
///
public static Result ToDomainEntity(this TrackIsrcEntity repositoryEntity)
{
- return Isrc.Create(repositoryEntity.Value);
+ return Isrc.Create(repositoryEntity.Value!);
}
///
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/MoodDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/MoodDtoMapping.cs
index 9b8230b0..661ec0ed 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/MoodDtoMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/MoodDtoMapping.cs
@@ -22,7 +22,7 @@ public static class MoodDtoMapping
///
public static Result ToDomainEntity(this MoodDto dto)
{
- return Mood.Create(dto.Name);
+ return Mood.Create(dto.Name!);
}
///
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/MoodEntityMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/MoodEntityMapping.cs
index 6c9cc533..b70c86d3 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/MoodEntityMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Common/MoodEntityMapping.cs
@@ -45,7 +45,7 @@ public static class MoodEntityMapping
///
public static Result ToDomainEntity(this TrackMoodEntity repositoryEntity)
{
- return Mood.Create(repositoryEntity.Name);
+ return Mood.Create(repositoryEntity.Name!);
}
///
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/AddTrackCommandMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/AddTrackCommandMapping.cs
index 65d75067..e609bdf1 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/AddTrackCommandMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/AddTrackCommandMapping.cs
@@ -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> domainIsrcsResult = (command.Isrcs ?? []).ToDomainEntities();
- List errors = [.. domainIsrcsResult.Where(isrcResult => isrcResult.IsFailure).SelectMany(isrcResult => isrcResult.Errors)];
- if (errors.Count > 0)
- return errors;
-
IEnumerable> domainMoodsResult = (command.Moods ?? []).ToDomainEntities();
- errors = [.. domainMoodsResult.Where(moodResult => moodResult.IsFailure).SelectMany(moodResult => moodResult.Errors)];
+ List errors = [.. domainMoodsResult.Where(moodResult => moodResult.IsFailure).SelectMany(moodResult => moodResult.Errors)];
if (errors.Count > 0)
return errors;
- IEnumerable> domainContributorsResult = (command.Contributors ?? []).ToMusicDomainEntities();
+ IEnumerable> domainIsrcsResult = (command.Isrcs ?? []).ToDomainEntities();
+ errors = [.. domainIsrcsResult.Where(isrcResult => isrcResult.IsFailure).SelectMany(isrcResult => isrcResult.Errors)];
+ if (errors.Count > 0)
+ return errors;
+
+ IEnumerable> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
errors = [.. domainContributorsResult.Where(contributorResult => contributorResult.IsFailure).SelectMany(contributorResult => contributorResult.Errors)];
if (errors.Count > 0)
return errors;
- IEnumerable> domainRatingsResult = (command.Ratings ?? []).ToDomainEntities();
+ IEnumerable> domainRatingsResult = command.Ratings!.ToDomainEntities();
errors = [.. domainRatingsResult.Where(ratingResult => ratingResult.IsFailure).SelectMany(ratingResult => ratingResult.Errors)];
if (errors.Count > 0)
return errors;
Optional musicBrainzRecordingId = Optional.None();
if (command.MusicBrainzRecordingId is not null)
- {
- Result musicBrainzRecordingIdResult = MusicBrainzId.Create(command.MusicBrainzRecordingId.Value);
- if (musicBrainzRecordingIdResult.IsFailure)
- return musicBrainzRecordingIdResult.Errors;
- musicBrainzRecordingId = musicBrainzRecordingIdResult.Value;
- }
+ musicBrainzRecordingId = MusicBrainzId.Create(command.MusicBrainzRecordingId.Value);
Optional musicBrainzTrackId = Optional.None();
if (command.MusicBrainzTrackId is not null)
- {
- Result musicBrainzTrackIdResult = MusicBrainzId.Create(command.MusicBrainzTrackId.Value);
- if (musicBrainzTrackIdResult.IsFailure)
- return musicBrainzTrackIdResult.Errors;
- musicBrainzTrackId = musicBrainzTrackIdResult.Value;
- }
+ musicBrainzTrackId = MusicBrainzId.Create(command.MusicBrainzTrackId.Value);
Optional musicBrainzWorkId = Optional.None();
if (command.MusicBrainzWorkId is not null)
- {
- Result musicBrainzWorkIdResult = MusicBrainzId.Create(command.MusicBrainzWorkId.Value);
- if (musicBrainzWorkIdResult.IsFailure)
- return musicBrainzWorkIdResult.Errors;
- musicBrainzWorkId = musicBrainzWorkIdResult.Value;
- }
+ musicBrainzWorkId = MusicBrainzId.Create(command.MusicBrainzWorkId.Value);
- List isrcs = [.. domainIsrcsResult.Select(isrcResult => isrcResult.Value)];
List moods = [.. domainMoodsResult.Select(moodResult => moodResult.Value)];
+ List isrcs = [.. domainIsrcsResult.Select(isrcResult => isrcResult.Value)];
List contributors = [.. domainContributorsResult.Select(contributorResult => contributorResult.Value)];
List 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.FromNullable(command.DiscNumber),
- isrcs,
+ moods,
Optional.FromNullable(command.Script),
Optional.FromNullable(command.Key),
Optional.FromNullable(command.Bpm),
- moods,
+ isrcs,
Optional.FromNullable(command.Work),
musicBrainzRecordingId,
musicBrainzTrackId,
musicBrainzWorkId,
contributors,
- ratings);
+ ratings,
+ DateTime.UtcNow,
+ Optional.None());
return Track.Create(
command.Path!,
metadataResult.Value,
- command.TrackNumber ?? 1,
+ command.TrackNumber!.Value,
Optional.FromNullable(command.DiscNumber),
- isrcs,
+ moods,
Optional.FromNullable(command.Script),
Optional.FromNullable(command.Key),
Optional.FromNullable(command.Bpm),
- moods,
+ isrcs,
Optional.FromNullable(command.Work),
musicBrainzRecordingId,
musicBrainzTrackId,
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackEntityMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackEntityMapping.cs
index ad2ecdb1..3689e5c8 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackEntityMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackEntityMapping.cs
@@ -91,27 +91,20 @@ public static class TrackEntityMapping
Optional musicBrainzRecordingId = Optional.None();
if (repositoryEntity.MusicBrainzRecordingId is not null)
- {
- Result musicBrainzRecordingIdResult = MusicBrainzId.Create(repositoryEntity.MusicBrainzRecordingId.Value);
- if (musicBrainzRecordingIdResult.IsFailure)
- return musicBrainzRecordingIdResult.Errors;
- musicBrainzRecordingId = musicBrainzRecordingIdResult.Value;
- }
+ musicBrainzRecordingId = MusicBrainzId.Create(repositoryEntity.MusicBrainzRecordingId.Value);
Optional musicBrainzTrackId = Optional.None();
if (repositoryEntity.MusicBrainzTrackId is not null)
- {
- Result musicBrainzTrackIdResult = MusicBrainzId.Create(repositoryEntity.MusicBrainzTrackId.Value);
- if (musicBrainzTrackIdResult.IsFailure)
- return musicBrainzTrackIdResult.Errors;
- musicBrainzTrackId = musicBrainzTrackIdResult.Value;
- }
+ musicBrainzTrackId = MusicBrainzId.Create(repositoryEntity.MusicBrainzTrackId.Value);
Optional musicBrainzWorkId = Optional.None();
if (repositoryEntity.MusicBrainzWorkId is not null)
+ musicBrainzWorkId = MusicBrainzId.Create(repositoryEntity.MusicBrainzWorkId.Value);
+
+ List domainMoods = [];
+ foreach (Result moodResult in repositoryEntity.Moods.ToDomainEntities())
{
- Result 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 domainIsrcs = [];
@@ -122,14 +115,6 @@ public static class TrackEntityMapping
domainIsrcs.Add(isrcResult.Value);
}
- List domainMoods = [];
- foreach (Result moodResult in repositoryEntity.Moods.ToDomainEntities())
- {
- if (moodResult.IsFailure)
- return moodResult.Errors;
- domainMoods.Add(moodResult.Value);
- }
-
List domainRatings = [];
foreach (Result ratingResult in repositoryEntity.Ratings.ToDomainEntities())
{
@@ -153,17 +138,19 @@ public static class TrackEntityMapping
metadataResult.Value,
repositoryEntity.TrackNumber,
Optional.FromNullable(repositoryEntity.DiscNumber),
- domainIsrcs,
+ domainMoods,
Optional.FromNullable(repositoryEntity.Script),
Optional.FromNullable(repositoryEntity.Key),
Optional.FromNullable(repositoryEntity.Bpm),
- domainMoods,
+ domainIsrcs,
Optional.FromNullable(repositoryEntity.Work),
musicBrainzRecordingId,
musicBrainzTrackId,
musicBrainzWorkId,
domainContributors,
- domainRatings);
+ domainRatings,
+ repositoryEntity.CreatedOnUtc,
+ Optional.FromNullable(repositoryEntity.UpdatedOnUtc));
}
///
@@ -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()]);
}
///
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackMapping.cs
index 3447be59..087d386a 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackMapping.cs
@@ -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
};
}
}
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/UpdateTrackCommandMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/UpdateTrackCommandMapping.cs
index f900a9cf..ee4d7bda 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/UpdateTrackCommandMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/UpdateTrackCommandMapping.cs
@@ -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> domainMoodsResult = (command.Moods ?? []).ToDomainEntities();
+ List errors = [.. domainMoodsResult.Where(moodResult => moodResult.IsFailure).SelectMany(moodResult => moodResult.Errors)];
+ if (errors.Count > 0)
+ return errors;
+
+ IEnumerable> domainIsrcsResult = (command.Isrcs ?? []).ToDomainEntities();
+ errors = [.. domainIsrcsResult.Where(isrcResult => isrcResult.IsFailure).SelectMany(isrcResult => isrcResult.Errors)];
+ if (errors.Count > 0)
+ return errors;
+
IEnumerable> domainContributorsResult = command.Contributors!.ToMusicDomainEntities();
- List 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 musicBrainzRecordingId = Optional.None();
if (command.MusicBrainzRecordingId is not null)
- {
- Result musicBrainzRecordingIdResult = MusicBrainzId.Create(command.MusicBrainzRecordingId.Value);
- if (musicBrainzRecordingIdResult.IsFailure)
- return musicBrainzRecordingIdResult.Errors;
- musicBrainzRecordingId = musicBrainzRecordingIdResult.Value;
- }
+ musicBrainzRecordingId = MusicBrainzId.Create(command.MusicBrainzRecordingId.Value);
Optional musicBrainzTrackId = Optional.None();
if (command.MusicBrainzTrackId is not null)
- {
- Result musicBrainzTrackIdResult = MusicBrainzId.Create(command.MusicBrainzTrackId.Value);
- if (musicBrainzTrackIdResult.IsFailure)
- return musicBrainzTrackIdResult.Errors;
- musicBrainzTrackId = musicBrainzTrackIdResult.Value;
- }
+ musicBrainzTrackId = MusicBrainzId.Create(command.MusicBrainzTrackId.Value);
Optional musicBrainzWorkId = Optional.None();
if (command.MusicBrainzWorkId is not null)
- {
- Result musicBrainzWorkIdResult = MusicBrainzId.Create(command.MusicBrainzWorkId.Value);
- if (musicBrainzWorkIdResult.IsFailure)
- return musicBrainzWorkIdResult.Errors;
- musicBrainzWorkId = musicBrainzWorkIdResult.Value;
- }
+ musicBrainzWorkId = MusicBrainzId.Create(command.MusicBrainzWorkId.Value);
- List domainIsrcs = [];
- foreach (IsrcDto isrc in command.Isrcs ?? [])
- {
- Result isrcResult = isrc.ToDomainEntity();
- if (isrcResult.IsFailure)
- return isrcResult.Errors;
- domainIsrcs.Add(isrcResult.Value);
- }
-
- List domainMoods = [];
- foreach (MoodDto mood in command.Moods ?? [])
- {
- Result 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 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.FromNullable(command.DiscNumber),
Optional.FromNullable(command.Script),
Optional.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;
diff --git a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/UpdateTrackRequestMapping.cs b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/UpdateTrackRequestMapping.cs
index 61f61a89..3635ccf8 100644
--- a/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/UpdateTrackRequestMapping.cs
+++ b/src/Lumina.Application/Common/Mapping/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/UpdateTrackRequestMapping.cs
@@ -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);
}
}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/AddTrack/AddTrackCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/AddTrack/AddTrackCommandHandler.cs
index 412a2023..6b1268bb 100644
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/AddTrack/AddTrackCommandHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/AddTrack/AddTrackCommandHandler.cs
@@ -96,12 +96,14 @@ public class AddTrackCommandHandler : ICommandHandler 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(
@@ -109,6 +111,10 @@ public class AddTrackCommandHandler : ICommandHandler 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 getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(libraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsFailure)
@@ -135,7 +141,11 @@ public class AddTrackCommandHandler : ICommandHandler createTrackResult = command.ToDomainEntity();
if (createTrackResult.IsFailure)
return createTrackResult.Errors;
- Result 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 addTrackResult = artistResult.Value.AddTrackToAlbum(domainAlbum, createTrackResult.Value);
if (addTrackResult.IsFailure)
return addTrackResult.Errors;
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/AddTrack/AddTrackCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/AddTrack/AddTrackCommandValidator.cs
index c71c4d22..265649e1 100644
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/AddTrack/AddTrackCommandValidator.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/AddTrack/AddTrackCommandValidator.cs
@@ -192,6 +192,7 @@ public class AddTrackCommandValidator : AbstractValidator
.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
.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
.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()
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/DeleteTrack/DeleteTrackCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/DeleteTrack/DeleteTrackCommandHandler.cs
index 46a9f1d4..8237a549 100644
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/DeleteTrack/DeleteTrackCommandHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/DeleteTrack/DeleteTrackCommandHandler.cs
@@ -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 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(
@@ -96,6 +91,13 @@ public class DeleteTrackCommandHandler : ICommandHandler 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 getLibraryResult = await _unitOfWork.LibraryRepository
.GetByIdAsync(libraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
@@ -109,14 +111,21 @@ public class DeleteTrackCommandHandler : ICommandHandler artistResult = existingArtist.ToDomainEntity();
if (artistResult.IsFailure)
return artistResult.Errors;
- Result 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 removeTrackResult = artistResult.Value.RemoveTrackFromAlbum(domainAlbum, domainTrack);
if (removeTrackResult.IsFailure)
return removeTrackResult.Errors;
- Result updateResult = await _unitOfWork.ArtistRepository
- .UpdateAsync(artistResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
+ Result updateResult = await _unitOfWork.ArtistRepository.UpdateAsync(artistResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
if (updateResult.IsFailure)
return updateResult.Errors;
+
Result saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
if (saveChangesResult.IsFailure)
return saveChangesResult.Errors;
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/UpdateTrack/UpdateTrackCommand.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/UpdateTrack/UpdateTrackCommand.cs
index 81a5b698..2f67a920 100644
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/UpdateTrack/UpdateTrackCommand.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/UpdateTrack/UpdateTrackCommand.cs
@@ -30,10 +30,10 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.
/// The MusicBrainz identifier of the recording, if applicable.
/// The MusicBrainz identifier of the track, if applicable.
/// The MusicBrainz identifier of the work, if applicable.
-/// The list of media contributors that performed on the track.
-/// The list of ratings for this track.
/// The list of moods of the track.
/// The list of ISRC of the track.
+/// The list of media contributors that performed on the track.
+/// The list of ratings for this track.
[DebuggerDisplay("Title: {Metadata.Title}")]
public record UpdateTrackCommand(
string? LibraryId,
@@ -51,8 +51,8 @@ public record UpdateTrackCommand(
Guid? MusicBrainzRecordingId,
Guid? MusicBrainzTrackId,
Guid? MusicBrainzWorkId,
- List? Contributors,
- List? Ratings,
List? Moods,
- List? Isrcs
+ List? Isrcs,
+ List? Contributors,
+ List? Ratings
) : ICommand;
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/UpdateTrack/UpdateTrackCommandHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/UpdateTrack/UpdateTrackCommandHandler.cs
index 595467f3..bced0f6d 100644
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/UpdateTrack/UpdateTrackCommandHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/UpdateTrack/UpdateTrackCommandHandler.cs
@@ -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 _validator;
+ private readonly IPathService _pathService;
///
/// Initializes a new instance of the class.
@@ -53,12 +57,14 @@ public class UpdateTrackCommandHandler : ICommandHandlerInjected service for authorization related functionality.
/// Injected service to retrieve the current user information.
/// Injected validator for application validation rules.
- public UpdateTrackCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator validator)
+ /// Injected service for file system path related functionality.
+ public UpdateTrackCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator validator, IPathService pathService)
{
_unitOfWork = unitOfWork;
_authorizationService = authorizationService;
_currentUserService = currentUserService;
_validator = validator;
+ _pathService = pathService;
}
///
@@ -92,15 +98,14 @@ public class UpdateTrackCommandHandler : ICommandHandler 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(
@@ -108,6 +113,13 @@ public class UpdateTrackCommandHandler : ICommandHandler 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 getLibraryResult = await _unitOfWork.LibraryRepository.GetByIdAsync(libraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
if (getLibraryResult.IsFailure)
@@ -115,8 +127,18 @@ public class UpdateTrackCommandHandler : ICommandHandler> 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 artistResult = existingArtist.ToDomainEntity();
if (artistResult.IsFailure)
return artistResult.Errors;
@@ -141,4 +163,49 @@ public class UpdateTrackCommandHandler : ICommandHandler
+ /// Determines whether the track path referenced by is stored inside one of the content locations of .
+ ///
+ /// The media library that owns the track.
+ /// The command carrying the referenced track.
+ /// when the referenced track path is within a content location of the library; otherwise, .
+ private bool AreTrackPathsWithinLibraryContentLocations(LibraryEntity library, UpdateTrackCommand command)
+ {
+ return library.ContentLocations.Any(contentLocation => _pathService.IsPathWithin(command.Path!, contentLocation.Path));
+ }
+
+ ///
+ /// Gets the media contributors referenced by , requiring each referenced Id to already exist.
+ ///
+ /// The command carrying the referenced media contributors.
+ /// Cancellation token that can be used to stop the execution.
+ ///
+ /// An containing either the existing media contributors, or an error when at least one referenced contributor does not exist.
+ ///
+ private async Task>> GetExistingContributorsAsync(UpdateTrackCommand command, CancellationToken cancellationToken)
+ {
+ List contributorIds = [.. CollectContributorIds(command).Distinct()];
+ if (contributorIds.Count == 0)
+ return Result.From>([]);
+
+ Result> 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);
+ }
+
+ ///
+ /// Collects the unique identifiers of every media contributor referenced by .
+ ///
+ /// The command carrying the referenced media contributors.
+ /// The collected media contributor identifiers.
+ private static IEnumerable CollectContributorIds(UpdateTrackCommand command)
+ {
+ foreach (MediaContributorReferenceDto contributor in command.Contributors!)
+ yield return contributor.ContributorId;
+ }
}
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/UpdateTrack/UpdateTrackCommandValidator.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/UpdateTrack/UpdateTrackCommandValidator.cs
index d828d747..0ebf84e5 100644
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/UpdateTrack/UpdateTrackCommandValidator.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Commands/UpdateTrack/UpdateTrackCommandValidator.cs
@@ -202,6 +202,7 @@ public class UpdateTrackCommandValidator : AbstractValidator
.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
.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
.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()
diff --git a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Queries/GetTrack/GetTrackQueryHandler.cs b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Queries/GetTrack/GetTrackQueryHandler.cs
index 2abcea22..f74fad1f 100644
--- a/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Queries/GetTrack/GetTrackQueryHandler.cs
+++ b/src/Lumina.Application/Core/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/Queries/GetTrack/GetTrackQueryHandler.cs
@@ -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 getTrackResult = await _unitOfWork.TrackRepository.GetByIdAsync(trackId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
if (getTrackResult.IsFailure)
diff --git a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/UpdateTrackRequest.cs b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/UpdateTrackRequest.cs
index e97bf005..3a65a285 100644
--- a/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/UpdateTrackRequest.cs
+++ b/src/Lumina.Contracts/Requests/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/UpdateTrackRequest.cs
@@ -25,10 +25,10 @@ namespace Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Track
/// The MusicBrainz identifier of the recording. Optional.
/// The MusicBrainz identifier of the track. Optional.
/// The MusicBrainz identifier of the work. Optional.
-/// The list of media contributors that performed on the track. Required.
-/// The list of ratings for this track. Required.
/// The list of moods of the track. Optional.
/// The list of ISRC (International Standard Recording Code) of the track. Optional.
+/// The list of media contributors that performed on the track. Required.
+/// The list of ratings for this track. Required.
[DebuggerDisplay("Title: {Metadata.Title}")]
public record UpdateTrackRequest(
string? Path,
@@ -42,8 +42,8 @@ public record UpdateTrackRequest(
Guid? MusicBrainzRecordingId,
Guid? MusicBrainzTrackId,
Guid? MusicBrainzWorkId,
- List? Contributors,
- List? Ratings,
List? Moods,
- List? Isrcs
+ List? Isrcs,
+ List? Contributors,
+ List? Ratings
);
diff --git a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackResponse.cs b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackResponse.cs
index 347b46e2..72fd1ddb 100644
--- a/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackResponse.cs
+++ b/src/Lumina.Contracts/Responses/MediaLibrary/AudioLibrary/MusicLibrary/Tracks/TrackResponse.cs
@@ -30,10 +30,10 @@ namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Trac
/// The MusicBrainz identifier of the work, if applicable.
/// The date and time when the track was created.
/// The optional date and time when the track was updated.
-/// The list of references to the media contributors that performed on the track, each with the role they played.
-/// The list of ratings for this track.
/// The list of moods of the track.
/// The list of ISRC (International Standard Recording Code) of the track.
+/// The list of references to the media contributors that performed on the track, each with the role they played.
+/// The list of ratings for this track.
[DebuggerDisplay("Title: {Metadata.Title}")]
public record TrackResponse(
Guid Id,
@@ -52,8 +52,8 @@ public record TrackResponse(
Guid? MusicBrainzWorkId,
DateTime CreatedOnUtc,
DateTime? UpdatedOnUtc,
- List? Contributors,
- List? Ratings,
List? Moods,
- List? Isrcs
+ List? Isrcs,
+ List? Contributors,
+ List? Ratings
);
diff --git a/src/Lumina.DataAccess/Common/Configuration/TrackConfiguration.cs b/src/Lumina.DataAccess/Common/Configuration/TrackConfiguration.cs
index c96b0d1a..c32b2194 100644
--- a/src/Lumina.DataAccess/Common/Configuration/TrackConfiguration.cs
+++ b/src/Lumina.DataAccess/Common/Configuration/TrackConfiguration.cs
@@ -157,37 +157,6 @@ public class TrackConfiguration : IEntityTypeConfiguration
j.ToTable("TrackGenres");
});
- builder.OwnsMany(track => track.Ratings, ratingBuilder =>
- {
- ratingBuilder.ToTable("TrackRatings");
- ratingBuilder.WithOwner()
- .HasForeignKey("TrackId");
- ratingBuilder.Property("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()
- .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
.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("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()
+ .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
diff --git a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/TrackRepository.cs b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/TrackRepository.cs
index b993837f..6b39c2f7 100644
--- a/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/TrackRepository.cs
+++ b/src/Lumina.DataAccess/Core/Repositories/MusicLibrary/TrackRepository.cs
@@ -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> 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;
}
+ ///
+ /// Gets the subset of that is already used by a track of the library identified by .
+ ///
+ /// The Id of the library whose tracks are searched.
+ /// The track paths to check.
+ /// Cancellation token that can be used to stop the execution.
+ /// An containing either the paths that are already used, or an error.
+ public async Task>> GetExistingPathsAsync(Guid libraryId, IReadOnlyCollection paths, CancellationToken cancellationToken)
+ {
+ if (paths.Count == 0)
+ return Result.From>([]);
+
+ // The stored paths are compared ordinally, matching the case sensitive comparison used by the unique index of the storage medium.
+ List distinctPaths = [.. paths.Distinct(StringComparer.Ordinal)];
+ List existingPaths = await _luminaDbContext.Tracks
+ .Where(repositoryTrack => repositoryTrack.LibraryId == libraryId && distinctPaths.Contains(repositoryTrack.Path))
+ .Select(repositoryTrack => repositoryTrack.Path)
+ .ToListAsync(cancellationToken).ConfigureAwait(false);
+ return Result.From>(existingPaths);
+ }
+
///
/// 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.
///
diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/Entities/Track.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/Entities/Track.cs
index d5995c5d..d7c418b8 100644
--- a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/Entities/Track.cs
+++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/Entities/Track.cs
@@ -19,8 +19,8 @@ namespace Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLib
[DebuggerDisplay("{Id}: {Metadata.Title}")]
public sealed class Track : Entity
{
- private readonly List _isrcs;
private readonly List _moods;
+ private readonly List _isrcs;
private readonly List _contributors;
private readonly List _ratings;
@@ -107,42 +107,46 @@ public sealed class Track : Entity
/// The audio metadata of the track.
/// The number of the track on its disc.
/// The optional number of the disc the track belongs to.
- /// The list of ISRC of the track.
+ /// The list of moods of the track.
/// The optional script used by the language of the track.
/// The optional musical key of the track.
/// The optional tempo of the track in beats per minute.
- /// The list of moods of the track.
+ /// The list of ISRC of the track.
/// The optional title of the work the track is a recording of.
/// The optional MusicBrainz identifier of the recording.
/// The optional MusicBrainz identifier of the track.
/// The optional MusicBrainz identifier of the work.
/// The list of the media contributors of the track.
/// The list of ratings for the track.
+ /// The date and time when the entity was created.
+ /// The date and time when the entity was last updated.
private Track(
TrackId id,
string path,
AudioMetadata metadata,
int trackNumber,
Optional discNumber,
- List isrcs,
+ List moods,
Optional script,
Optional key,
Optional bpm,
- List moods,
+ List isrcs,
Optional work,
Optional musicBrainzRecordingId,
Optional musicBrainzTrackId,
Optional musicBrainzWorkId,
List contributors,
- List ratings) : base(id)
+ List ratings,
+ DateTime createdOnUtc,
+ Optional 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
MusicBrainzWorkId = musicBrainzWorkId;
_contributors = contributors;
_ratings = ratings;
+ CreatedOnUtc = createdOnUtc;
+ UpdatedOnUtc = updatedOnUtc;
}
///
@@ -161,11 +167,11 @@ public sealed class Track : Entity
/// The audio metadata of the track.
/// The number of the track on its disc.
/// The optional number of the disc the track belongs to.
- /// The list of ISRC of the track.
+ /// The list of moods of the track.
/// The optional script used by the language of the track.
/// The optional musical key of the track.
/// The optional tempo of the track in beats per minute.
- /// The list of moods of the track.
+ /// The list of ISRC of the track.
/// The optional title of the work the track is a recording of.
/// The optional MusicBrainz identifier of the recording.
/// The optional MusicBrainz identifier of the track.
@@ -180,11 +186,11 @@ public sealed class Track : Entity
AudioMetadata metadata,
int trackNumber,
Optional discNumber,
- List isrcs,
+ List moods,
Optional script,
Optional key,
Optional bpm,
- List moods,
+ List isrcs,
Optional work,
Optional musicBrainzRecordingId,
Optional musicBrainzTrackId,
@@ -198,17 +204,19 @@ public sealed class Track : Entity
metadata,
trackNumber,
discNumber,
- isrcs,
+ moods,
script,
key,
bpm,
- moods,
+ isrcs,
work,
musicBrainzRecordingId,
musicBrainzTrackId,
musicBrainzWorkId,
contributors,
- ratings);
+ ratings,
+ DateTime.UtcNow, // TODO: should be IDateTimeProvider
+ Optional.None());
}
///
@@ -219,17 +227,19 @@ public sealed class Track : Entity
/// The audio metadata of the track.
/// The number of the track on its disc.
/// The optional number of the disc the track belongs to.
- /// The list of ISRC of the track.
+ /// The list of moods of the track.
/// The optional script used by the language of the track.
/// The optional musical key of the track.
/// The optional tempo of the track in beats per minute.
- /// The list of moods of the track.
+ /// The list of ISRC of the track.
/// The optional title of the work the track is a recording of.
/// The optional MusicBrainz identifier of the recording.
/// The optional MusicBrainz identifier of the track.
/// The optional MusicBrainz identifier of the work.
/// The list of the media contributors of the track.
/// The list of ratings for the track.
+ /// The date and time when the entity was created.
+ /// The date and time when the entity was last updated.
///
/// An containing either a successfully created , or an error message.
///
@@ -239,17 +249,19 @@ public sealed class Track : Entity
AudioMetadata metadata,
int trackNumber,
Optional discNumber,
- List isrcs,
+ List moods,
Optional script,
Optional key,
Optional bpm,
- List moods,
+ List isrcs,
Optional work,
Optional musicBrainzRecordingId,
Optional musicBrainzTrackId,
Optional musicBrainzWorkId,
List contributors,
- List ratings)
+ List ratings,
+ DateTime createdOnUtc,
+ Optional updatedOnUtc)
{
return new Track(
id,
@@ -257,39 +269,19 @@ public sealed class Track : Entity
metadata,
trackNumber,
discNumber,
- isrcs,
+ moods,
script,
key,
bpm,
- moods,
+ isrcs,
work,
musicBrainzRecordingId,
musicBrainzTrackId,
musicBrainzWorkId,
contributors,
- ratings);
- }
-
- ///
- /// Replaces the media contributors of the track with the provided .
- ///
- /// The media contributors of the track.
- internal void UpdateContributors(IReadOnlyCollection contributors)
- {
- // replace the contents of the collection in place, preserving the readonly reference invariants of the entity
- _contributors.Clear();
- _contributors.AddRange(contributors);
- }
-
- ///
- /// Replaces the ratings of the track with the provided .
- ///
- /// The ratings of the track.
- internal void UpdateRatings(IReadOnlyCollection 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);
}
///
@@ -314,6 +306,28 @@ public sealed class Track : Entity
_isrcs.AddRange(isrcs);
}
+ ///
+ /// Replaces the media contributors of the track with the provided .
+ ///
+ /// The media contributors of the track.
+ internal void UpdateContributors(IReadOnlyCollection contributors)
+ {
+ // replace the contents of the collection in place, preserving the readonly reference invariants of the entity
+ _contributors.Clear();
+ _contributors.AddRange(contributors);
+ }
+
+ ///
+ /// Replaces the ratings of the track with the provided .
+ ///
+ /// The ratings of the track.
+ internal void UpdateRatings(IReadOnlyCollection ratings)
+ {
+ // replace the contents of the collection in place, preserving the readonly reference invariants of the entity
+ _ratings.Clear();
+ _ratings.AddRange(ratings);
+ }
+
///
/// Updates the details of the track, without touching the moods, the ISRCs, the media contributors, and the ratings.
///
@@ -353,7 +367,7 @@ public sealed class Track : Entity
MusicBrainzRecordingId = musicBrainzRecordingId;
MusicBrainzTrackId = musicBrainzTrackId;
MusicBrainzWorkId = musicBrainzWorkId;
- UpdatedOnUtc = DateTime.UtcNow;
+ UpdatedOnUtc = Optional.Some(DateTime.UtcNow);
return Result.Updated;
}
}
diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/Barcode.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/Barcode.cs
index 82282edd..83bdc2eb 100644
--- a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/Barcode.cs
+++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/Barcode.cs
@@ -38,7 +38,7 @@ public sealed class Barcode : ValueObject
///
/// An containing either a successfully created , or an error message.
///
- public static Result Create(string? value)
+ public static Result Create(string value)
{
if (string.IsNullOrWhiteSpace(value))
return Errors.Music.BarcodeValueCannotBeEmpty;
diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/Isrc.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/Isrc.cs
index 7fe8c356..2c87c0be 100644
--- a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/Isrc.cs
+++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/Isrc.cs
@@ -38,7 +38,7 @@ public sealed class Isrc : ValueObject
///
/// An containing either a successfully created , or an error message.
///
- public static Result Create(string? value)
+ public static Result Create(string value)
{
if (string.IsNullOrWhiteSpace(value))
return Errors.Music.IsrcValueCannotBeEmpty;
diff --git a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicBrainzId.cs b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicBrainzId.cs
index 0663c63c..fc5ea56e 100644
--- a/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicBrainzId.cs
+++ b/src/Lumina.Domain/Core/BoundedContexts/AudioLibraryBoundedContext/MusicLibraryAggregate/ValueObjects/MusicBrainzId.cs
@@ -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
///
/// The value used to create the instance.
/// The created instance.
- public static Result Create(Guid value)
+ public static MusicBrainzId Create(Guid value)
{
- if (value == Guid.Empty)
- return Errors.Music.MusicBrainzIdInvalidFormat;
-
return new MusicBrainzId(value);
}
- ///
- /// Creates a new instance of the class, from a .
- ///
- /// The value used to create the instance.
- ///
- /// An containing either a successfully created , or an error message.
- ///
- public static Result 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);
- }
-
///
/// Gets the list of items that define equality of the object.
///
diff --git a/src/Lumina.Presentation.Api/Common/Routes/Library/AudioLibrary/MusicLibrary/ApiRoutes.Tracks.cs b/src/Lumina.Presentation.Api/Common/Routes/Library/AudioLibrary/MusicLibrary/ApiRoutes.Tracks.cs
index dc7e6ed3..b17a5043 100644
--- a/src/Lumina.Presentation.Api/Common/Routes/Library/AudioLibrary/MusicLibrary/ApiRoutes.Tracks.cs
+++ b/src/Lumina.Presentation.Api/Common/Routes/Library/AudioLibrary/MusicLibrary/ApiRoutes.Tracks.cs
@@ -10,6 +10,7 @@ public static partial class ApiRoutes
///
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}";
diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/AddTrack/AddTrackEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/AddTrack/AddTrackEndpoint.cs
index 03cc56c9..cefe1abf 100644
--- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/AddTrack/AddTrackEndpoint.cs
+++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/AddTrack/AddTrackEndpoint.cs
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.AddTrack;
///
-/// API endpoint for the /{libraryId}/artists/{artistId}/albums/{albumId}/tracks route.
+/// API endpoint for the /libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks route.
///
public class AddTrackEndpoint : BaseEndpoint
{
@@ -36,7 +36,7 @@ public class AddTrackEndpoint : BaseEndpoint
public override void Configure()
{
Verbs(FastEndpoints.Http.POST);
- Routes(ApiRoutes.Albums.ADD_TRACK);
+ Routes(ApiRoutes.Tracks.ADD_TRACK);
Version(1);
DontCatchExceptions();
}
diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/AddTrack/AddTrackEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/AddTrack/AddTrackEndpointSummary.cs
index a9748bc2..4ac2fba7 100644
--- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/AddTrack/AddTrackEndpointSummary.cs
+++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/AddTrack/AddTrackEndpointSummary.cs
@@ -28,7 +28,7 @@ public class AddTrackEndpointSummary : Summary 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 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 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(r => r.Id, "The Id of the track.");
ResponseParam(r => r.AlbumId, "The Id of the album the track belongs to.");
@@ -177,6 +177,8 @@ public class AddTrackEndpointSummary : Summary(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
ResponseParam(r => r.CreatedOnUtc, "The date and time when the track was created.");
ResponseParam(r => r.UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
+ ResponseParam(r => r.Moods, "The list of moods of the track.");
+ ResponseParam(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
ResponseParam(r => r.Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
ResponseParam(r => r.Ratings, "The list of ratings for this track.");
ResponseParam(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
@@ -199,8 +201,6 @@ public class AddTrackEndpointSummary : Summary(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track, if applicable.");
ResponseParam(r => r.Metadata!.Genres, "The list of genres associated with the track.");
ResponseParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track.");
- ResponseParam(r => r.Moods, "The list of moods of the track.");
- ResponseParam(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
-/// API endpoint for the /artists/{artistId}/albums/{albumId}/tracks/{trackId} route.
+/// API endpoint for the /libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId} route.
///
public class GetTrackEndpoint : BaseEndpoint
{
diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/GetTrack/GetTrackEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/GetTrack/GetTrackEndpointSummary.cs
index 423fbce9..2df68fd7 100644
--- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/GetTrack/GetTrackEndpointSummary.cs
+++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/GetTrack/GetTrackEndpointSummary.cs
@@ -47,6 +47,8 @@ public class GetTrackEndpointSummary : Summary
ResponseParam(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
ResponseParam(r => r.CreatedOnUtc, "The date and time when the track was created.");
ResponseParam(r => r.UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
+ ResponseParam(r => r.Moods, "The list of moods of the track.");
+ ResponseParam(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
ResponseParam(r => r.Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
ResponseParam(r => r.Ratings, "The list of ratings for this track.");
ResponseParam(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
@@ -69,8 +71,6 @@ public class GetTrackEndpointSummary : Summary
ResponseParam(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track, if applicable.");
ResponseParam(r => r.Metadata!.Genres, "The list of genres associated with the track.");
ResponseParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track.");
- ResponseParam(r => r.Moods, "The list of moods of the track.");
- ResponseParam(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
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
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
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
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
}
);
- 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
{
"General.Validation", new[]
{
+ "LibraryIdCannotBeEmpty",
+ "ArtistIdCannotBeEmpty",
+ "AlbumIdCannotBeEmpty",
"TrackIdCannotBeEmpty"
}
}
diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/UpdateTrack/UpdateTrackEndpoint.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/UpdateTrack/UpdateTrackEndpoint.cs
index ddd441b2..5bc92f14 100644
--- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/UpdateTrack/UpdateTrackEndpoint.cs
+++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/UpdateTrack/UpdateTrackEndpoint.cs
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.UpdateTrack;
///
-/// API endpoint for the /{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId} route.
+/// API endpoint for the /libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId} route.
///
public class UpdateTrackEndpoint : BaseEndpoint
{
diff --git a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/UpdateTrack/UpdateTrackEndpointSummary.cs b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/UpdateTrack/UpdateTrackEndpointSummary.cs
index 870bc3dc..300f67a3 100644
--- a/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/UpdateTrack/UpdateTrackEndpointSummary.cs
+++ b/src/Lumina.Presentation.Api/Core/Endpoints/Library/AudioLibrary/MusicLibrary/Tracks/UpdateTrack/UpdateTrackEndpointSummary.cs
@@ -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 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 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 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(r => r.Id, "The Id of the track.");
ResponseParam(r => r.AlbumId, "The Id of the album the track belongs to.");
@@ -177,6 +177,8 @@ public class UpdateTrackEndpointSummary : Summary(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
ResponseParam(r => r.CreatedOnUtc, "The date and time when the track was created.");
ResponseParam(r => r.UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
+ ResponseParam(r => r.Moods, "The list of moods of the track.");
+ ResponseParam(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
ResponseParam(r => r.Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
ResponseParam(r => r.Ratings, "The list of ratings for this track.");
ResponseParam(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
@@ -199,8 +201,6 @@ public class UpdateTrackEndpointSummary : Summary(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track, if applicable.");
ResponseParam(r => r.Metadata!.Genres, "The list of genres associated with the track.");
ResponseParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track.");
- ResponseParam(r => r.Moods, "The list of moods of the track.");
- ResponseParam(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