mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Merge pull request #288 from BinaryAlley/feature/add-music-deletion-and-restore
Adds deletion and restore for music library items
This commit is contained in:
224 files changed
+22384
-1360
No files matched your search
@@ -68,7 +68,7 @@ Book libraries track consumption progress by default. Reopening a book continues
|
||||
|
||||
## Browsing your music
|
||||
|
||||
Opening a music library shows a page with the library title, a search box, a sort toggle, a count of items, a grid of artist cards, an alphabetical picker down the side, and pagination at the bottom.
|
||||
Opening a music library shows a page with the library title, a search box, a sort toggle, a count of items, a **Deleted items** button, a grid of artist cards, an alphabetical picker down the side, and pagination at the bottom.
|
||||
|
||||
- **Search** filters the artists by name; press Enter or use the search button.
|
||||
- **Sort** toggles between ascending and descending order.
|
||||
@@ -77,7 +77,9 @@ Opening a music library shows a page with the library title, a search box, a sor
|
||||
|
||||
Each artist is a card; selecting it opens the artist's page, and the card's actions menu offers **View details**, **Play**, **Shuffle**, **Add to playlist** and **Delete**. The heart on the card marks the artist as a favorite.
|
||||
|
||||
The artist page is also where you edit the artist. It lists the artist's albums as cards, each leading to its own album page, followed by the artist's general information, contributors, ratings, genres, tags, aliases, areas and identifiers. The album page holds the album's information and its tracks, and the track page holds the track's details. The album page also shows the artwork Lumina stored for the album as a strip of thumbnails beside the main image, and selecting a thumbnail displays that image in place of the cover. Deleting an artist, album or track removes it from Lumina's catalogue; your files are not touched.
|
||||
The artist page is also where you edit the artist. It lists the artist's albums as cards, each leading to its own album page, followed by the artist's general information, contributors, ratings, genres, tags, aliases, areas and identifiers. The album page holds the album's information and its tracks, and the track page holds the track's details. The album page also shows the artwork Lumina stored for the album as a strip of thumbnails beside the main image, and selecting a thumbnail displays that image in place of the cover.
|
||||
|
||||
Deleting an artist, album or track asks for confirmation and moves it to the library's **Deleted items**, together with the metadata and artwork Lumina stored for it. The file behind it is left untouched. The item stops appearing in the library, and an automatic scan does not add it back. An artist always keeps at least one album, so the last album of an artist cannot be deleted. If a file is later removed from disk, the next scan permanently removes the deleted track, including its stored artwork, and the albums and artists left with no files, including their stored artwork. The **Deleted items** button on the artists page lists the deleted artists, albums and tracks, and restores one when you select **Restore**. Restoring an artist or an album brings back the items inside it that were not deleted on their own.
|
||||
|
||||
The music pages also play what they show. The artist page has a **Play all** control that plays the artist's releases in the order the page presents them, one release after another. The actions menu of a music library card on the home page, of an artist card, and of an album card offers **Play** and **Shuffle**. Play starts the library at its first artist and continues through the remaining artists in artist page order, starts the artist's discography in the order the artist page presents it, or starts the release in disc and track order. Shuffle starts the library, the artist's discography or the release with a list of up to 100 tracks sampled uniformly at random from every track of that scope, and continues in random order without repeating a track that is already queued. The album page has a **Play album** control that plays the release in disc and track order, and every track row has its own play control that plays just that track. The track page has a **Play track** control for the track it shows. Every track row on the album page also has an actions menu: **Add to playlist** opens the playlist picker for that track, **Add to play queue** appends it to the end of the player queue or starts it when the queue is empty, and **Play all from here** replaces the queue with that track and the rest of the album and starts playing. Starting playback opens the player bar at the bottom of the window. It keeps playing while you move between pages, and the bar shows the track name, with the album name underneath when the track belongs to a named album, the progress of the current track, a segmented VU meter that follows the level of the track, and the volume, together with previous, play or pause, stop, next and repeat controls. When you expand it, it also shows the cover art, the current track name, the release type, the release name and year, the artist name, and a carousel of the album's stored artwork, next to the queue, where every entry carries its album cover, including when only one track is queued. Selecting an artwork in the carousel shows it as the main cover. The expanded queue moves the current track to the top whenever playback advances, so it stays visible even in a long list. The current track's favorite is the heart on the bar between the repeat and mute controls, and every entry of the expanded queue carries its own heart. The queue's own playlist picker appends the whole queue, in order, to one of your playlists. The double chevron at the right points up to expand the bar and down to collapse it. Stop is the square control next to play or pause; in the condensed bar it stops playback and slides the bar out of view.
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ Returns the favorites of the current user, from the most recently favorited. The
|
||||
"collectionTitle": "A Night at the Opera",
|
||||
"creatorId": "d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a",
|
||||
"creatorName": "Queen",
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg"
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
},
|
||||
{
|
||||
"mediaKind": "Book",
|
||||
|
||||
@@ -27,6 +27,12 @@
|
||||
- [Get Album Tracks Lite](#get-album-tracks-lite)
|
||||
- [Get Album Tracks Lite Request](#get-album-tracks-lite-request)
|
||||
- [Get Album Tracks Lite Response](#get-album-tracks-lite-response)
|
||||
- [Get Deleted Albums](#get-deleted-albums)
|
||||
- [Get Deleted Albums Request](#get-deleted-albums-request)
|
||||
- [Get Deleted Albums Response](#get-deleted-albums-response)
|
||||
- [Restore Album](#restore-album)
|
||||
- [Restore Album Request](#restore-album-request)
|
||||
- [Restore Album Response](#restore-album-response)
|
||||
|
||||
## Album
|
||||
|
||||
@@ -531,12 +537,12 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b
|
||||
]
|
||||
}
|
||||
],
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg",
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg",
|
||||
"artwork": [
|
||||
{
|
||||
"type": "Cover",
|
||||
"ordinal": 0,
|
||||
"path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg"
|
||||
"path": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -797,12 +803,12 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
|
||||
]
|
||||
}
|
||||
],
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg",
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg",
|
||||
"artwork": [
|
||||
{
|
||||
"type": "Cover",
|
||||
"ordinal": 0,
|
||||
"path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg"
|
||||
"path": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -836,7 +842,7 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
|
||||
"id": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f",
|
||||
"title": "A Night at the Opera",
|
||||
"totalTracks": 12,
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg",
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg",
|
||||
"releaseYear": 1975,
|
||||
"releaseTypes": [ "Album" ]
|
||||
}
|
||||
@@ -1102,12 +1108,12 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
|
||||
]
|
||||
}
|
||||
],
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg",
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg",
|
||||
"artwork": [
|
||||
{
|
||||
"type": "Cover",
|
||||
"ordinal": 0,
|
||||
"path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg"
|
||||
"path": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
},
|
||||
{
|
||||
"type": "Back",
|
||||
@@ -1447,12 +1453,12 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
|
||||
]
|
||||
}
|
||||
],
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg",
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg",
|
||||
"artwork": [
|
||||
{
|
||||
"type": "Cover",
|
||||
"ordinal": 0,
|
||||
"path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg"
|
||||
"path": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1484,7 +1490,7 @@ Content-Type: image/jpeg
|
||||
|
||||
```json
|
||||
{
|
||||
"coverPath": "/media/music/music-3f2504e0-4f89-41d3-9a0c-0305e82c3301/Queen-2b0e5f5a-0b3f-4b7e-8f4a-8c9e3d2f5a6b/A Night at the Opera-7c1d2e3f-4a5b-6c7d-8e9f-0a1b2c3d4e5f/cover.jpg"
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1499,7 +1505,7 @@ DELETE api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f
|
||||
200 Ok
|
||||
```
|
||||
|
||||
Deletes the album identified by the route, together with its tracks. An artist must always keep at least one album.
|
||||
Soft deletes the album identified by the route. The stored metadata, artwork and track paths are kept, so the album can be restored, and its tracks stay reserved, so a scan does not add them back. The album is hidden until it is restored. An artist must always keep at least one album, so the last album of an artist cannot be deleted and the request fails with a forbidden problem.
|
||||
|
||||
|
||||
### Get Album Tracks
|
||||
@@ -1643,3 +1649,51 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-
|
||||
"numberOfPages": 1
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Get Deleted Albums
|
||||
|
||||
#### Get Deleted Albums Request
|
||||
|
||||
```js
|
||||
GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/albums/deleted-items
|
||||
```
|
||||
|
||||
#### Get Deleted Albums Response
|
||||
|
||||
```js
|
||||
200 Ok
|
||||
```
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
|
||||
"libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
||||
"artistId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
|
||||
"artistName": "Queen",
|
||||
"title": "A Night at the Opera",
|
||||
"deletedOnUtc": "2026-11-14T18:35:00Z",
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d/A Night at the Opera-b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e/cover.jpg"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
An album whose artist is also deleted is not returned until the artist is restored.
|
||||
|
||||
|
||||
### Restore Album
|
||||
|
||||
#### Restore Album Request
|
||||
|
||||
```js
|
||||
POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/{albumId}/restore
|
||||
```
|
||||
|
||||
#### Restore Album Response
|
||||
|
||||
```js
|
||||
200 Ok
|
||||
```
|
||||
|
||||
Restores the deleted album identified by the route, together with its stored metadata, artwork and the tracks that were not deleted on their own.
|
||||
@@ -21,6 +21,12 @@
|
||||
- [Update Artist Cover Request](#update-artist-cover-request)
|
||||
- [Update Artist Cover Response](#update-artist-cover-response)
|
||||
- [Delete Artist](#delete-artist)
|
||||
- [Get Deleted Artists](#get-deleted-artists)
|
||||
- [Get Deleted Artists Request](#get-deleted-artists-request)
|
||||
- [Get Deleted Artists Response](#get-deleted-artists-response)
|
||||
- [Restore Artist](#restore-artist)
|
||||
- [Restore Artist Request](#restore-artist-request)
|
||||
- [Restore Artist Response](#restore-artist-response)
|
||||
|
||||
## Artist
|
||||
|
||||
@@ -672,17 +678,17 @@ POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists
|
||||
]
|
||||
}
|
||||
],
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg",
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg",
|
||||
"artwork": [
|
||||
{
|
||||
"type": "Cover",
|
||||
"ordinal": 0,
|
||||
"path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg"
|
||||
"path": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/cover.jpg"
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/cover.jpg"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1021,17 +1027,17 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists?currentPage=1&
|
||||
]
|
||||
}
|
||||
],
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg",
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg",
|
||||
"artwork": [
|
||||
{
|
||||
"type": "Cover",
|
||||
"ordinal": 0,
|
||||
"path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg"
|
||||
"path": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/cover.jpg"
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/cover.jpg"
|
||||
}
|
||||
],
|
||||
"currentPage": 1,
|
||||
@@ -1072,7 +1078,7 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/lite?currentPa
|
||||
{
|
||||
"id": "d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a",
|
||||
"name": "Queen",
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/cover.jpg"
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/cover.jpg"
|
||||
}
|
||||
],
|
||||
"currentPage": 1,
|
||||
@@ -1410,17 +1416,17 @@ GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}
|
||||
]
|
||||
}
|
||||
],
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg",
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg",
|
||||
"artwork": [
|
||||
{
|
||||
"type": "Cover",
|
||||
"ordinal": 0,
|
||||
"path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg"
|
||||
"path": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/cover.jpg"
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/cover.jpg"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -2076,17 +2082,17 @@ PUT api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}
|
||||
]
|
||||
}
|
||||
],
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg",
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg",
|
||||
"artwork": [
|
||||
{
|
||||
"type": "Cover",
|
||||
"ordinal": 0,
|
||||
"path": "/media/music/Queen-3b3a19f3/A Night at the Opera-e8d52f7b/cover.jpg"
|
||||
"path": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/A Night at the Opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"coverPath": "/media/music/Queen-3b3a19f3/cover.jpg"
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/cover.jpg"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -2116,7 +2122,7 @@ Content-Type: image/jpeg
|
||||
|
||||
```json
|
||||
{
|
||||
"coverPath": "/media/music/music-3f2504e0-4f89-41d3-9a0c-0305e82c3301/Queen-2b0e5f5a-0b3f-4b7e-8f4a-8c9e3d2f5a6b/cover.jpg"
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/cover.jpg"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -2131,4 +2137,48 @@ DELETE api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}
|
||||
200 Ok
|
||||
```
|
||||
|
||||
Deletes the artist identified by the route, together with its albums and tracks.
|
||||
Soft deletes the artist identified by the route. The stored metadata, artwork, albums and tracks are kept, so the artist can be restored, and their paths stay reserved, so a scan does not add them back.
|
||||
|
||||
|
||||
### Get Deleted Artists
|
||||
|
||||
#### Get Deleted Artists Request
|
||||
|
||||
```js
|
||||
GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/deleted-items
|
||||
```
|
||||
|
||||
#### Get Deleted Artists Response
|
||||
|
||||
```js
|
||||
200 Ok
|
||||
```
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
|
||||
"libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
||||
"name": "Queen",
|
||||
"deletedOnUtc": "2026-11-14T18:35:00Z",
|
||||
"coverPath": "/media/music/music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/Queen-a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d/cover.jpg"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
### Restore Artist
|
||||
|
||||
#### Restore Artist Request
|
||||
|
||||
```js
|
||||
POST api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{artistId}/restore
|
||||
```
|
||||
|
||||
#### Restore Artist Response
|
||||
|
||||
```js
|
||||
200 Ok
|
||||
```
|
||||
|
||||
Restores the deleted artist identified by the route, together with its stored metadata, artwork and the albums and tracks that were not deleted on their own. An artist cannot be restored when a visible artist with the same name already exists in the library.
|
||||
@@ -24,6 +24,12 @@
|
||||
- [Update Track Request](#update-track-request)
|
||||
- [Update Track Response](#update-track-response)
|
||||
- [Delete Track](#delete-track)
|
||||
- [Get Deleted Tracks](#get-deleted-tracks)
|
||||
- [Get Deleted Tracks Request](#get-deleted-tracks-request)
|
||||
- [Get Deleted Tracks Response](#get-deleted-tracks-response)
|
||||
- [Restore Track](#restore-track)
|
||||
- [Restore Track Request](#restore-track-request)
|
||||
- [Restore Track Response](#restore-track-response)
|
||||
|
||||
## Track
|
||||
|
||||
@@ -360,7 +366,7 @@ Returns a uniformly random selection of tracks from every track of the library,
|
||||
"albumId": "e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f",
|
||||
"albumTitle": "A Night at the Opera",
|
||||
"artistId": "d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a",
|
||||
"coverPath": "\\media\\music\\music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a\\QUEEN\\Album\\A night at the opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f\\cover.jpg"
|
||||
"coverPath": "\\media\\music\\music-3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a\\Queen-d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a\\Album\\A night at the opera-e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f\\cover.jpg"
|
||||
}
|
||||
]
|
||||
```
|
||||
@@ -688,4 +694,54 @@ DELETE api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f
|
||||
200 Ok
|
||||
```
|
||||
|
||||
Deletes the track identified by the route.
|
||||
Soft deletes the track identified by the route. The stored metadata, artwork and file path are kept, so the track can be restored, and its path stays reserved, so a scan does not add it back.
|
||||
|
||||
|
||||
### Get Deleted Tracks
|
||||
|
||||
#### Get Deleted Tracks Request
|
||||
|
||||
```js
|
||||
GET api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/tracks/deleted-items
|
||||
```
|
||||
|
||||
#### Get Deleted Tracks Response
|
||||
|
||||
```js
|
||||
200 Ok
|
||||
```
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"id": "c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f",
|
||||
"libraryId": "3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
|
||||
"artistId": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
|
||||
"artistName": "Queen",
|
||||
"albumId": "b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
|
||||
"albumTitle": "A Night at the Opera",
|
||||
"title": "Bohemian Rhapsody",
|
||||
"path": "/music/queen/a-night-at-the-opera/01 - Bohemian Rhapsody.flac",
|
||||
"deletedOnUtc": "2026-11-14T18:35:00Z"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
A track whose album or artist is also deleted is not returned until the album and the artist are restored.
|
||||
|
||||
|
||||
### Restore Track
|
||||
|
||||
#### Restore 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/{trackId}/restore
|
||||
```
|
||||
|
||||
#### Restore Track Response
|
||||
|
||||
```js
|
||||
200 Ok
|
||||
```
|
||||
|
||||
Restores the deleted track identified by the route, together with its stored metadata and artwork.
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
GET {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/albums/deleted-items
|
||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||
@@ -0,0 +1,2 @@
|
||||
POST {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{{$guid}}/albums/{{$guid}}/restore
|
||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
GET {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/deleted-items
|
||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||
@@ -0,0 +1,2 @@
|
||||
POST {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{{$guid}}/restore
|
||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
GET {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/tracks/deleted-items
|
||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||
@@ -0,0 +1,2 @@
|
||||
POST {{host}}/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/{{$guid}}/albums/{{$guid}}/tracks/{{$guid}}/restore
|
||||
Authorization: Bearer {{ACCESS_TOKEN}}
|
||||
@@ -86,7 +86,7 @@ The manifest is a JSON object describing the theme. The example below is the man
|
||||
"name": "Editorial Paper",
|
||||
"description": "A clean, readable proof of concept theme.",
|
||||
"author": "Lumina",
|
||||
"version": "1.5.61",
|
||||
"version": "1.6.0",
|
||||
"preview": "assets/preview.svg",
|
||||
"templates": {
|
||||
"default": "templates/index.html"
|
||||
@@ -180,6 +180,7 @@ Known page keys:
|
||||
| `shared/audio-player/playlist-item` | The playlist item of the audio player bar. |
|
||||
| `library/written-content-library/book-library/books/index` | The books browsing page. |
|
||||
| `library/written-content-library/book-library/books/deleted-items` | The deleted items page of a book library, which restores deleted books. |
|
||||
| `library/audio-library/music-library/deleted-items` | The deleted items page of a music library, which restores deleted artists, albums and tracks. |
|
||||
| `playlists/index` | The page that lists and deletes the playlists of the current user. |
|
||||
| `playlists/item` | The page that creates a playlist, or edits, reorders, plays and deletes an existing playlist of the current user. The `isNew` page data field tells the two modes apart. |
|
||||
| `favorites/index` | The page that lists, filters and removes the favorites of the current user across media kinds. |
|
||||
@@ -621,6 +622,42 @@ The page script drives these hooks:
|
||||
|
||||
A theme that provides this page must keep these hooks and render the anti-forgery token, or reimplement the restore behavior itself.
|
||||
|
||||
#### The Music Deleted Items Page
|
||||
|
||||
`library/audio-library/music-library/deleted-items` lists the artists, albums and tracks that were deleted from a music library and lets the user restore them. Its fallback is `Core/Views/Library/AudioLibrary/MusicLibrary/DeletedItems.cshtml`. The bundled themes ship their own `templates/library/audio-library/music-library/deleted-items.html`; when a theme has no template for the page, the application renders the fallback view.
|
||||
|
||||
Template resolution walks up the path scopes, so a theme that ships `templates/library/audio-library/music-library.html` without a `deleted-items.html` would render that parent template for this page. A theme that provides a music library parent template must also provide the deleted items template.
|
||||
|
||||
Page data:
|
||||
|
||||
| Field | Content |
|
||||
| --- | --- |
|
||||
| `libraryId` | The Id of the library whose deleted music items are listed. |
|
||||
| `libraryTitle` | The title of that library. |
|
||||
| `deletedArtistsJson` | The deleted artists, serialized as a JSON array. Each item carries `id`, `libraryId`, `name`, `deletedOnUtc` and `coverPath`. |
|
||||
| `deletedAlbumsJson` | The deleted albums, serialized as a JSON array. Each item carries `id`, `libraryId`, `artistId`, `artistName`, `title`, `deletedOnUtc` and `coverPath`. |
|
||||
| `deletedTracksJson` | The deleted tracks, serialized as a JSON array. Each item carries `id`, `libraryId`, `artistId`, `artistName`, `albumId`, `albumTitle`, `title`, `path` and `deletedOnUtc`. |
|
||||
| `artistRestoreUrl` | The route template that restores a deleted artist. The trailing `00000000-0000-0000-0000-000000000000` is replaced by the Id of the artist, and `libraryId` is appended as a query parameter. |
|
||||
| `albumRestoreUrl` | The route template that restores a deleted album. Its two `00000000-0000-0000-0000-000000000000` segments are replaced, in order, by the Id of the artist and the Id of the album, and `libraryId` is appended as a query parameter. |
|
||||
| `trackRestoreUrl` | The route template that restores a deleted track. Its three `00000000-0000-0000-0000-000000000000` segments are replaced, in order, by the Id of the artist, the Id of the album and the Id of the track, and `libraryId` is appended as a query parameter. |
|
||||
| `backUrl` | The route of the artists page of the library. |
|
||||
| `antiforgeryToken` | The anti-forgery request token for the restore POST. |
|
||||
| `strings` | The localized strings of the page, keyed by their resource names. |
|
||||
| `stringsJson` | The same localized strings serialized as JSON, with camel case keys, for the page script. |
|
||||
|
||||
The page script drives these hooks:
|
||||
|
||||
| Hook | Purpose |
|
||||
| --- | --- |
|
||||
| `btn-back-to-library` | Returns to the artists page of the library. |
|
||||
| `deleted-artists-table`, `deleted-albums-table` and `deleted-tracks-table` | Hold the deleted artists, albums and tracks. The restore click handler is bound at the document level. |
|
||||
| `no-deleted-music-items` | The empty state, shown when no deleted music items remain. |
|
||||
| `.deleted-music-item-row` | A deleted music item row, carrying its kind in `data-row-type` and the Ids it needs to restore in `data-artist-id`, `data-album-id` and `data-track-id`. Removed after a successful restore. |
|
||||
| `.btn-restore-artist`, `.btn-restore-album` and `.btn-restore-track` | The restore button of a row, carrying the same Ids as its row. |
|
||||
| `input[name="__RequestVerificationToken"]` | The anti-forgery token that the restore POST sends. |
|
||||
|
||||
A theme that provides this page must keep these hooks and render the anti-forgery token, or reimplement the restore behavior itself. The `library/audio-library/music-library/artists/index` page supplies a `deletedItemsUrl` page data field with the route of this page, and the artists page template must also provide the `deleted-items-button` hook when it wants to link to it. The page reads the library from the `libraryId` query parameter, so a theme that links to `deletedItemsUrl` must append `?libraryId=` with the Id of the library, as the application template does; the route alone lands on the home page.
|
||||
|
||||
#### The Playlist Pages
|
||||
|
||||
`playlists/index` receives a model with the following fields:
|
||||
|
||||
+11
@@ -231,6 +231,17 @@ public class AlbumEntity : IStorageEntity, IAuditableEntity
|
||||
/// </summary>
|
||||
public string? MetadataProvider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the album was deleted by the user and is waiting to be restored or permanently removed.
|
||||
/// A deleted album is kept out of every catalogue read and is not materialized again by scans, so that an automatic scan never undoes the deletion.
|
||||
/// </summary>
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the album was deleted, or <see langword="null"/> when the album is not deleted.
|
||||
/// </summary>
|
||||
public DateTime? DeletedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
|
||||
+11
@@ -150,6 +150,17 @@ public class ArtistEntity : IStorageEntity, IAuditableEntity
|
||||
/// </summary>
|
||||
public string? MetadataProvider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the artist was deleted by the user and is waiting to be restored or permanently removed.
|
||||
/// A deleted artist is kept out of every catalogue read and is not materialized again by scans, so that an automatic scan never undoes the deletion.
|
||||
/// </summary>
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the artist was deleted, or <see langword="null"/> when the artist is not deleted.
|
||||
/// </summary>
|
||||
public DateTime? DeletedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
|
||||
+11
@@ -291,6 +291,17 @@ public class TrackEntity : IStorageEntity, IAuditableEntity
|
||||
/// </summary>
|
||||
public string? MetadataProvider { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the track was deleted by the user and is waiting to be restored or permanently removed.
|
||||
/// A deleted track is kept out of every catalogue read and is not materialized again by scans, so that an automatic scan never undoes the deletion.
|
||||
/// </summary>
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the track was deleted, or <see langword="null"/> when the track is not deleted.
|
||||
/// </summary>
|
||||
public DateTime? DeletedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
|
||||
+49
-1
@@ -24,13 +24,61 @@ public interface IAlbumRepository : IRepository<AlbumEntity>,
|
||||
IDeleteByIdRepositoryAction<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all the albums of the artist identified by <paramref name="artistId"/>.
|
||||
/// Gets the albums of the artist identified by <paramref name="artistId"/> that are not soft deleted.
|
||||
/// </summary>
|
||||
/// <param name="artistId">The Id of the artist whose albums are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="AlbumEntity"/>, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<AlbumEntity>>> GetByArtistIdAsync(Guid artistId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the albums of the artist identified by <paramref name="artistId"/>, whether they are soft deleted or not.
|
||||
/// </summary>
|
||||
/// <param name="artistId">The Id of the artist whose albums are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="AlbumEntity"/>, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<AlbumEntity>>> GetByArtistIdIncludingDeletedAsync(Guid artistId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the album identified by <paramref name="id"/>, whether it is soft deleted or not, without loading its navigation properties.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the album to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="AlbumEntity"/>, or an error.</returns>
|
||||
Task<Result<AlbumEntity?>> GetIncludingDeletedByIdAsync(Guid id, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the soft deleted album identified by <paramref name="id"/>, when its artist is not soft deleted.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the soft deleted album to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted <see cref="AlbumEntity"/>, <see langword="null"/> when the album does not exist, is not soft deleted, or its artist is soft deleted, or an error.</returns>
|
||||
Task<Result<AlbumEntity?>> GetSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the soft deleted albums of the media library identified by <paramref name="libraryId"/>, whose artist is not soft deleted.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose soft deleted albums are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted albums, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<AlbumEntity>>> GetSoftDeletedByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Soft deletes the album identified by <paramref name="id"/>, without removing its stored metadata or artwork, when another visible album of its artist remains.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the album to soft delete.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Updated>> SoftDeleteByIdAsync(Guid id, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Restores the soft deleted album identified by <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the album to restore.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Updated>> RestoreSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lightweight read models of the albums of the artist identified by <paramref name="artistId"/>, projecting only the fields needed to display the albums in a card-based grid or a list.
|
||||
/// </summary>
|
||||
|
||||
+32
@@ -86,4 +86,36 @@ public interface IArtistRepository : IRepository<ArtistEntity>,
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Deleted>> DeleteByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the soft deleted artist identified by <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the soft deleted artist to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted <see cref="ArtistEntity"/>, <see langword="null"/> when the artist does not exist or is not soft deleted, or an error.</returns>
|
||||
Task<Result<ArtistEntity?>> GetSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the soft deleted artists of the media library identified by <paramref name="libraryId"/>.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose soft deleted artists are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted artists, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<ArtistEntity>>> GetSoftDeletedByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Soft deletes the artist identified by <paramref name="id"/>, without removing its stored metadata or artwork.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the artist to soft delete.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Updated>> SoftDeleteByIdAsync(Guid id, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Restores the soft deleted artist identified by <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the artist to restore.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Updated>> RestoreSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken);
|
||||
}
|
||||
+41
-1
@@ -33,13 +33,21 @@ public interface ITrackRepository : IRepository<TrackEntity>,
|
||||
Task<Result<IReadOnlyCollection<string>>> GetExistingPathsAsync(Guid libraryId, IReadOnlyCollection<string> paths, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the tracks of the album identified by <paramref name="albumId"/>.
|
||||
/// Gets the tracks of the album identified by <paramref name="albumId"/> that are not soft deleted.
|
||||
/// </summary>
|
||||
/// <param name="albumId">The Id of the album whose tracks are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="TrackEntity"/>, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<TrackEntity>>> GetByAlbumIdAsync(Guid albumId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the tracks of the album identified by <paramref name="albumId"/>, whether they are soft deleted or not.
|
||||
/// </summary>
|
||||
/// <param name="albumId">The Id of the album whose tracks are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="TrackEntity"/>, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<TrackEntity>>> GetByAlbumIdIncludingDeletedAsync(Guid albumId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lightweight read models of the tracks of the album identified by <paramref name="albumId"/>, projecting only the fields needed to display the tracks of an album.
|
||||
/// </summary>
|
||||
@@ -146,4 +154,36 @@ public interface ITrackRepository : IRepository<TrackEntity>,
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the existing tracks, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<TrackEntity>>> GetByIdsAsync(IReadOnlyCollection<Guid> trackIds, bool shouldIncludeNavigationProperties, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the soft deleted track identified by <paramref name="id"/>, when its album and artist are not soft deleted.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the soft deleted track to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted <see cref="TrackEntity"/>, <see langword="null"/> when the track does not exist, is not soft deleted, or its album or artist is soft deleted, or an error.</returns>
|
||||
Task<Result<TrackEntity?>> GetSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the soft deleted tracks of the media library identified by <paramref name="libraryId"/>, whose album and artist are not soft deleted.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose soft deleted tracks are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted tracks, or an error.</returns>
|
||||
Task<Result<IReadOnlyList<TrackEntity>>> GetSoftDeletedByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Soft deletes the track identified by <paramref name="id"/>, without removing its stored metadata or artwork.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the track to soft delete.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Updated>> SoftDeleteByIdAsync(Guid id, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Restores the soft deleted track identified by <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the track to restore.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Updated>> RestoreSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Telemetry;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artwork;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Deletion;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -45,7 +44,6 @@ public static class ApplicationLayerServices
|
||||
|
||||
services.AddScoped<IMediaLibraryItemDeletionStrategy, BooksMediaLibraryItemDeletionStrategy>();
|
||||
services.AddScoped<IMediaLibraryItemDeletionStrategy, MusicMediaLibraryItemDeletionStrategy>();
|
||||
services.AddScoped<IMusicArtworkCleanupService, MusicArtworkCleanupService>();
|
||||
|
||||
foreach (var registration in handlerRegistrations)
|
||||
{
|
||||
|
||||
+19
@@ -228,6 +228,25 @@ public static class AlbumEntityMapping
|
||||
artwork ?? []);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="DeletedAlbumResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <param name="deletedOnUtc">The date and time when the album was deleted.</param>
|
||||
/// <param name="coverPath">The optional path of the image representing the album.</param>
|
||||
/// <returns>The converted response entity.</returns>
|
||||
public static DeletedAlbumResponse ToResponse(this AlbumEntity repositoryEntity, DateTime deletedOnUtc, string? coverPath = null)
|
||||
{
|
||||
return new DeletedAlbumResponse(
|
||||
repositoryEntity.Id,
|
||||
repositoryEntity.LibraryId,
|
||||
repositoryEntity.ArtistId,
|
||||
repositoryEntity.Artist?.Name ?? string.Empty,
|
||||
repositoryEntity.Title,
|
||||
deletedOnUtc,
|
||||
coverPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="AlbumResponse"/>.
|
||||
/// </summary>
|
||||
|
||||
+17
@@ -183,6 +183,23 @@ public static class ArtistEntityMapping
|
||||
coverPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="DeletedArtistResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <param name="deletedOnUtc">The date and time when the artist was deleted.</param>
|
||||
/// <param name="coverPath">The optional path of the image representing the artist.</param>
|
||||
/// <returns>The converted response entity.</returns>
|
||||
public static DeletedArtistResponse ToResponse(this ArtistEntity repositoryEntity, DateTime deletedOnUtc, string? coverPath = null)
|
||||
{
|
||||
return new DeletedArtistResponse(
|
||||
repositoryEntity.Id,
|
||||
repositoryEntity.LibraryId,
|
||||
repositoryEntity.Name,
|
||||
deletedOnUtc,
|
||||
coverPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="ArtistResponse"/>.
|
||||
/// </summary>
|
||||
|
||||
+20
@@ -293,6 +293,26 @@ public static class TrackEntityMapping
|
||||
repositoryEntity.Container);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="DeletedTrackResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <param name="deletedOnUtc">The date and time when the track was deleted.</param>
|
||||
/// <returns>The converted response entity.</returns>
|
||||
public static DeletedTrackResponse ToResponse(this TrackEntity repositoryEntity, DateTime deletedOnUtc)
|
||||
{
|
||||
return new DeletedTrackResponse(
|
||||
repositoryEntity.Id,
|
||||
repositoryEntity.LibraryId,
|
||||
repositoryEntity.Album?.ArtistId ?? Guid.Empty,
|
||||
repositoryEntity.Album?.Artist?.Name ?? string.Empty,
|
||||
repositoryEntity.AlbumId,
|
||||
repositoryEntity.Album?.Title ?? string.Empty,
|
||||
repositoryEntity.Title,
|
||||
repositoryEntity.Path,
|
||||
deletedOnUtc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntities"/> to a collection of <see cref="TrackResponse"/>.
|
||||
/// </summary>
|
||||
|
||||
+13
-25
@@ -8,7 +8,6 @@ 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.Artists;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artwork;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
@@ -29,7 +28,6 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.
|
||||
public class DeleteAlbumCommandHandler : ICommandHandler<DeleteAlbumCommand, Result<Deleted>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IMusicArtworkCleanupService _musicArtworkCleanupService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<DeleteAlbumCommand> _validator;
|
||||
@@ -38,14 +36,12 @@ public class DeleteAlbumCommandHandler : ICommandHandler<DeleteAlbumCommand, Res
|
||||
/// Initializes a new instance of the <see cref="DeleteAlbumCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="musicArtworkCleanupService">Injected service for removing the artwork of a music library item and of its children.</param>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public DeleteAlbumCommandHandler(IUnitOfWork unitOfWork, IMusicArtworkCleanupService musicArtworkCleanupService, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<DeleteAlbumCommand> validator)
|
||||
public DeleteAlbumCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<DeleteAlbumCommand> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_musicArtworkCleanupService = musicArtworkCleanupService;
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_validator = validator;
|
||||
@@ -74,7 +70,7 @@ public class DeleteAlbumCommandHandler : ICommandHandler<DeleteAlbumCommand, Res
|
||||
Guid artistId = Guid.Parse(command.ArtistId!);
|
||||
Guid albumId = Guid.Parse(command.AlbumId!);
|
||||
|
||||
// An album is a child of the artist aggregate, so the whole aggregate is loaded and the album is removed within it.
|
||||
// An album is a child of the artist aggregate, so the whole aggregate is loaded and the album is looked up within it.
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository
|
||||
.GetByIdAsync(artistId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getArtistResult.IsFailure)
|
||||
@@ -94,10 +90,6 @@ public class DeleteAlbumCommandHandler : ICommandHandler<DeleteAlbumCommand, Res
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
AlbumEntity? existingAlbum = existingArtist.Albums.FirstOrDefault(album => album.Id == albumId);
|
||||
if (existingAlbum is null)
|
||||
return DomainErrors.Music.AlbumNotFound;
|
||||
|
||||
// An album can only belong to a library that exists, so a client can never delete an album of a library of the host that is not there.
|
||||
Result<LibraryEntity?> getLibraryResult = await _unitOfWork.LibraryRepository
|
||||
.GetByIdAsync(libraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
@@ -106,29 +98,25 @@ public class DeleteAlbumCommandHandler : ICommandHandler<DeleteAlbumCommand, Res
|
||||
if (getLibraryResult.Value is null)
|
||||
return DomainErrors.Library.LibraryNotFound;
|
||||
|
||||
// The write path goes through the aggregate root: an album is a child entity of the artist aggregate, unlike Book and Artist,
|
||||
// which are aggregate roots and are deleted directly through their own repositories. This difference is intentional.
|
||||
Result<Artist> artistResult = existingArtist.ToDomainEntity();
|
||||
if (artistResult.IsFailure)
|
||||
return artistResult.Errors;
|
||||
// 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 DomainErrors.Music.AlbumNotFound;
|
||||
Result<Deleted> removeAlbumResult = artistResult.Value.RemoveAlbum(domainAlbum);
|
||||
if (removeAlbumResult.IsFailure)
|
||||
return removeAlbumResult.Errors;
|
||||
|
||||
// The artwork of the album and of its tracks does not cascade from the album row, because the artwork table is shared by all the music
|
||||
// library item types, so it is removed first, while the album and its tracks are still present.
|
||||
Result<Deleted> deleteArtworkResult = await _musicArtworkCleanupService.DeleteAlbumArtworkAsync(albumId, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteArtworkResult.IsFailure)
|
||||
return deleteArtworkResult.Errors;
|
||||
|
||||
Result<Updated> updateResult = await _unitOfWork.ArtistRepository
|
||||
.UpdateAsync(artistResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsFailure)
|
||||
return updateResult.Errors;
|
||||
Result<bool> canRemoveAlbumResult = artistResult.Value.CanRemoveAlbum(domainAlbum);
|
||||
if (canRemoveAlbumResult.IsFailure)
|
||||
return canRemoveAlbumResult.Errors;
|
||||
|
||||
// The album is soft deleted, so its metadata, artwork and track paths stay available until the user restores it or the files disappear
|
||||
// from disk. The tracks of the album are not deleted themselves, so restoring the album brings back the tracks that were not deleted on their own.
|
||||
// The write re-checks the last-album condition because this snapshot can be stale.
|
||||
Result<Updated> deleteAlbumResult = await _unitOfWork.AlbumRepository.SoftDeleteByIdAsync(albumId, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteAlbumResult.IsFailure)
|
||||
return deleteAlbumResult.Errors;
|
||||
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.RestoreAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// Command for restoring a deleted album by its Id.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The unique identifier of the media library this album belongs to, taken from the route.</param>
|
||||
/// <param name="ArtistId">The unique identifier of the artist the album belongs to, taken from the route.</param>
|
||||
/// <param name="AlbumId">The unique identifier of the album to restore, taken from the route.</param>
|
||||
[DebuggerDisplay("AlbumId: {AlbumId}")]
|
||||
public record RestoreAlbumCommand(
|
||||
string? LibraryId,
|
||||
string? ArtistId,
|
||||
string? AlbumId
|
||||
) : ICommand;
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
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.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.RestoreAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to restore a deleted album by its Id.
|
||||
/// </summary>
|
||||
public class RestoreAlbumCommandHandler : ICommandHandler<RestoreAlbumCommand, Result<Updated>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<RestoreAlbumCommand> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreAlbumCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public RestoreAlbumCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<RestoreAlbumCommand> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to restore a deleted album by its Id.
|
||||
/// </summary>
|
||||
/// <param name="command">The command to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> HandleAsync(RestoreAlbumCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// The validator guarantees that the route identifiers are non-empty Guids before this point.
|
||||
Guid libraryId = Guid.Parse(command.LibraryId!);
|
||||
Guid artistId = Guid.Parse(command.ArtistId!);
|
||||
Guid albumId = Guid.Parse(command.AlbumId!);
|
||||
|
||||
// A deleted album whose artist is also deleted is not restorable on its own, so the repository reports it as missing until the artist is restored.
|
||||
Result<AlbumEntity?> getAlbumResult = await _unitOfWork.AlbumRepository.GetSoftDeletedByIdAsync(albumId, cancellationToken).ConfigureAwait(false);
|
||||
if (getAlbumResult.IsFailure)
|
||||
return getAlbumResult.Errors;
|
||||
if (getAlbumResult.Value is null)
|
||||
return DomainErrors.Music.AlbumNotFound;
|
||||
AlbumEntity existingAlbum = getAlbumResult.Value;
|
||||
|
||||
// Resource scoping: the album must belong to the artist and library named by the route, so that an album can never be restored through
|
||||
// another library's route; the mismatch is reported as not found, without disclosing that the album exists elsewhere.
|
||||
if (existingAlbum.LibraryId != libraryId || existingAlbum.ArtistId != artistId)
|
||||
return DomainErrors.Music.AlbumNotFound;
|
||||
|
||||
// Admins can restore the albums of all libraries; for everyone else, only the albums of the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(existingAlbum.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Result<Updated> restoreAlbumResult = await _unitOfWork.AlbumRepository.RestoreSoftDeletedByIdAsync(existingAlbum.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (restoreAlbumResult.IsFailure)
|
||||
return restoreAlbumResult.Errors;
|
||||
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
|
||||
return Result.Updated;
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.RestoreAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="RestoreAlbumCommand"/>.
|
||||
/// </summary>
|
||||
public class RestoreAlbumCommandValidator : AbstractValidator<RestoreAlbumCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreAlbumCommandValidator"/> class.
|
||||
/// </summary>
|
||||
public RestoreAlbumCommandValidator()
|
||||
{
|
||||
// Validates the identifier of the media library that owns the album, taken from the route.
|
||||
RuleFor(command => command.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.LibraryId)
|
||||
.Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty)
|
||||
.When(command => command.LibraryId is not null && command.LibraryId.Length > 0)
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
// Validates the identifier of the artist the album belongs to, taken from the route.
|
||||
RuleFor(command => command.ArtistId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.ArtistIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.ArtistId)
|
||||
.Must(artistId => Guid.TryParse(artistId, out Guid parsedArtistId) && parsedArtistId != Guid.Empty)
|
||||
.When(command => command.ArtistId is not null && command.ArtistId.Length > 0)
|
||||
.WithError(Errors.Music.ArtistIdCannotBeEmpty);
|
||||
|
||||
// Validates the identifier of the deleted album, taken from the route.
|
||||
RuleFor(command => command.AlbumId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.AlbumIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.AlbumId)
|
||||
.Must(albumId => Guid.TryParse(albumId, out Guid parsedAlbumId) && parsedAlbumId != Guid.Empty)
|
||||
.When(command => command.AlbumId is not null && command.AlbumId.Length > 0)
|
||||
.WithError(Errors.Music.AlbumIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+13
-10
@@ -121,13 +121,14 @@ public class UpdateAlbumCoverCommandHandler : ICommandHandler<UpdateAlbumCoverCo
|
||||
.Where(artwork => artwork.ArtworkType == ArtworkType.Cover)
|
||||
.Select(artwork => artwork.FileName)
|
||||
.FirstOrDefault();
|
||||
string? releaseTypeName = ExtractReleaseTypeDirectoryName(existingCoverPath, artistName)
|
||||
string? releaseTypeName = ExtractReleaseTypeDirectoryName(existingCoverPath, artistName, existingAlbum.ArtistId)
|
||||
?? (existingAlbum.ReleaseTypes.Count > 0 ? existingAlbum.ReleaseTypes[0].ReleaseType.ToString() : null);
|
||||
|
||||
Result<string> storeArtworkResult = await _musicArtworkService.SaveAlbumArtworkAsync(
|
||||
existingAlbum.LibraryId,
|
||||
existingAlbum.Id,
|
||||
libraryName,
|
||||
existingAlbum.ArtistId,
|
||||
artistName,
|
||||
existingAlbum.Title,
|
||||
command.Cover!,
|
||||
@@ -164,19 +165,21 @@ public class UpdateAlbumCoverCommandHandler : ICommandHandler<UpdateAlbumCoverCo
|
||||
/// </summary>
|
||||
/// <param name="coverRelativePath">The relative path of the existing cover image of the album, or <see langword="null"/> when the album has no cover.</param>
|
||||
/// <param name="artistName">The name of the artist of the album.</param>
|
||||
/// <param name="artistId">The Id of the artist of the album.</param>
|
||||
/// <returns>The name of the on-disk release type directory, or <see langword="null"/> when the album does not use one.</returns>
|
||||
private string? ExtractReleaseTypeDirectoryName(string? coverRelativePath, string artistName)
|
||||
private string? ExtractReleaseTypeDirectoryName(string? coverRelativePath, string artistName, Guid artistId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(coverRelativePath))
|
||||
return null;
|
||||
// The path is media/music/{library}/{artist}[/{releaseType}]/{album}/{file}, so the segment right before the album directory is the release
|
||||
// type directory when the album uses one, and the artist directory otherwise. An artist whose name happens to match a release type, like
|
||||
// "Live", must not be mistaken for one, so the segment is only accepted as a release type when it is not the directory of the artist.
|
||||
// The path is media/music/{libraryName}-{libraryId}/{artistName}-{artistId}[/{releaseType}]/{albumTitle}-{albumId}/{file}, so the segment
|
||||
// right before the album directory is the release type directory when the album uses one, and the artist directory otherwise. An artist
|
||||
// whose name happens to match a release type, like "Live", must not be mistaken for one, so the segment is only accepted as a release type
|
||||
// when it is not the directory of the artist.
|
||||
string[] segments = coverRelativePath.Split(_pathService.PathSeparator, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (segments.Length < 3)
|
||||
return null;
|
||||
string candidate = segments[^3];
|
||||
if (IsArtistDirectory(candidate, artistName))
|
||||
if (IsArtistDirectory(candidate, artistName, artistId))
|
||||
return null;
|
||||
return Enum.TryParse(candidate, ignoreCase: true, out MusicReleaseType releaseType) && Enum.IsDefined(releaseType) ? candidate : null;
|
||||
}
|
||||
@@ -186,12 +189,12 @@ public class UpdateAlbumCoverCommandHandler : ICommandHandler<UpdateAlbumCoverCo
|
||||
/// </summary>
|
||||
/// <param name="pathSegment">The path segment to be checked.</param>
|
||||
/// <param name="artistName">The name of the artist of the album.</param>
|
||||
/// <param name="artistId">The Id of the artist of the album.</param>
|
||||
/// <returns><see langword="true"/> when the segment is the artwork directory of the artist, <see langword="false"/> otherwise.</returns>
|
||||
private bool IsArtistDirectory(string pathSegment, string artistName)
|
||||
private bool IsArtistDirectory(string pathSegment, string artistName, Guid artistId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(artistName))
|
||||
return false;
|
||||
Result<PathSegment> artistSegmentResult = _pathService.SanitizeSegment(artistName);
|
||||
string resolvedArtistName = string.IsNullOrWhiteSpace(artistName) ? "Unknown" : artistName;
|
||||
Result<PathSegment> artistSegmentResult = _pathService.SanitizeCompositeSegment(resolvedArtistName, artistId.ToString());
|
||||
return artistSegmentResult.IsSuccess
|
||||
&& string.Equals(pathSegment, artistSegmentResult.Value.Name, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Queries.GetDeletedAlbums;
|
||||
|
||||
/// <summary>
|
||||
/// Query for getting the deleted albums of a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The unique identifier of the media library whose deleted albums are retrieved, taken from the route.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
public record GetDeletedAlbumsQuery(
|
||||
string? LibraryId
|
||||
) : IQuery;
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
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.Albums;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Queries.GetDeletedAlbums;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the deleted albums of a media library.
|
||||
/// </summary>
|
||||
public class GetDeletedAlbumsQueryHandler : IQueryHandler<GetDeletedAlbumsQuery, Result<IReadOnlyList<DeletedAlbumResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<GetDeletedAlbumsQuery> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDeletedAlbumsQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public GetDeletedAlbumsQueryHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<GetDeletedAlbumsQuery> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the query to get the deleted albums of a media library.
|
||||
/// </summary>
|
||||
/// <param name="query">The query to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the deleted albums, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<DeletedAlbumResponse>>> HandleAsync(GetDeletedAlbumsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(query);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// The validator guarantees that the library id of the route is a non-empty Guid before this point.
|
||||
Guid libraryId = Guid.Parse(query.LibraryId!);
|
||||
|
||||
// Admins can see all libraries; for everyone else, only the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(libraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Result<IReadOnlyList<AlbumEntity>> getDeletedAlbumsResult = await _unitOfWork.AlbumRepository.GetSoftDeletedByLibraryIdAsync(libraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getDeletedAlbumsResult.IsFailure)
|
||||
return getDeletedAlbumsResult.Errors;
|
||||
|
||||
IReadOnlyList<AlbumEntity> deletedAlbums = getDeletedAlbumsResult.Value;
|
||||
Result<IReadOnlyList<MusicArtworkEntity>> getArtworkResult = await _unitOfWork.MusicArtworkRepository
|
||||
.GetByOwnersAsync(MusicArtworkOwnerType.Album, [.. deletedAlbums.Select(album => album.Id)], cancellationToken).ConfigureAwait(false);
|
||||
if (getArtworkResult.IsFailure)
|
||||
return getArtworkResult.Errors;
|
||||
|
||||
// A cover row can exist before its file is resolved, so rows without a stored file name are skipped instead of hiding a resolved cover.
|
||||
Dictionary<Guid, string> coverPaths = getArtworkResult.Value
|
||||
.Where(artwork => artwork.ArtworkType == ArtworkType.Cover && !string.IsNullOrWhiteSpace(artwork.FileName))
|
||||
.GroupBy(artwork => artwork.OwnerId)
|
||||
.ToDictionary(group => group.Key, group => group.Select(artwork => artwork.FileName!).First());
|
||||
|
||||
return Result.From<IReadOnlyList<DeletedAlbumResponse>>(
|
||||
[.. deletedAlbums.Select(album => album.ToResponse(album.DeletedOnUtc ?? album.CreatedOnUtc, coverPaths.GetValueOrDefault(album.Id)))]);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Queries.GetDeletedAlbums;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetDeletedAlbumsQuery"/>.
|
||||
/// </summary>
|
||||
public class GetDeletedAlbumsQueryValidator : AbstractValidator<GetDeletedAlbumsQuery>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDeletedAlbumsQueryValidator"/> class.
|
||||
/// </summary>
|
||||
public GetDeletedAlbumsQueryValidator()
|
||||
{
|
||||
// Validates the identifier of the media library whose deleted albums are retrieved, taken from the route.
|
||||
RuleFor(query => query.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(query => query.LibraryId)
|
||||
.Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty)
|
||||
.When(query => query.LibraryId is not null && query.LibraryId.Length > 0)
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+4
-12
@@ -7,7 +7,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.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artwork;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -25,7 +24,6 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists
|
||||
public class DeleteArtistCommandHandler : ICommandHandler<DeleteArtistCommand, Result<Deleted>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IMusicArtworkCleanupService _musicArtworkCleanupService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<DeleteArtistCommand> _validator;
|
||||
@@ -34,14 +32,12 @@ public class DeleteArtistCommandHandler : ICommandHandler<DeleteArtistCommand, R
|
||||
/// Initializes a new instance of the <see cref="DeleteArtistCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="musicArtworkCleanupService">Injected service for removing the artwork of a music library item and of its children.</param>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public DeleteArtistCommandHandler(IUnitOfWork unitOfWork, IMusicArtworkCleanupService musicArtworkCleanupService, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<DeleteArtistCommand> validator)
|
||||
public DeleteArtistCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<DeleteArtistCommand> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_musicArtworkCleanupService = musicArtworkCleanupService;
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_validator = validator;
|
||||
@@ -96,13 +92,9 @@ public class DeleteArtistCommandHandler : ICommandHandler<DeleteArtistCommand, R
|
||||
if (getLibraryResult.Value is null)
|
||||
return DomainErrors.Library.LibraryNotFound;
|
||||
|
||||
// The artwork of the artist and of its albums and tracks does not cascade from the artist row, because the artwork table is shared by all
|
||||
// the music library item types, so it is removed first, while the artist and its children are still present.
|
||||
Result<Deleted> deleteArtworkResult = await _musicArtworkCleanupService.DeleteArtistArtworkAsync(artistId, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteArtworkResult.IsFailure)
|
||||
return deleteArtworkResult.Errors;
|
||||
|
||||
Result<Deleted> deleteArtistResult = await _unitOfWork.ArtistRepository.DeleteByIdAsync(artistId, cancellationToken).ConfigureAwait(false);
|
||||
// The artist is soft deleted, so its metadata, artwork and paths stay available until the user restores it or the files disappear from disk.
|
||||
// Keeping the row is also what makes the deletion survive an automatic scan, because the scan treats its track paths as already catalogued.
|
||||
Result<Updated> deleteArtistResult = await _unitOfWork.ArtistRepository.SoftDeleteByIdAsync(artistId, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteArtistResult.IsFailure)
|
||||
return deleteArtistResult.Errors;
|
||||
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.RestoreArtist;
|
||||
|
||||
/// <summary>
|
||||
/// Command for restoring a deleted artist by its Id.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The unique identifier of the media library this artist belongs to, taken from the route.</param>
|
||||
/// <param name="ArtistId">The unique identifier of the artist to restore, taken from the route.</param>
|
||||
[DebuggerDisplay("ArtistId: {ArtistId}")]
|
||||
public record RestoreArtistCommand(
|
||||
string? LibraryId,
|
||||
string? ArtistId
|
||||
) : ICommand;
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
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.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.RestoreArtist;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to restore a deleted artist by its Id.
|
||||
/// </summary>
|
||||
public class RestoreArtistCommandHandler : ICommandHandler<RestoreArtistCommand, Result<Updated>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<RestoreArtistCommand> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreArtistCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public RestoreArtistCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<RestoreArtistCommand> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to restore a deleted artist by its Id.
|
||||
/// </summary>
|
||||
/// <param name="command">The command to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> HandleAsync(RestoreArtistCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// The validator guarantees that the route identifiers are non-empty Guids before this point.
|
||||
Guid libraryId = Guid.Parse(command.LibraryId!);
|
||||
Guid artistId = Guid.Parse(command.ArtistId!);
|
||||
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository.GetSoftDeletedByIdAsync(artistId, cancellationToken).ConfigureAwait(false);
|
||||
if (getArtistResult.IsFailure)
|
||||
return getArtistResult.Errors;
|
||||
if (getArtistResult.Value is null)
|
||||
return DomainErrors.Music.ArtistNotFound;
|
||||
ArtistEntity existingArtist = getArtistResult.Value;
|
||||
|
||||
// Resource scoping: the artist must belong to the library named by the route, so that an artist can never be restored through another
|
||||
// library's route; the mismatch is reported as not found, without disclosing that the artist exists in another library.
|
||||
if (existingArtist.LibraryId != libraryId)
|
||||
return DomainErrors.Music.ArtistNotFound;
|
||||
|
||||
// Admins can restore the artists of all libraries; for everyone else, only the artists of the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(existingArtist.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
// The name of a visible artist is unique within a library, so an artist can only be restored while no visible artist took over its name.
|
||||
// The lookup only considers visible artists, so it can never return the deleted artist itself.
|
||||
Result<ArtistEntity?> getArtistByNameResult = await _unitOfWork.ArtistRepository.GetByNameAsync(existingArtist.LibraryId, existingArtist.Name, cancellationToken).ConfigureAwait(false);
|
||||
if (getArtistByNameResult.IsFailure)
|
||||
return getArtistByNameResult.Errors;
|
||||
if (getArtistByNameResult.Value is not null)
|
||||
return DomainErrors.Music.ArtistAlreadyExists;
|
||||
|
||||
Result<Updated> restoreArtistResult = await _unitOfWork.ArtistRepository.RestoreSoftDeletedByIdAsync(existingArtist.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (restoreArtistResult.IsFailure)
|
||||
return restoreArtistResult.Errors;
|
||||
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
|
||||
return Result.Updated;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.RestoreArtist;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="RestoreArtistCommand"/>.
|
||||
/// </summary>
|
||||
public class RestoreArtistCommandValidator : AbstractValidator<RestoreArtistCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreArtistCommandValidator"/> class.
|
||||
/// </summary>
|
||||
public RestoreArtistCommandValidator()
|
||||
{
|
||||
// Validates the identifier of the media library that owns the artist, taken from the route.
|
||||
RuleFor(command => command.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.LibraryId)
|
||||
.Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty)
|
||||
.When(command => command.LibraryId is not null && command.LibraryId.Length > 0)
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
// Validates the identifier of the deleted artist, taken from the route.
|
||||
RuleFor(command => command.ArtistId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.ArtistIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.ArtistId)
|
||||
.Must(artistId => Guid.TryParse(artistId, out Guid parsedArtistId) && parsedArtistId != Guid.Empty)
|
||||
.When(command => command.ArtistId is not null && command.ArtistId.Length > 0)
|
||||
.WithError(Errors.Music.ArtistIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+1
@@ -113,6 +113,7 @@ public class UpdateArtistCoverCommandHandler : ICommandHandler<UpdateArtistCover
|
||||
Result<string> storeArtworkResult = await _musicArtworkService.SaveArtistArtworkAsync(
|
||||
existingArtist.LibraryId,
|
||||
libraryName,
|
||||
existingArtist.Id,
|
||||
existingArtist.Name,
|
||||
command.Cover!,
|
||||
command.FileName!,
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetDeletedArtists;
|
||||
|
||||
/// <summary>
|
||||
/// Query for getting the deleted artists of a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The unique identifier of the media library whose deleted artists are retrieved, taken from the route.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
public record GetDeletedArtistsQuery(
|
||||
string? LibraryId
|
||||
) : IQuery;
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
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.Artists;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetDeletedArtists;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the deleted artists of a media library.
|
||||
/// </summary>
|
||||
public class GetDeletedArtistsQueryHandler : IQueryHandler<GetDeletedArtistsQuery, Result<IReadOnlyList<DeletedArtistResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<GetDeletedArtistsQuery> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDeletedArtistsQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public GetDeletedArtistsQueryHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<GetDeletedArtistsQuery> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the query to get the deleted artists of a media library.
|
||||
/// </summary>
|
||||
/// <param name="query">The query to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the deleted artists, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<DeletedArtistResponse>>> HandleAsync(GetDeletedArtistsQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(query);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// The validator guarantees that the library id of the route is a non-empty Guid before this point.
|
||||
Guid libraryId = Guid.Parse(query.LibraryId!);
|
||||
|
||||
// Admins can see all libraries; for everyone else, only the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(libraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Result<IReadOnlyList<ArtistEntity>> getDeletedArtistsResult = await _unitOfWork.ArtistRepository.GetSoftDeletedByLibraryIdAsync(libraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getDeletedArtistsResult.IsFailure)
|
||||
return getDeletedArtistsResult.Errors;
|
||||
|
||||
IReadOnlyList<ArtistEntity> deletedArtists = getDeletedArtistsResult.Value;
|
||||
Result<IReadOnlyList<MusicArtworkEntity>> getArtworkResult = await _unitOfWork.MusicArtworkRepository
|
||||
.GetByOwnersAsync(MusicArtworkOwnerType.Artist, [.. deletedArtists.Select(artist => artist.Id)], cancellationToken).ConfigureAwait(false);
|
||||
if (getArtworkResult.IsFailure)
|
||||
return getArtworkResult.Errors;
|
||||
|
||||
// A cover row can exist before its file is resolved, so rows without a stored file name are skipped instead of hiding a resolved cover.
|
||||
Dictionary<Guid, string> coverPaths = getArtworkResult.Value
|
||||
.Where(artwork => artwork.ArtworkType == ArtworkType.Cover && !string.IsNullOrWhiteSpace(artwork.FileName))
|
||||
.GroupBy(artwork => artwork.OwnerId)
|
||||
.ToDictionary(group => group.Key, group => group.Select(artwork => artwork.FileName!).First());
|
||||
|
||||
return Result.From<IReadOnlyList<DeletedArtistResponse>>(
|
||||
[.. deletedArtists.Select(artist => artist.ToResponse(artist.DeletedOnUtc ?? artist.CreatedOnUtc, coverPaths.GetValueOrDefault(artist.Id)))]);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetDeletedArtists;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetDeletedArtistsQuery"/>.
|
||||
/// </summary>
|
||||
public class GetDeletedArtistsQueryValidator : AbstractValidator<GetDeletedArtistsQuery>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDeletedArtistsQueryValidator"/> class.
|
||||
/// </summary>
|
||||
public GetDeletedArtistsQueryValidator()
|
||||
{
|
||||
// Validates the identifier of the media library whose deleted artists are retrieved, taken from the route.
|
||||
RuleFor(query => query.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(query => query.LibraryId)
|
||||
.Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty)
|
||||
.When(query => query.LibraryId is not null && query.LibraryId.Length > 0)
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artwork;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the service that removes the artwork records and the stored artwork files of a music library item, together with the artwork of its children.
|
||||
/// </summary>
|
||||
public interface IMusicArtworkCleanupService
|
||||
{
|
||||
/// <summary>
|
||||
/// Removes the artwork records and the stored artwork files of the artist identified by <paramref name="artistId"/>, together with the artwork of its albums and tracks.
|
||||
/// </summary>
|
||||
/// <param name="artistId">The Id of the artist whose artwork is removed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Deleted>> DeleteArtistArtworkAsync(Guid artistId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the artwork records and the stored artwork files of the album identified by <paramref name="albumId"/>, together with the artwork of its tracks.
|
||||
/// </summary>
|
||||
/// <param name="albumId">The Id of the album whose artwork is removed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Deleted>> DeleteAlbumArtworkAsync(Guid albumId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the artwork records and the stored artwork files of the track identified by <paramref name="trackId"/>.
|
||||
/// </summary>
|
||||
/// <param name="trackId">The Id of the track whose artwork is removed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Task<Result<Deleted>> DeleteTrackArtworkAsync(Guid trackId, CancellationToken cancellationToken);
|
||||
}
|
||||
+12
-6
@@ -20,13 +20,14 @@ public interface IMusicArtworkService
|
||||
/// <param name="libraryId">The Id of the media library the album belongs to.</param>
|
||||
/// <param name="albumId">The Id of the album.</param>
|
||||
/// <param name="libraryName">The name of the media library the album belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist of the album.</param>
|
||||
/// <param name="artistName">The name of the artist of the album.</param>
|
||||
/// <param name="albumTitle">The title of the album.</param>
|
||||
/// <param name="artwork">The artwork to store.</param>
|
||||
/// <param name="releaseTypeName">The name of the release type directory the album is stored under on disk, used to group the artwork of the different releases of an artist. When <see langword="null"/>, no release type segment is added.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the relative path of the stored artwork, or an error.</returns>
|
||||
Task<Result<string>> SaveAlbumArtworkAsync(Guid libraryId, Guid albumId, string libraryName, string artistName, string albumTitle, ArtworkDto artwork, string? releaseTypeName, CancellationToken cancellationToken);
|
||||
Task<Result<string>> SaveAlbumArtworkAsync(Guid libraryId, Guid albumId, string libraryName, Guid artistId, string artistName, string albumTitle, ArtworkDto artwork, string? releaseTypeName, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Stores the uploaded <paramref name="artwork"/> of the album into the internal media directory, and returns the relative path of the stored artwork.
|
||||
@@ -34,6 +35,7 @@ public interface IMusicArtworkService
|
||||
/// <param name="libraryId">The Id of the media library the album belongs to.</param>
|
||||
/// <param name="albumId">The Id of the album.</param>
|
||||
/// <param name="libraryName">The name of the media library the album belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist of the album.</param>
|
||||
/// <param name="artistName">The name of the artist of the album.</param>
|
||||
/// <param name="albumTitle">The title of the album.</param>
|
||||
/// <param name="artwork">The stream of the uploaded artwork to store.</param>
|
||||
@@ -41,7 +43,7 @@ public interface IMusicArtworkService
|
||||
/// <param name="releaseTypeName">The name of the release type directory the album is stored under on disk, used to group the artwork of the different releases of an artist. When <see langword="null"/>, no release type segment is added.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the relative path of the stored artwork, or an error.</returns>
|
||||
Task<Result<string>> SaveAlbumArtworkAsync(Guid libraryId, Guid albumId, string libraryName, string artistName, string albumTitle, Stream artwork, string fileName, string? releaseTypeName, CancellationToken cancellationToken);
|
||||
Task<Result<string>> SaveAlbumArtworkAsync(Guid libraryId, Guid albumId, string libraryName, Guid artistId, string artistName, string albumTitle, Stream artwork, string fileName, string? releaseTypeName, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the stored artwork of the album from the internal media directory.
|
||||
@@ -49,43 +51,47 @@ public interface IMusicArtworkService
|
||||
/// <param name="libraryId">The Id of the media library the album belongs to.</param>
|
||||
/// <param name="albumId">The Id of the album.</param>
|
||||
/// <param name="libraryName">The name of the media library the album belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist of the album.</param>
|
||||
/// <param name="artistName">The name of the artist of the album.</param>
|
||||
/// <param name="albumTitle">The title of the album.</param>
|
||||
/// <param name="releaseTypeName">The name of the release type directory the album is stored under on disk, used to group the artwork of the different releases of an artist. When omitted, no release type segment is added.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Result<Deleted> DeleteAlbumArtwork(Guid libraryId, Guid albumId, string libraryName, string artistName, string albumTitle, string? releaseTypeName = null);
|
||||
Result<Deleted> DeleteAlbumArtwork(Guid libraryId, Guid albumId, string libraryName, Guid artistId, string artistName, string albumTitle, string? releaseTypeName = null);
|
||||
|
||||
/// <summary>
|
||||
/// Stores the <paramref name="artwork"/> of the artist into the internal media directory, and returns the relative path of the stored artwork.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library the artist belongs to.</param>
|
||||
/// <param name="libraryName">The name of the media library the artist belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist.</param>
|
||||
/// <param name="artistName">The name of the artist.</param>
|
||||
/// <param name="artwork">The artwork to store.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the relative path of the stored artwork, or an error.</returns>
|
||||
Task<Result<string>> SaveArtistArtworkAsync(Guid libraryId, string libraryName, string artistName, ArtworkDto artwork, CancellationToken cancellationToken);
|
||||
Task<Result<string>> SaveArtistArtworkAsync(Guid libraryId, string libraryName, Guid artistId, string artistName, ArtworkDto artwork, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Stores the uploaded <paramref name="artwork"/> of the artist into the internal media directory, and returns the relative path of the stored artwork.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library the artist belongs to.</param>
|
||||
/// <param name="libraryName">The name of the media library the artist belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist.</param>
|
||||
/// <param name="artistName">The name of the artist.</param>
|
||||
/// <param name="artwork">The stream of the uploaded artwork to store.</param>
|
||||
/// <param name="fileName">The name of the uploaded artwork file.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the relative path of the stored artwork, or an error.</returns>
|
||||
Task<Result<string>> SaveArtistArtworkAsync(Guid libraryId, string libraryName, string artistName, Stream artwork, string fileName, CancellationToken cancellationToken);
|
||||
Task<Result<string>> SaveArtistArtworkAsync(Guid libraryId, string libraryName, Guid artistId, string artistName, Stream artwork, string fileName, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the stored artwork of the artist from the internal media directory.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library the artist belongs to.</param>
|
||||
/// <param name="libraryName">The name of the media library the artist belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist.</param>
|
||||
/// <param name="artistName">The name of the artist.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
Result<Deleted> DeleteArtistArtwork(Guid libraryId, string libraryName, string artistName);
|
||||
Result<Deleted> DeleteArtistArtwork(Guid libraryId, string libraryName, Guid artistId, string artistName);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the stored artwork file at <paramref name="artworkRelativePath"/> from the internal media directory, when it still exists.
|
||||
|
||||
-119
@@ -1,119 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artwork;
|
||||
|
||||
/// <summary>
|
||||
/// Service that removes the artwork records and the stored artwork files of a music library item, together with the artwork of its children.
|
||||
/// The artwork table is shared by all the music library item types and references its owners by a plain id, so the artwork of an item does not
|
||||
/// cascade when the item is removed, and is removed explicitly instead, from the innermost children outwards.
|
||||
/// </summary>
|
||||
internal sealed class MusicArtworkCleanupService : IMusicArtworkCleanupService
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IMusicArtworkService _musicArtworkService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MusicArtworkCleanupService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="musicArtworkService">Injected service for removing the stored artwork files of a music library item.</param>
|
||||
public MusicArtworkCleanupService(IUnitOfWork unitOfWork, IMusicArtworkService musicArtworkService)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_musicArtworkService = musicArtworkService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the artwork records and the stored artwork files of the artist identified by <paramref name="artistId"/>, together with the artwork of its albums and tracks.
|
||||
/// </summary>
|
||||
/// <param name="artistId">The Id of the artist whose artwork is removed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Deleted>> DeleteArtistArtworkAsync(Guid artistId, CancellationToken cancellationToken)
|
||||
{
|
||||
// The albums and the tracks of the artist are removed by the database through the cascading foreign keys, so only the artwork of the
|
||||
// children has to be collected here, and it has to be removed before the artwork of the artist itself, from the innermost children outwards.
|
||||
Result<IReadOnlyList<AlbumEntity>> getAlbumsResult = await _unitOfWork.AlbumRepository.GetByArtistIdAsync(artistId, cancellationToken).ConfigureAwait(false);
|
||||
if (getAlbumsResult.IsFailure)
|
||||
return getAlbumsResult.Errors;
|
||||
|
||||
foreach (AlbumEntity album in getAlbumsResult.Value)
|
||||
{
|
||||
Result<Deleted> deleteAlbumArtworkResult = await DeleteAlbumArtworkAsync(album.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteAlbumArtworkResult.IsFailure)
|
||||
return deleteAlbumArtworkResult.Errors;
|
||||
}
|
||||
|
||||
return await DeleteOwnerArtworkAsync(MusicArtworkOwnerType.Artist, artistId, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the artwork records and the stored artwork files of the album identified by <paramref name="albumId"/>, together with the artwork of its tracks.
|
||||
/// </summary>
|
||||
/// <param name="albumId">The Id of the album whose artwork is removed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Deleted>> DeleteAlbumArtworkAsync(Guid albumId, CancellationToken cancellationToken)
|
||||
{
|
||||
// The tracks of the album are removed by the database through the cascading foreign keys, so only their artwork has to be removed here,
|
||||
// before the artwork of the album itself.
|
||||
Result<IReadOnlyList<TrackEntity>> getTracksResult = await _unitOfWork.TrackRepository.GetByAlbumIdAsync(albumId, cancellationToken).ConfigureAwait(false);
|
||||
if (getTracksResult.IsFailure)
|
||||
return getTracksResult.Errors;
|
||||
|
||||
foreach (TrackEntity track in getTracksResult.Value)
|
||||
{
|
||||
Result<Deleted> deleteTrackArtworkResult = await DeleteTrackArtworkAsync(track.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteTrackArtworkResult.IsFailure)
|
||||
return deleteTrackArtworkResult.Errors;
|
||||
}
|
||||
|
||||
return await DeleteOwnerArtworkAsync(MusicArtworkOwnerType.Album, albumId, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the artwork records and the stored artwork files of the track identified by <paramref name="trackId"/>.
|
||||
/// </summary>
|
||||
/// <param name="trackId">The Id of the track whose artwork is removed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Task<Result<Deleted>> DeleteTrackArtworkAsync(Guid trackId, CancellationToken cancellationToken)
|
||||
{
|
||||
return DeleteOwnerArtworkAsync(MusicArtworkOwnerType.Track, trackId, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the artwork records and the stored artwork files of the single music library item identified by <paramref name="ownerType"/> and <paramref name="ownerId"/>.
|
||||
/// </summary>
|
||||
/// <param name="ownerType">The type of the music library item whose artwork is removed.</param>
|
||||
/// <param name="ownerId">The Id of the music library item whose artwork is removed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
private async Task<Result<Deleted>> DeleteOwnerArtworkAsync(MusicArtworkOwnerType ownerType, Guid ownerId, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<IReadOnlyList<MusicArtworkEntity>> getArtworkResult = await _unitOfWork.MusicArtworkRepository.GetByOwnerAsync(ownerType, ownerId, cancellationToken).ConfigureAwait(false);
|
||||
if (getArtworkResult.IsFailure)
|
||||
return getArtworkResult.Errors;
|
||||
|
||||
// The stored files do not cascade from their records either, so every stored file is removed before its record is; the artwork whose file has not been resolved yet has no file to remove.
|
||||
foreach (MusicArtworkEntity artwork in getArtworkResult.Value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(artwork.FileName))
|
||||
continue;
|
||||
Result<Deleted> deleteStoredArtworkResult = _musicArtworkService.DeleteStoredArtwork(artwork.FileName);
|
||||
if (deleteStoredArtworkResult.IsFailure)
|
||||
return deleteStoredArtworkResult.Errors;
|
||||
}
|
||||
|
||||
return await _unitOfWork.MusicArtworkRepository.DeleteByOwnerAsync(ownerType, ownerId, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
+19
-40
@@ -7,14 +7,9 @@ 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.Artists;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artwork;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
@@ -29,7 +24,6 @@ namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.
|
||||
public class DeleteTrackCommandHandler : ICommandHandler<DeleteTrackCommand, Result<Deleted>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IMusicArtworkCleanupService _musicArtworkCleanupService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<DeleteTrackCommand> _validator;
|
||||
@@ -38,14 +32,12 @@ public class DeleteTrackCommandHandler : ICommandHandler<DeleteTrackCommand, Res
|
||||
/// Initializes a new instance of the <see cref="DeleteTrackCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="musicArtworkCleanupService">Injected service for removing the artwork of a music library item and of its children.</param>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public DeleteTrackCommandHandler(IUnitOfWork unitOfWork, IMusicArtworkCleanupService musicArtworkCleanupService, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<DeleteTrackCommand> validator)
|
||||
public DeleteTrackCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<DeleteTrackCommand> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_musicArtworkCleanupService = musicArtworkCleanupService;
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_validator = validator;
|
||||
@@ -75,9 +67,9 @@ public class DeleteTrackCommandHandler : ICommandHandler<DeleteTrackCommand, Res
|
||||
Guid albumId = Guid.Parse(command.AlbumId!);
|
||||
Guid trackId = Guid.Parse(command.TrackId!);
|
||||
|
||||
// A track is a child of the artist aggregate, so the whole aggregate is loaded and the track is removed within it.
|
||||
// Only the library of the artist is needed to scope the delete, so the artist row is read without its aggregate graph and without tracking.
|
||||
Result<ArtistEntity?> getArtistResult = await _unitOfWork.ArtistRepository
|
||||
.GetByIdAsync(artistId, shouldIncludeNavigationProperties: true, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
.GetByIdAsync(artistId, shouldIncludeNavigationProperties: false, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getArtistResult.IsFailure)
|
||||
return getArtistResult.Errors;
|
||||
if (getArtistResult.Value is null)
|
||||
@@ -95,13 +87,6 @@ public class DeleteTrackCommandHandler : ICommandHandler<DeleteTrackCommand, Res
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
AlbumEntity? existingAlbum = existingArtist.Albums.FirstOrDefault(album => album.Id == albumId);
|
||||
if (existingAlbum is null)
|
||||
return DomainErrors.Music.AlbumNotFound;
|
||||
TrackEntity? existingTrack = existingAlbum.Tracks.FirstOrDefault(track => track.Id == trackId);
|
||||
if (existingTrack is null)
|
||||
return DomainErrors.Music.TrackNotFound;
|
||||
|
||||
// A track can only belong to a library that exists, so a client can never delete a track of a library of the host that is not there.
|
||||
Result<LibraryEntity?> getLibraryResult = await _unitOfWork.LibraryRepository
|
||||
.GetByIdAsync(libraryId, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
@@ -110,31 +95,25 @@ public class DeleteTrackCommandHandler : ICommandHandler<DeleteTrackCommand, Res
|
||||
if (getLibraryResult.Value is null)
|
||||
return DomainErrors.Library.LibraryNotFound;
|
||||
|
||||
// The write path goes through the aggregate root: a track is a child entity of the artist aggregate, unlike Book and Artist,
|
||||
// which are aggregate roots and are deleted directly through their own repositories. This difference is intentional.
|
||||
Result<Artist> artistResult = existingArtist.ToDomainEntity();
|
||||
if (artistResult.IsFailure)
|
||||
return artistResult.Errors;
|
||||
// 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)
|
||||
Result<AlbumEntity?> getAlbumResult = await _unitOfWork.AlbumRepository
|
||||
.GetByIdAsync(albumId, shouldIncludeNavigationProperties: false, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getAlbumResult.IsFailure)
|
||||
return getAlbumResult.Errors;
|
||||
if (getAlbumResult.Value is null || getAlbumResult.Value.ArtistId != artistId || getAlbumResult.Value.LibraryId != libraryId)
|
||||
return DomainErrors.Music.AlbumNotFound;
|
||||
Track? domainTrack = domainAlbum.Tracks.FirstOrDefault(track => track.Id.Value == trackId);
|
||||
if (domainTrack is null)
|
||||
|
||||
Result<TrackEntity?> getTrackResult = await _unitOfWork.TrackRepository
|
||||
.GetByIdAsync(trackId, shouldIncludeNavigationProperties: false, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getTrackResult.IsFailure)
|
||||
return getTrackResult.Errors;
|
||||
if (getTrackResult.Value is null || getTrackResult.Value.AlbumId != albumId || getTrackResult.Value.LibraryId != libraryId)
|
||||
return DomainErrors.Music.TrackNotFound;
|
||||
Result<Deleted> removeTrackResult = artistResult.Value.RemoveTrackFromAlbum(domainAlbum, domainTrack);
|
||||
if (removeTrackResult.IsFailure)
|
||||
return removeTrackResult.Errors;
|
||||
|
||||
// The artwork of the track does not cascade from the track row, because the artwork table is shared by all the music library item
|
||||
// types, so it is removed first, while the track is still present.
|
||||
Result<Deleted> deleteArtworkResult = await _musicArtworkCleanupService.DeleteTrackArtworkAsync(trackId, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteArtworkResult.IsFailure)
|
||||
return deleteArtworkResult.Errors;
|
||||
|
||||
Result<Updated> updateResult = await _unitOfWork.ArtistRepository.UpdateAsync(artistResult.Value.ToRepositoryEntity(), cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsFailure)
|
||||
return updateResult.Errors;
|
||||
// The track is soft deleted, so its metadata, artwork and path stay available until the user restores it or the file disappears from disk.
|
||||
// Keeping the row is also what makes the deletion survive an automatic scan, because the scan treats its path as already catalogued.
|
||||
Result<Updated> deleteTrackResult = await _unitOfWork.TrackRepository.SoftDeleteByIdAsync(trackId, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteTrackResult.IsFailure)
|
||||
return deleteTrackResult.Errors;
|
||||
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.RestoreTrack;
|
||||
|
||||
/// <summary>
|
||||
/// Command for restoring a deleted track by its Id.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The unique identifier of the media library this track belongs to, taken from the route.</param>
|
||||
/// <param name="ArtistId">The unique identifier of the artist the album of the track belongs to, taken from the route.</param>
|
||||
/// <param name="AlbumId">The unique identifier of the album the track belongs to, taken from the route.</param>
|
||||
/// <param name="TrackId">The unique identifier of the track to restore, taken from the route.</param>
|
||||
[DebuggerDisplay("TrackId: {TrackId}")]
|
||||
public record RestoreTrackCommand(
|
||||
string? LibraryId,
|
||||
string? ArtistId,
|
||||
string? AlbumId,
|
||||
string? TrackId
|
||||
) : ICommand;
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
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.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.RestoreTrack;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to restore a deleted track by its Id.
|
||||
/// </summary>
|
||||
public class RestoreTrackCommandHandler : ICommandHandler<RestoreTrackCommand, Result<Updated>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<RestoreTrackCommand> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreTrackCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public RestoreTrackCommandHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<RestoreTrackCommand> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to restore a deleted track by its Id.
|
||||
/// </summary>
|
||||
/// <param name="command">The command to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> HandleAsync(RestoreTrackCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// The validator guarantees that the route identifiers are non-empty Guids before this point.
|
||||
Guid libraryId = Guid.Parse(command.LibraryId!);
|
||||
Guid artistId = Guid.Parse(command.ArtistId!);
|
||||
Guid albumId = Guid.Parse(command.AlbumId!);
|
||||
Guid trackId = Guid.Parse(command.TrackId!);
|
||||
|
||||
// A deleted track whose album or artist is also deleted is not restorable on its own, so the repository reports it as missing until
|
||||
// the album and the artist are restored.
|
||||
Result<TrackEntity?> getTrackResult = await _unitOfWork.TrackRepository.GetSoftDeletedByIdAsync(trackId, cancellationToken).ConfigureAwait(false);
|
||||
if (getTrackResult.IsFailure)
|
||||
return getTrackResult.Errors;
|
||||
if (getTrackResult.Value is null)
|
||||
return DomainErrors.Music.TrackNotFound;
|
||||
TrackEntity existingTrack = getTrackResult.Value;
|
||||
|
||||
// Resource scoping: the track must belong to the album, the artist and the library named by the route, so that a track can never be
|
||||
// restored through another library's route; the mismatch is reported as not found, without disclosing that the track exists elsewhere.
|
||||
if (existingTrack.LibraryId != libraryId || existingTrack.AlbumId != albumId)
|
||||
return DomainErrors.Music.TrackNotFound;
|
||||
|
||||
// Admins can restore the tracks of all libraries; for everyone else, only the tracks of the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(existingTrack.LibraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Result<AlbumEntity?> getAlbumResult = await _unitOfWork.AlbumRepository
|
||||
.GetByIdAsync(albumId, shouldIncludeNavigationProperties: false, shouldTrackEntities: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getAlbumResult.IsFailure)
|
||||
return getAlbumResult.Errors;
|
||||
if (getAlbumResult.Value is null || getAlbumResult.Value.ArtistId != artistId)
|
||||
return DomainErrors.Music.TrackNotFound;
|
||||
|
||||
Result<Updated> restoreTrackResult = await _unitOfWork.TrackRepository.RestoreSoftDeletedByIdAsync(existingTrack.Id, cancellationToken).ConfigureAwait(false);
|
||||
if (restoreTrackResult.IsFailure)
|
||||
return restoreTrackResult.Errors;
|
||||
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
|
||||
return Result.Updated;
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.RestoreTrack;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="RestoreTrackCommand"/>.
|
||||
/// </summary>
|
||||
public class RestoreTrackCommandValidator : AbstractValidator<RestoreTrackCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreTrackCommandValidator"/> class.
|
||||
/// </summary>
|
||||
public RestoreTrackCommandValidator()
|
||||
{
|
||||
// Validates the identifier of the media library that owns the track, taken from the route.
|
||||
RuleFor(command => command.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.LibraryId)
|
||||
.Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty)
|
||||
.When(command => command.LibraryId is not null && command.LibraryId.Length > 0)
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
// Validates the identifier of the artist the album of the track belongs to, taken from the route.
|
||||
RuleFor(command => command.ArtistId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.ArtistIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.ArtistId)
|
||||
.Must(artistId => Guid.TryParse(artistId, out Guid parsedArtistId) && parsedArtistId != Guid.Empty)
|
||||
.When(command => command.ArtistId is not null && command.ArtistId.Length > 0)
|
||||
.WithError(Errors.Music.ArtistIdCannotBeEmpty);
|
||||
|
||||
// Validates the identifier of the album the track belongs to, taken from the route.
|
||||
RuleFor(command => command.AlbumId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.AlbumIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.AlbumId)
|
||||
.Must(albumId => Guid.TryParse(albumId, out Guid parsedAlbumId) && parsedAlbumId != Guid.Empty)
|
||||
.When(command => command.AlbumId is not null && command.AlbumId.Length > 0)
|
||||
.WithError(Errors.Music.AlbumIdCannotBeEmpty);
|
||||
|
||||
// Validates the identifier of the deleted track, taken from the route.
|
||||
RuleFor(command => command.TrackId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Music.TrackIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.TrackId)
|
||||
.Must(trackId => Guid.TryParse(trackId, out Guid parsedTrackId) && parsedTrackId != Guid.Empty)
|
||||
.When(command => command.TrackId is not null && command.TrackId.Length > 0)
|
||||
.WithError(Errors.Music.TrackIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.GetDeletedTracks;
|
||||
|
||||
/// <summary>
|
||||
/// Query for getting the deleted tracks of a media library.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The unique identifier of the media library whose deleted tracks are retrieved, taken from the route.</param>
|
||||
[DebuggerDisplay("LibraryId: {LibraryId}")]
|
||||
public record GetDeletedTracksQuery(
|
||||
string? LibraryId
|
||||
) : IQuery;
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
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.Tracks;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.GetDeletedTracks;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the deleted tracks of a media library.
|
||||
/// </summary>
|
||||
public class GetDeletedTracksQueryHandler : IQueryHandler<GetDeletedTracksQuery, Result<IReadOnlyList<DeletedTrackResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IValidator<GetDeletedTracksQuery> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDeletedTracksQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public GetDeletedTracksQueryHandler(IUnitOfWork unitOfWork, IAuthorizationService authorizationService, ICurrentUserService currentUserService, IValidator<GetDeletedTracksQuery> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_authorizationService = authorizationService;
|
||||
_currentUserService = currentUserService;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the query to get the deleted tracks of a media library.
|
||||
/// </summary>
|
||||
/// <param name="query">The query to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the deleted tracks, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<DeletedTrackResponse>>> HandleAsync(GetDeletedTracksQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(query);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// The validator guarantees that the library id of the route is a non-empty Guid before this point.
|
||||
Guid libraryId = Guid.Parse(query.LibraryId!);
|
||||
|
||||
// Admins can see all libraries; for everyone else, only the libraries they own.
|
||||
bool canAccessLibrary = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(libraryId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessLibrary)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Result<IReadOnlyList<TrackEntity>> getDeletedTracksResult = await _unitOfWork.TrackRepository.GetSoftDeletedByLibraryIdAsync(libraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (getDeletedTracksResult.IsFailure)
|
||||
return getDeletedTracksResult.Errors;
|
||||
|
||||
return Result.From<IReadOnlyList<DeletedTrackResponse>>(
|
||||
[.. getDeletedTracksResult.Value.Select(track => track.ToResponse(track.DeletedOnUtc ?? track.CreatedOnUtc))]);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.GetDeletedTracks;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetDeletedTracksQuery"/>.
|
||||
/// </summary>
|
||||
public class GetDeletedTracksQueryValidator : AbstractValidator<GetDeletedTracksQuery>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDeletedTracksQueryValidator"/> class.
|
||||
/// </summary>
|
||||
public GetDeletedTracksQueryValidator()
|
||||
{
|
||||
// Validates the identifier of the media library whose deleted tracks are retrieved, taken from the route.
|
||||
RuleFor(query => query.LibraryId)
|
||||
.NotEmpty()
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(query => query.LibraryId)
|
||||
.Must(libraryId => Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty)
|
||||
.When(query => query.LibraryId is not null && query.LibraryId.Length > 0)
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+48
-8
@@ -1,9 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artwork;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -20,6 +22,8 @@ namespace Lumina.Application.Core.MediaLibrary.Management.Deletion;
|
||||
internal sealed class MusicMediaLibraryItemDeletionStrategy : IMediaLibraryItemDeletionStrategy
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IMusicArtworkService _musicArtworkService;
|
||||
private readonly ILogger<MusicMediaLibraryItemDeletionStrategy> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// The media library type that this deletion strategy supports.
|
||||
@@ -30,9 +34,13 @@ internal sealed class MusicMediaLibraryItemDeletionStrategy : IMediaLibraryItemD
|
||||
/// Initializes a new instance of the <see cref="MusicMediaLibraryItemDeletionStrategy"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
public MusicMediaLibraryItemDeletionStrategy(IUnitOfWork unitOfWork)
|
||||
/// <param name="musicArtworkService">Injected service for deleting the stored artwork files of the music library items.</param>
|
||||
/// <param name="logger">Injected logger used to report the issues encountered while deleting the media library item.</param>
|
||||
public MusicMediaLibraryItemDeletionStrategy(IUnitOfWork unitOfWork, IMusicArtworkService musicArtworkService, ILogger<MusicMediaLibraryItemDeletionStrategy> logger)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_musicArtworkService = musicArtworkService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -46,6 +54,7 @@ internal sealed class MusicMediaLibraryItemDeletionStrategy : IMediaLibraryItemD
|
||||
public async Task<Result<Success>> DeleteItemAsync(Guid libraryId, string path, CancellationToken cancellationToken)
|
||||
{
|
||||
// Load the track stored at the deleted path, which might have been already removed.
|
||||
// Soft deleted tracks are included on purpose: when their file disappears from disk, they must be removed permanently too.
|
||||
Result<TrackEntity?> getTrackResult = await _unitOfWork.TrackRepository.GetByPathAsync(libraryId, path, cancellationToken).ConfigureAwait(false);
|
||||
if (getTrackResult.IsFailure)
|
||||
return getTrackResult.Errors;
|
||||
@@ -57,7 +66,7 @@ internal sealed class MusicMediaLibraryItemDeletionStrategy : IMediaLibraryItemD
|
||||
Guid albumId = track.AlbumId;
|
||||
|
||||
// Delete the stored artwork of the track, which has no cascade relationship because the artwork table is shared by all the music library item types.
|
||||
Result<Deleted> deleteTrackArtworkResult = await _unitOfWork.MusicArtworkRepository.DeleteByOwnerAsync(MusicArtworkOwnerType.Track, trackId, cancellationToken).ConfigureAwait(false);
|
||||
Result<Deleted> deleteTrackArtworkResult = await DeleteStoredArtworkAndRowsAsync(MusicArtworkOwnerType.Track, trackId, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteTrackArtworkResult.IsFailure)
|
||||
return deleteTrackArtworkResult.Errors;
|
||||
|
||||
@@ -65,8 +74,8 @@ internal sealed class MusicMediaLibraryItemDeletionStrategy : IMediaLibraryItemD
|
||||
if (deleteTrackResult.IsFailure)
|
||||
return deleteTrackResult.Errors;
|
||||
|
||||
// Load the album the deleted track belonged to, to determine whether it is left with no children.
|
||||
Result<AlbumEntity?> getAlbumResult = await _unitOfWork.AlbumRepository.GetByIdAsync(albumId, shouldIncludeNavigationProperties: false, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
// Load the album the deleted track belonged to, whether the album itself is soft deleted or not, to determine whether it is left with no children.
|
||||
Result<AlbumEntity?> getAlbumResult = await _unitOfWork.AlbumRepository.GetIncludingDeletedByIdAsync(albumId, cancellationToken).ConfigureAwait(false);
|
||||
if (getAlbumResult.IsFailure)
|
||||
return getAlbumResult.Errors;
|
||||
AlbumEntity? album = getAlbumResult.Value;
|
||||
@@ -75,13 +84,14 @@ internal sealed class MusicMediaLibraryItemDeletionStrategy : IMediaLibraryItemD
|
||||
|
||||
Guid artistId = album.ArtistId;
|
||||
|
||||
Result<IReadOnlyList<TrackEntity>> getRemainingTracksResult = await _unitOfWork.TrackRepository.GetByAlbumIdAsync(albumId, cancellationToken).ConfigureAwait(false);
|
||||
// Soft deleted tracks are counted as well, because their files still exist and the album must survive until the last one of them disappears.
|
||||
Result<IReadOnlyList<TrackEntity>> getRemainingTracksResult = await _unitOfWork.TrackRepository.GetByAlbumIdIncludingDeletedAsync(albumId, cancellationToken).ConfigureAwait(false);
|
||||
if (getRemainingTracksResult.IsFailure)
|
||||
return getRemainingTracksResult.Errors;
|
||||
// The deleted track is still tracked by the change tracker until the changes are saved, so it is excluded explicitly.
|
||||
if (getRemainingTracksResult.Value.All(remainingTrack => remainingTrack.Id == trackId))
|
||||
{
|
||||
Result<Deleted> deleteAlbumArtworkResult = await _unitOfWork.MusicArtworkRepository.DeleteByOwnerAsync(MusicArtworkOwnerType.Album, albumId, cancellationToken).ConfigureAwait(false);
|
||||
Result<Deleted> deleteAlbumArtworkResult = await DeleteStoredArtworkAndRowsAsync(MusicArtworkOwnerType.Album, albumId, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteAlbumArtworkResult.IsFailure)
|
||||
return deleteAlbumArtworkResult.Errors;
|
||||
|
||||
@@ -89,13 +99,14 @@ internal sealed class MusicMediaLibraryItemDeletionStrategy : IMediaLibraryItemD
|
||||
if (deleteAlbumResult.IsFailure)
|
||||
return deleteAlbumResult.Errors;
|
||||
|
||||
Result<IReadOnlyList<AlbumEntity>> getRemainingAlbumsResult = await _unitOfWork.AlbumRepository.GetByArtistIdAsync(artistId, cancellationToken).ConfigureAwait(false);
|
||||
// Soft deleted albums are counted as well, because their tracks still exist and the artist must survive until the last one of them disappears.
|
||||
Result<IReadOnlyList<AlbumEntity>> getRemainingAlbumsResult = await _unitOfWork.AlbumRepository.GetByArtistIdIncludingDeletedAsync(artistId, cancellationToken).ConfigureAwait(false);
|
||||
if (getRemainingAlbumsResult.IsFailure)
|
||||
return getRemainingAlbumsResult.Errors;
|
||||
// The deleted album is still tracked by the change tracker until the changes are saved, so it is excluded explicitly.
|
||||
if (getRemainingAlbumsResult.Value.All(remainingAlbum => remainingAlbum.Id == albumId))
|
||||
{
|
||||
Result<Deleted> deleteArtistArtworkResult = await _unitOfWork.MusicArtworkRepository.DeleteByOwnerAsync(MusicArtworkOwnerType.Artist, artistId, cancellationToken).ConfigureAwait(false);
|
||||
Result<Deleted> deleteArtistArtworkResult = await DeleteStoredArtworkAndRowsAsync(MusicArtworkOwnerType.Artist, artistId, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteArtistArtworkResult.IsFailure)
|
||||
return deleteArtistArtworkResult.Errors;
|
||||
|
||||
@@ -108,6 +119,35 @@ internal sealed class MusicMediaLibraryItemDeletionStrategy : IMediaLibraryItemD
|
||||
return await SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the stored artwork files of the music library item of the provided <paramref name="ownerType"/> identified by <paramref name="ownerId"/>,
|
||||
/// and then deletes the artwork rows of that item.
|
||||
/// </summary>
|
||||
/// <param name="ownerType">The type of the music library item that owns the artwork.</param>
|
||||
/// <param name="ownerId">The Id of the music library item that owns the artwork.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
private async Task<Result<Deleted>> DeleteStoredArtworkAndRowsAsync(MusicArtworkOwnerType ownerType, Guid ownerId, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<IReadOnlyList<MusicArtworkEntity>> getArtworkResult = await _unitOfWork.MusicArtworkRepository
|
||||
.GetByOwnerAsync(ownerType, ownerId, cancellationToken).ConfigureAwait(false);
|
||||
if (getArtworkResult.IsFailure)
|
||||
return getArtworkResult.Errors;
|
||||
|
||||
// The stored files are deleted best-effort, since a missing or locked file must not prevent the permanent removal of the media library item.
|
||||
foreach (MusicArtworkEntity artwork in getArtworkResult.Value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(artwork.FileName))
|
||||
continue;
|
||||
|
||||
Result<Deleted> deleteStoredArtworkResult = _musicArtworkService.DeleteStoredArtwork(artwork.FileName);
|
||||
if (deleteStoredArtworkResult.IsFailure)
|
||||
_logger.LogWarning("Failed to delete the stored {OwnerType} artwork at '{ArtworkPath}' of the music library item with Id '{OwnerId}', the file might remain orphaned.", ownerType, artwork.FileName, ownerId);
|
||||
}
|
||||
|
||||
return await _unitOfWork.MusicArtworkRepository.DeleteByOwnerAsync(ownerType, ownerId, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Persists the changes made to the storage medium.
|
||||
/// </summary>
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ public class LibraryDeletedDomainEventHandler : IDomainEventHandler<LibraryDelet
|
||||
// live inside these directories, so removing them removes the library's stored media without touching the user's own files.
|
||||
DeleteLibraryDirectory(_mediaSettingsModel.LibrariesDirectory, libraryId.ToString());
|
||||
|
||||
Result<PathSegment> librarySegmentResult = _pathService.SanitizeSegment($"{domainEvent.Library.Title}-{libraryId}");
|
||||
Result<PathSegment> librarySegmentResult = _pathService.SanitizeCompositeSegment(domainEvent.Library.Title, libraryId.ToString());
|
||||
if (librarySegmentResult.IsFailure)
|
||||
throw new EventualConsistencyException(librarySegmentResult.FirstError, librarySegmentResult.Errors);
|
||||
DeleteLibraryDirectory(_mediaSettingsModel.BooksDirectory, librarySegmentResult.Value.Name);
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a music album that the user deleted and can restore.
|
||||
/// </summary>
|
||||
/// <param name="Id">The unique identifier of the album.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the media library the album belongs to.</param>
|
||||
/// <param name="ArtistId">The unique identifier of the artist the album belongs to.</param>
|
||||
/// <param name="ArtistName">The name of the artist the album belongs to.</param>
|
||||
/// <param name="Title">The title of the album.</param>
|
||||
/// <param name="DeletedOnUtc">The date and time when the album was deleted.</param>
|
||||
/// <param name="CoverPath">The relative path of the stored cover image of the album, when it has one.</param>
|
||||
public record DeletedAlbumResponse(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
Guid ArtistId,
|
||||
string ArtistName,
|
||||
string Title,
|
||||
DateTime DeletedOnUtc,
|
||||
string? CoverPath
|
||||
);
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a music artist that the user deleted and can restore.
|
||||
/// </summary>
|
||||
/// <param name="Id">The unique identifier of the artist.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the media library the artist belongs to.</param>
|
||||
/// <param name="Name">The name of the artist.</param>
|
||||
/// <param name="DeletedOnUtc">The date and time when the artist was deleted.</param>
|
||||
/// <param name="CoverPath">The relative path of the stored cover image of the artist, when it has one.</param>
|
||||
public record DeletedArtistResponse(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
string Name,
|
||||
DateTime DeletedOnUtc,
|
||||
string? CoverPath
|
||||
);
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a music track that the user deleted and can restore.
|
||||
/// </summary>
|
||||
/// <param name="Id">The unique identifier of the track.</param>
|
||||
/// <param name="LibraryId">The unique identifier of the media library the track belongs to.</param>
|
||||
/// <param name="ArtistId">The unique identifier of the artist the track belongs to.</param>
|
||||
/// <param name="ArtistName">The name of the artist the track belongs to.</param>
|
||||
/// <param name="AlbumId">The unique identifier of the album the track belongs to.</param>
|
||||
/// <param name="AlbumTitle">The title of the album the track belongs to.</param>
|
||||
/// <param name="Title">The title of the track.</param>
|
||||
/// <param name="Path">The file system path of the track.</param>
|
||||
/// <param name="DeletedOnUtc">The date and time when the track was deleted.</param>
|
||||
public record DeletedTrackResponse(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
Guid ArtistId,
|
||||
string ArtistName,
|
||||
Guid AlbumId,
|
||||
string AlbumTitle,
|
||||
string Title,
|
||||
string Path,
|
||||
DateTime DeletedOnUtc
|
||||
);
|
||||
@@ -130,6 +130,12 @@ public class AlbumConfiguration : IEntityTypeConfiguration<AlbumEntity>
|
||||
builder.Property(album => album.MetadataProvider)
|
||||
.HasMaxLength(100)
|
||||
.HasColumnOrder(38);
|
||||
builder.Property(album => album.IsDeleted)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnOrder(39);
|
||||
builder.Property(album => album.DeletedOnUtc)
|
||||
.HasColumnOrder(40);
|
||||
|
||||
builder.HasOne(album => album.Artist)
|
||||
.WithMany(artist => artist.Albums)
|
||||
@@ -232,5 +238,9 @@ public class AlbumConfiguration : IEntityTypeConfiguration<AlbumEntity>
|
||||
|
||||
builder.HasIndex(album => new { album.ArtistId, album.Title });
|
||||
builder.HasIndex(album => new { album.LibraryId, album.Title });
|
||||
// The deleted items page filters by library and deletion state, and orders by the stored deletion time, the title and the Id, so the
|
||||
// filtered index follows the same order and no temporary B-tree is needed for the sort, while visible rows add no entries to it.
|
||||
builder.HasIndex(album => new { album.LibraryId, album.IsDeleted, album.DeletedOnUtc, album.Title, album.Id })
|
||||
.HasFilter("\"IsDeleted\" = 1");
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,12 @@ public class ArtistConfiguration : IEntityTypeConfiguration<ArtistEntity>
|
||||
builder.Property(artist => artist.MetadataProvider)
|
||||
.HasMaxLength(100)
|
||||
.HasColumnOrder(19);
|
||||
builder.Property(artist => artist.IsDeleted)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnOrder(20);
|
||||
builder.Property(artist => artist.DeletedOnUtc)
|
||||
.HasColumnOrder(21);
|
||||
|
||||
// The areas are owned value objects that are never referenced on their own, so they are stored as JSON documents next to the artist.
|
||||
builder.OwnsOne(artist => artist.Area, areaBuilder => areaBuilder.ToJson());
|
||||
@@ -202,7 +208,14 @@ public class ArtistConfiguration : IEntityTypeConfiguration<ArtistEntity>
|
||||
.HasForeignKey(contributor => contributor.ArtistId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
// The same visible artist cannot appear twice in the same library, while a deleted artist does not block a new visible artist with the
|
||||
// same name, so that a new file of an artist the user deleted can still materialize as a new, visible artist.
|
||||
builder.HasIndex(artist => new { artist.LibraryId, artist.Name })
|
||||
.IsUnique(); // the same artist cannot appear twice in the same library
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = 0");
|
||||
// The deleted items page filters by library and deletion state, and orders by the stored deletion time, the name and the Id, so the
|
||||
// filtered index follows the same order and no temporary B-tree is needed for the sort, while visible rows add no entries to it.
|
||||
builder.HasIndex(artist => new { artist.LibraryId, artist.IsDeleted, artist.DeletedOnUtc, artist.Name, artist.Id })
|
||||
.HasFilter("\"IsDeleted\" = 1");
|
||||
}
|
||||
}
|
||||
@@ -155,6 +155,12 @@ public class TrackConfiguration : IEntityTypeConfiguration<TrackEntity>
|
||||
builder.Property(track => track.Container)
|
||||
.HasMaxLength(50)
|
||||
.HasColumnOrder(49);
|
||||
builder.Property(track => track.IsDeleted)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnOrder(50);
|
||||
builder.Property(track => track.DeletedOnUtc)
|
||||
.HasColumnOrder(51);
|
||||
|
||||
builder.HasOne(track => track.Album)
|
||||
.WithMany(album => album.Tracks)
|
||||
@@ -291,5 +297,9 @@ public class TrackConfiguration : IEntityTypeConfiguration<TrackEntity>
|
||||
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
|
||||
// The deleted items page filters by library and deletion state, and orders by the stored deletion time, the title and the Id, so the
|
||||
// filtered index follows the same order and no temporary B-tree is needed for the sort, while visible rows add no entries to it.
|
||||
builder.HasIndex(track => new { track.LibraryId, track.IsDeleted, track.DeletedOnUtc, track.Title, track.Id })
|
||||
.HasFilter("\"IsDeleted\" = 1");
|
||||
}
|
||||
}
|
||||
+3956
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Lumina.DataAccess.Common.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddsMusicDeletionState : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Artists_LibraryId_Name",
|
||||
table: "Artists");
|
||||
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "DeletedOnUtc",
|
||||
table: "Tracks",
|
||||
type: "TEXT",
|
||||
nullable: true)
|
||||
.Annotation("Relational:ColumnOrder", 51);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsDeleted",
|
||||
table: "Tracks",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: false)
|
||||
.Annotation("Relational:ColumnOrder", 50);
|
||||
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "DeletedOnUtc",
|
||||
table: "Artists",
|
||||
type: "TEXT",
|
||||
nullable: true)
|
||||
.Annotation("Relational:ColumnOrder", 21);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsDeleted",
|
||||
table: "Artists",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: false)
|
||||
.Annotation("Relational:ColumnOrder", 20);
|
||||
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "DeletedOnUtc",
|
||||
table: "Albums",
|
||||
type: "TEXT",
|
||||
nullable: true)
|
||||
.Annotation("Relational:ColumnOrder", 40);
|
||||
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsDeleted",
|
||||
table: "Albums",
|
||||
type: "INTEGER",
|
||||
nullable: false,
|
||||
defaultValue: false)
|
||||
.Annotation("Relational:ColumnOrder", 39);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Tracks_LibraryId_IsDeleted_DeletedOnUtc_Title_Id",
|
||||
table: "Tracks",
|
||||
columns: new[] { "LibraryId", "IsDeleted", "DeletedOnUtc", "Title", "Id" },
|
||||
filter: "\"IsDeleted\" = 1");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Artists_LibraryId_IsDeleted_DeletedOnUtc_Name_Id",
|
||||
table: "Artists",
|
||||
columns: new[] { "LibraryId", "IsDeleted", "DeletedOnUtc", "Name", "Id" },
|
||||
filter: "\"IsDeleted\" = 1");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Artists_LibraryId_Name",
|
||||
table: "Artists",
|
||||
columns: new[] { "LibraryId", "Name" },
|
||||
unique: true,
|
||||
filter: "\"IsDeleted\" = 0");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Albums_LibraryId_IsDeleted_DeletedOnUtc_Title_Id",
|
||||
table: "Albums",
|
||||
columns: new[] { "LibraryId", "IsDeleted", "DeletedOnUtc", "Title", "Id" },
|
||||
filter: "\"IsDeleted\" = 1");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Tracks_LibraryId_IsDeleted_DeletedOnUtc_Title_Id",
|
||||
table: "Tracks");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Artists_LibraryId_IsDeleted_DeletedOnUtc_Name_Id",
|
||||
table: "Artists");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Artists_LibraryId_Name",
|
||||
table: "Artists");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Albums_LibraryId_IsDeleted_DeletedOnUtc_Title_Id",
|
||||
table: "Albums");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DeletedOnUtc",
|
||||
table: "Tracks");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsDeleted",
|
||||
table: "Tracks");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DeletedOnUtc",
|
||||
table: "Artists");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsDeleted",
|
||||
table: "Artists");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "DeletedOnUtc",
|
||||
table: "Albums");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsDeleted",
|
||||
table: "Albums");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Artists_LibraryId_Name",
|
||||
table: "Artists",
|
||||
columns: new[] { "LibraryId", "Name" },
|
||||
unique: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -652,6 +652,10 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(32);
|
||||
|
||||
b.Property<DateTime?>("DeletedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(40);
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("TEXT")
|
||||
@@ -662,6 +666,12 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(6);
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER")
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnOrder(39);
|
||||
|
||||
b.Property<string>("Label")
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT")
|
||||
@@ -807,6 +817,9 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
|
||||
b.HasIndex("LibraryId", "Title");
|
||||
|
||||
b.HasIndex("LibraryId", "IsDeleted", "DeletedOnUtc", "Title", "Id")
|
||||
.HasFilter("\"IsDeleted\" = 1");
|
||||
|
||||
b.ToTable("Albums", (string)null);
|
||||
});
|
||||
|
||||
@@ -875,6 +888,10 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(13);
|
||||
|
||||
b.Property<DateTime?>("DeletedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(21);
|
||||
|
||||
b.Property<string>("Disambiguation")
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT")
|
||||
@@ -885,6 +902,12 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(6);
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER")
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnOrder(20);
|
||||
|
||||
b.Property<bool>("IsEnded")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(10);
|
||||
@@ -954,7 +977,11 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("LibraryId", "Name")
|
||||
.IsUnique();
|
||||
.IsUnique()
|
||||
.HasFilter("\"IsDeleted\" = 0");
|
||||
|
||||
b.HasIndex("LibraryId", "IsDeleted", "DeletedOnUtc", "Name", "Id")
|
||||
.HasFilter("\"IsDeleted\" = 1");
|
||||
|
||||
b.ToTable("Artists", (string)null);
|
||||
});
|
||||
@@ -1279,6 +1306,10 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(37);
|
||||
|
||||
b.Property<DateTime?>("DeletedOnUtc")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(51);
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("TEXT")
|
||||
@@ -1297,6 +1328,12 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(20);
|
||||
|
||||
b.Property<bool>("IsDeleted")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER")
|
||||
.HasDefaultValue(false)
|
||||
.HasColumnOrder(50);
|
||||
|
||||
b.Property<bool>("IsVideo")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(31);
|
||||
@@ -1459,6 +1496,9 @@ namespace Lumina.DataAccess.Common.Migrations
|
||||
b.HasIndex("LibraryId", "Path")
|
||||
.IsUnique();
|
||||
|
||||
b.HasIndex("LibraryId", "IsDeleted", "DeletedOnUtc", "Title", "Id")
|
||||
.HasFilter("\"IsDeleted\" = 1");
|
||||
|
||||
b.ToTable("Tracks", (string)null);
|
||||
});
|
||||
|
||||
|
||||
@@ -113,17 +113,17 @@ internal sealed class FavoriteRepository : IFavoriteRepository
|
||||
{
|
||||
FavoriteMediaKind.MusicArtist => await _luminaDbContext.Artists
|
||||
.AsNoTracking()
|
||||
.Where(artist => artist.Id == mediaItemId)
|
||||
.Where(artist => artist.Id == mediaItemId && !artist.IsDeleted)
|
||||
.Select(artist => (Guid?)artist.LibraryId)
|
||||
.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false),
|
||||
FavoriteMediaKind.MusicAlbum => await _luminaDbContext.Albums
|
||||
.AsNoTracking()
|
||||
.Where(album => album.Id == mediaItemId)
|
||||
.Where(album => album.Id == mediaItemId && !album.IsDeleted && !album.Artist!.IsDeleted)
|
||||
.Select(album => (Guid?)album.LibraryId)
|
||||
.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false),
|
||||
FavoriteMediaKind.MusicTrack => await _luminaDbContext.Tracks
|
||||
.AsNoTracking()
|
||||
.Where(track => track.Id == mediaItemId)
|
||||
.Where(track => track.Id == mediaItemId && !track.IsDeleted && !track.Album!.IsDeleted && !track.Album!.Artist!.IsDeleted)
|
||||
.Select(track => (Guid?)track.LibraryId)
|
||||
.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false),
|
||||
FavoriteMediaKind.Book => await _luminaDbContext.Books
|
||||
@@ -293,7 +293,7 @@ internal sealed class FavoriteRepository : IFavoriteRepository
|
||||
// The cover of the artist is the cover artwork stored for it, if any, the same one the artist listing exposes.
|
||||
rows = await _luminaDbContext.Artists
|
||||
.AsNoTracking()
|
||||
.Where(artist => requestedIds.Contains(artist.Id))
|
||||
.Where(artist => requestedIds.Contains(artist.Id) && !artist.IsDeleted)
|
||||
.Select(artist => new DisplayRow(
|
||||
artist.Id,
|
||||
artist.LibraryId,
|
||||
@@ -311,7 +311,7 @@ internal sealed class FavoriteRepository : IFavoriteRepository
|
||||
case FavoriteMediaKind.MusicAlbum:
|
||||
rows = await (from album in _luminaDbContext.Albums.AsNoTracking()
|
||||
join artist in _luminaDbContext.Artists on album.ArtistId equals artist.Id
|
||||
where requestedIds.Contains(album.Id)
|
||||
where requestedIds.Contains(album.Id) && !album.IsDeleted && !artist.IsDeleted
|
||||
select new DisplayRow(
|
||||
album.Id,
|
||||
album.LibraryId,
|
||||
@@ -331,7 +331,7 @@ internal sealed class FavoriteRepository : IFavoriteRepository
|
||||
rows = await (from track in _luminaDbContext.Tracks.AsNoTracking()
|
||||
join album in _luminaDbContext.Albums on track.AlbumId equals album.Id
|
||||
join artist in _luminaDbContext.Artists on album.ArtistId equals artist.Id
|
||||
where requestedIds.Contains(track.Id)
|
||||
where requestedIds.Contains(track.Id) && !track.IsDeleted && !album.IsDeleted && !artist.IsDeleted
|
||||
select new DisplayRow(
|
||||
track.Id,
|
||||
track.LibraryId,
|
||||
|
||||
@@ -3,6 +3,7 @@ using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MusicLibrary;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.DataAccess.Common.Persistence;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
@@ -28,16 +29,19 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
{
|
||||
private readonly LuminaDbContext _luminaDbContext;
|
||||
private readonly ITrackRepository _trackRepository;
|
||||
private readonly IDateTimeProvider _dateTimeProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AlbumRepository"/> class.
|
||||
/// </summary>
|
||||
/// <param name="luminaDbContext">Injected Entity Framework DbContext.</param>
|
||||
/// <param name="trackRepository">Injected repository for tracks.</param>
|
||||
public AlbumRepository(LuminaDbContext luminaDbContext, ITrackRepository trackRepository)
|
||||
/// <param name="dateTimeProvider">Injected provider for the current UTC time, used to stamp deletions deterministically.</param>
|
||||
public AlbumRepository(LuminaDbContext luminaDbContext, ITrackRepository trackRepository, IDateTimeProvider dateTimeProvider)
|
||||
{
|
||||
_luminaDbContext = luminaDbContext;
|
||||
_trackRepository = trackRepository;
|
||||
_dateTimeProvider = dateTimeProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -121,7 +125,7 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
.Include(repositoryAlbum => repositoryAlbum.Ratings)
|
||||
.Include(repositoryAlbum => repositoryAlbum.Contributors)
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(repositoryAlbum => repositoryAlbum.Id == data.Id, cancellationToken).ConfigureAwait(false);
|
||||
.FirstOrDefaultAsync(repositoryAlbum => repositoryAlbum.Id == data.Id && !repositoryAlbum.IsDeleted && !repositoryAlbum.Artist!.IsDeleted, cancellationToken).ConfigureAwait(false);
|
||||
if (foundAlbum is null)
|
||||
return Errors.Music.AlbumNotFound;
|
||||
|
||||
@@ -141,9 +145,17 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
// The stored identity is never overwritten by an edit, and the audit columns are only ever written by the auditing interceptor.
|
||||
Guid artistId = foundAlbum.ArtistId;
|
||||
Guid libraryId = foundAlbum.LibraryId;
|
||||
bool isDeleted = foundAlbum.IsDeleted;
|
||||
DateTime? deletedOnUtc = foundAlbum.DeletedOnUtc;
|
||||
EditableValuesCopier.CopyEditableValues(_luminaDbContext, foundAlbum, data);
|
||||
foundAlbum.ArtistId = artistId;
|
||||
foundAlbum.LibraryId = libraryId;
|
||||
// The deletion state is owned by the explicit delete and restore operations. Clearing the modified flags keeps it out of the UPDATE statement,
|
||||
// so an edit that raced with a delete can never write the deletion state back and resurrect the album.
|
||||
foundAlbum.IsDeleted = isDeleted;
|
||||
foundAlbum.DeletedOnUtc = deletedOnUtc;
|
||||
_luminaDbContext.Entry(foundAlbum).Property(album => album.IsDeleted).IsModified = false;
|
||||
_luminaDbContext.Entry(foundAlbum).Property(album => album.DeletedOnUtc).IsModified = false;
|
||||
|
||||
// Tags and genres are shared across the whole database, so the stored rows whose names already exist are reused, and only the missing names are inserted.
|
||||
Result<Updated> reconcileTagsResult = await SharedReferenceResolver.ReconcileAsync(_luminaDbContext, foundAlbum.Tags, data.Tags, Errors.Metadata.TagNameCannotBeEmpty, cancellationToken).ConfigureAwait(false);
|
||||
@@ -204,7 +216,8 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either an <see cref="AlbumEntity"/>, or an error.</returns>
|
||||
public async Task<Result<AlbumEntity?>> GetByIdAsync(Guid id, bool shouldIncludeNavigationProperties = true, bool shouldTrackEntities = true, CancellationToken cancellationToken = default)
|
||||
{
|
||||
IQueryable<AlbumEntity> query = _luminaDbContext.Albums;
|
||||
// A deleted album, or an album of a deleted artist, is kept in the storage medium only so that its paths stay reserved and it can be restored, so it is never returned to a caller.
|
||||
IQueryable<AlbumEntity> query = _luminaDbContext.Albums.Where(album => !album.IsDeleted && !album.Artist!.IsDeleted);
|
||||
if (!shouldTrackEntities)
|
||||
query = query.AsNoTracking();
|
||||
if (shouldIncludeNavigationProperties)
|
||||
@@ -215,17 +228,17 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
.Include(album => album.Tags)
|
||||
.Include(album => album.Genres)
|
||||
.Include(album => album.Contributors)
|
||||
.Include(album => album.Tracks)
|
||||
.Include(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Ratings)
|
||||
.Include(album => album.Tracks)
|
||||
.Include(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Genres)
|
||||
.Include(album => album.Tracks)
|
||||
.Include(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Tags)
|
||||
.Include(album => album.Tracks)
|
||||
.Include(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Moods)
|
||||
.Include(album => album.Tracks)
|
||||
.Include(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Isrcs)
|
||||
.Include(album => album.Tracks)
|
||||
.Include(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Contributors)
|
||||
.AsSplitQuery();
|
||||
}
|
||||
@@ -233,7 +246,7 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the albums of the artist identified by <paramref name="artistId"/>.
|
||||
/// Gets the albums of the artist identified by <paramref name="artistId"/> that are not soft deleted.
|
||||
/// </summary>
|
||||
/// <param name="artistId">The Id of the artist whose albums are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
@@ -245,25 +258,54 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
.Include(album => album.Tags)
|
||||
.Include(album => album.Genres)
|
||||
.Include(album => album.Contributors)
|
||||
.Include(album => album.Tracks)
|
||||
.Include(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Ratings)
|
||||
.Include(album => album.Tracks)
|
||||
.Include(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Genres)
|
||||
.Include(album => album.Tracks)
|
||||
.Include(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Tags)
|
||||
.Include(album => album.Tracks)
|
||||
.Include(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Moods)
|
||||
.Include(album => album.Tracks)
|
||||
.Include(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Isrcs)
|
||||
.Include(album => album.Tracks)
|
||||
.Include(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Contributors)
|
||||
.AsSplitQuery()
|
||||
.Where(album => album.ArtistId == artistId && !album.IsDeleted && !album.Artist!.IsDeleted)
|
||||
.OrderBy(album => album.Title)
|
||||
.ThenBy(album => album.Id)
|
||||
.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the albums of the artist identified by <paramref name="artistId"/>, whether they are soft deleted or not.
|
||||
/// </summary>
|
||||
/// <param name="artistId">The Id of the artist whose albums are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="AlbumEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<AlbumEntity>>> GetByArtistIdIncludingDeletedAsync(Guid artistId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Albums
|
||||
.AsNoTracking()
|
||||
.Where(album => album.ArtistId == artistId)
|
||||
.OrderBy(album => album.Title)
|
||||
.ThenBy(album => album.Id)
|
||||
.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the album identified by <paramref name="id"/>, whether it is soft deleted or not, without loading its navigation properties.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the album to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="AlbumEntity"/>, or an error.</returns>
|
||||
public async Task<Result<AlbumEntity?>> GetIncludingDeletedByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Albums
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(album => album.Id == id, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lightweight read models of the albums of the artist identified by <paramref name="artistId"/>,
|
||||
/// or all of them when the pagination data is <see langword="null"/>, projecting only the fields needed to display the albums in a card-based grid.
|
||||
@@ -279,7 +321,7 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
// The cover of the album is the cover artwork stored for it, if any, and it is exposed so that the clients can display it without loading the whole album.
|
||||
IQueryable<AlbumLiteRow> liteRowsQuery = _luminaDbContext.Albums
|
||||
.AsNoTracking()
|
||||
.Where(album => album.ArtistId == artistId)
|
||||
.Where(album => album.ArtistId == artistId && !album.IsDeleted && !album.Artist!.IsDeleted)
|
||||
.OrderBy(album => album.Title)
|
||||
.ThenBy(album => album.Id)
|
||||
.Select(album => new AlbumLiteRow(
|
||||
@@ -335,7 +377,7 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
public async Task<Result<AlbumEntity?>> GetByTitleAsync(Guid artistId, string title, CancellationToken cancellationToken)
|
||||
{
|
||||
AlbumEntity? album = await _luminaDbContext.Albums
|
||||
.FirstOrDefaultAsync(repositoryAlbum => repositoryAlbum.ArtistId == artistId && repositoryAlbum.Title == title, cancellationToken).ConfigureAwait(false);
|
||||
.FirstOrDefaultAsync(repositoryAlbum => repositoryAlbum.ArtistId == artistId && repositoryAlbum.Title == title && !repositoryAlbum.IsDeleted && !repositoryAlbum.Artist!.IsDeleted, cancellationToken).ConfigureAwait(false);
|
||||
return album;
|
||||
}
|
||||
|
||||
@@ -352,10 +394,98 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
string directoryPrefix = directoryPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + Path.DirectorySeparatorChar;
|
||||
AlbumEntity? album = await _luminaDbContext.Albums
|
||||
.FirstOrDefaultAsync(repositoryAlbum => repositoryAlbum.ArtistId == artistId
|
||||
&& !repositoryAlbum.IsDeleted
|
||||
&& !repositoryAlbum.Artist!.IsDeleted
|
||||
&& repositoryAlbum.Tracks.Any(track => track.Path.StartsWith(directoryPrefix)), cancellationToken).ConfigureAwait(false);
|
||||
return album;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the soft deleted album identified by <paramref name="id"/>, when its artist is not soft deleted.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the soft deleted album to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted <see cref="AlbumEntity"/>, <see langword="null"/> when the album does not exist, is not soft deleted, or its artist is soft deleted, or an error.</returns>
|
||||
public async Task<Result<AlbumEntity?>> GetSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Albums
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(album => album.Id == id && album.IsDeleted && !album.Artist!.IsDeleted, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the soft deleted albums of the media library identified by <paramref name="libraryId"/>, whose artist is not soft deleted.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose soft deleted albums are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted albums, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<AlbumEntity>>> GetSoftDeletedByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Albums
|
||||
.AsNoTracking()
|
||||
.Include(album => album.Artist)
|
||||
.Where(album => album.LibraryId == libraryId && album.IsDeleted && !album.Artist!.IsDeleted)
|
||||
// The deletion time is stored when the album is deleted, so later writes to the hidden row cannot change the order of the deleted items,
|
||||
// and every deleted row carries a deletion time because the delete operation always sets it. All terms sort descending, so the filtered
|
||||
// (LibraryId, IsDeleted, DeletedOnUtc, Title, Id) index can be scanned backwards and the database does not build a temporary B-tree.
|
||||
.OrderByDescending(album => album.DeletedOnUtc)
|
||||
.ThenByDescending(album => album.Title)
|
||||
.ThenByDescending(album => album.Id)
|
||||
.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Soft deletes the album identified by <paramref name="id"/>, without removing its stored metadata or artwork, when another visible album of its artist remains.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The update is executed directly against the storage medium, so an entity already tracked by the caller is not refreshed, and the audit fields
|
||||
/// stamped by the change tracker are not updated; the deletion time is stored in <see cref="AlbumEntity.DeletedOnUtc"/> instead.
|
||||
/// </remarks>
|
||||
/// <param name="id">The Id of the album to soft delete.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> SoftDeleteByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
DateTime deletedOnUtc = _dateTimeProvider.UtcNow;
|
||||
|
||||
// The condition that an artist must have at least one remaining album is re-checked here so a delete that raced with another cannot leave the artist without albums.
|
||||
int updatedRows = await _luminaDbContext.Albums
|
||||
.Where(album => album.Id == id
|
||||
&& !album.IsDeleted
|
||||
&& _luminaDbContext.Albums.Any(sibling => sibling.ArtistId == album.ArtistId && sibling.Id != album.Id && !sibling.IsDeleted))
|
||||
.ExecuteUpdateAsync(setters => setters
|
||||
.SetProperty(album => album.IsDeleted, true)
|
||||
.SetProperty(album => album.DeletedOnUtc, deletedOnUtc), cancellationToken).ConfigureAwait(false);
|
||||
if (updatedRows > 0)
|
||||
return Result.Updated;
|
||||
|
||||
// The update matched nothing, so the album is missing, is already deleted, or is the last visible album of its artist. The row is read
|
||||
// only to report the reason, never to decide the transition.
|
||||
AlbumEntity? album = await _luminaDbContext.Albums
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(candidate => candidate.Id == id, cancellationToken).ConfigureAwait(false);
|
||||
if (album is null || album.IsDeleted)
|
||||
return Errors.Music.AlbumNotFound;
|
||||
return Errors.Music.ArtistMustHaveAtLeastOneAlbum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores the soft deleted album identified by <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the album to restore.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> RestoreSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
AlbumEntity? album = await _luminaDbContext.Albums.FirstOrDefaultAsync(repositoryAlbum => repositoryAlbum.Id == id, cancellationToken).ConfigureAwait(false);
|
||||
if (album is null || !album.IsDeleted)
|
||||
return Errors.Music.AlbumNotFound;
|
||||
|
||||
album.IsDeleted = false;
|
||||
album.DeletedOnUtc = null;
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the album identified by <paramref name="id"/>, together with its tracks and its contributions, by the database cascade.
|
||||
/// </summary>
|
||||
@@ -382,7 +512,7 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
public async Task<Result<int>> GetAlbumsNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Albums
|
||||
.CountAsync(album => album.LibraryId == libraryId && album.MetadataStatus != MetadataStatus.Enriched, cancellationToken).ConfigureAwait(false);
|
||||
.CountAsync(album => album.LibraryId == libraryId && !album.IsDeleted && !album.Artist!.IsDeleted && album.MetadataStatus != MetadataStatus.Enriched, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -395,6 +525,8 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
{
|
||||
return await _luminaDbContext.Albums
|
||||
.CountAsync(album => album.LibraryId == libraryId
|
||||
&& !album.IsDeleted
|
||||
&& !album.Artist!.IsDeleted
|
||||
&& !_luminaDbContext.MusicArtwork.Any(musicArtwork => musicArtwork.OwnerType == MusicArtworkOwnerType.Album
|
||||
&& musicArtwork.OwnerId == album.Id
|
||||
&& (musicArtwork.Status == ArtworkStatus.Enriched || musicArtwork.Status == ArtworkStatus.NotAvailable)), cancellationToken).ConfigureAwait(false);
|
||||
@@ -416,6 +548,8 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
.AsNoTracking()
|
||||
.Include(album => album.Artist)
|
||||
.Where(album => album.LibraryId == libraryId
|
||||
&& !album.IsDeleted
|
||||
&& !album.Artist!.IsDeleted
|
||||
&& !excludedIds.Contains(album.Id)
|
||||
&& !_luminaDbContext.MusicArtwork.Any(musicArtwork => musicArtwork.OwnerType == MusicArtworkOwnerType.Album
|
||||
&& musicArtwork.OwnerId == album.Id
|
||||
@@ -439,7 +573,7 @@ internal sealed class AlbumRepository : IAlbumRepository
|
||||
|
||||
List<AlbumTrackPathRow> rows = await _luminaDbContext.Tracks
|
||||
.AsNoTracking()
|
||||
.Where(track => albumIdsList.Contains(track.AlbumId))
|
||||
.Where(track => albumIdsList.Contains(track.AlbumId) && !track.IsDeleted)
|
||||
.OrderBy(track => track.AlbumId)
|
||||
.ThenBy(track => track.Path)
|
||||
.Select(track => new AlbumTrackPathRow(track.AlbumId, track.Path))
|
||||
|
||||
@@ -5,6 +5,7 @@ using Lumina.Application.Common.DataAccess.Repositories.MusicLibrary;
|
||||
using Lumina.Application.Common.DTO.Filtering;
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.Application.Common.Specifications;
|
||||
using Lumina.DataAccess.Common.Persistence;
|
||||
using Lumina.DataAccess.Core.Repositories.MusicLibrary.Specifications;
|
||||
@@ -38,6 +39,7 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
private readonly LuminaDbContext _luminaDbContext;
|
||||
private readonly IAlbumRepository _albumRepository;
|
||||
private readonly ITrackRepository _trackRepository;
|
||||
private readonly IDateTimeProvider _dateTimeProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ArtistRepository"/> class.
|
||||
@@ -45,11 +47,13 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
/// <param name="luminaDbContext">Injected Entity Framework DbContext.</param>
|
||||
/// <param name="albumRepository">Injected repository for albums.</param>
|
||||
/// <param name="trackRepository">Injected repository for tracks.</param>
|
||||
public ArtistRepository(LuminaDbContext luminaDbContext, IAlbumRepository albumRepository, ITrackRepository trackRepository)
|
||||
/// <param name="dateTimeProvider">Injected provider for the current UTC time, used to stamp deletions deterministically.</param>
|
||||
public ArtistRepository(LuminaDbContext luminaDbContext, IAlbumRepository albumRepository, ITrackRepository trackRepository, IDateTimeProvider dateTimeProvider)
|
||||
{
|
||||
_luminaDbContext = luminaDbContext;
|
||||
_albumRepository = albumRepository;
|
||||
_trackRepository = trackRepository;
|
||||
_dateTimeProvider = dateTimeProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -65,7 +69,7 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
return Errors.Music.ArtistAlreadyExists;
|
||||
|
||||
// An artist is unique within its library by its name, so the same artist can never be registered twice in the same library.
|
||||
bool doesArtistNameExist = await _luminaDbContext.Artists.AnyAsync(repositoryArtist => repositoryArtist.LibraryId == artist.LibraryId && repositoryArtist.Name == artist.Name, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
bool doesArtistNameExist = await _luminaDbContext.Artists.AnyAsync(repositoryArtist => repositoryArtist.LibraryId == artist.LibraryId && repositoryArtist.Name == artist.Name && !repositoryArtist.IsDeleted, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (doesArtistNameExist)
|
||||
return Errors.Music.ArtistAlreadyExists;
|
||||
|
||||
@@ -154,14 +158,27 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.ThenInclude(track => track.Contributors)
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(repositoryArtist => repositoryArtist.Id == data.Id, cancellationToken).ConfigureAwait(false);
|
||||
.FirstOrDefaultAsync(repositoryArtist => repositoryArtist.Id == data.Id && !repositoryArtist.IsDeleted, cancellationToken).ConfigureAwait(false);
|
||||
if (foundArtist is null)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
|
||||
// A soft deleted album or track is kept out of every edit, so a payload that names one, even under another parent, must not rewrite it.
|
||||
Result<Success> validateNoSoftDeletedItemsResult = ValidateNoSoftDeletedItemsAreEdited(foundArtist, data);
|
||||
if (validateNoSoftDeletedItemsResult.IsFailure)
|
||||
return validateNoSoftDeletedItemsResult.Errors;
|
||||
|
||||
// The stored identity is never overwritten by an edit, and the audit columns are only ever written by the auditing interceptor.
|
||||
Guid libraryId = foundArtist.LibraryId;
|
||||
bool isDeleted = foundArtist.IsDeleted;
|
||||
DateTime? deletedOnUtc = foundArtist.DeletedOnUtc;
|
||||
EditableValuesCopier.CopyEditableValues(_luminaDbContext, foundArtist, data);
|
||||
foundArtist.LibraryId = libraryId;
|
||||
// The deletion state is owned by the explicit delete and restore operations. Clearing the modified flags keeps it out of the UPDATE statement,
|
||||
// so an edit that raced with a delete can never write the deletion state back and resurrect the artist.
|
||||
foundArtist.IsDeleted = isDeleted;
|
||||
foundArtist.DeletedOnUtc = deletedOnUtc;
|
||||
_luminaDbContext.Entry(foundArtist).Property(artist => artist.IsDeleted).IsModified = false;
|
||||
_luminaDbContext.Entry(foundArtist).Property(artist => artist.DeletedOnUtc).IsModified = false;
|
||||
|
||||
// A contributor participation is matched by the contributor and the role they played. Matched participations keep their identity and their audit columns, so a
|
||||
// contributor that is displayed or linked elsewhere is never deleted and re-inserted just because another field of the artist was edited.
|
||||
@@ -257,7 +274,8 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
// albums and their tracks are updated in place, so that persisted entities keep their identity across an edit. An album whose data did
|
||||
// not change produces no write statement, because its own repository only applies the values that actually changed.
|
||||
List<Guid> incomingAlbumIds = [.. data.Albums.Select(album => album.Id)];
|
||||
foreach (AlbumEntity removedAlbum in foundArtist.Albums.Where(album => !incomingAlbumIds.Contains(album.Id)).ToList())
|
||||
// A soft deleted album is kept out of every edit, so it is never removed from the tracked aggregate, which would permanently delete it.
|
||||
foreach (AlbumEntity removedAlbum in foundArtist.Albums.Where(album => !album.IsDeleted && !incomingAlbumIds.Contains(album.Id)).ToList())
|
||||
foundArtist.Albums.Remove(removedAlbum);
|
||||
|
||||
foreach (AlbumEntity incomingAlbum in data.Albums)
|
||||
@@ -283,6 +301,30 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures no incoming album or track of <paramref name="data"/> matches a soft deleted album or track of <paramref name="foundArtist"/>.
|
||||
/// </summary>
|
||||
/// <param name="foundArtist">The tracked artist that is being updated.</param>
|
||||
/// <param name="data">The artist carrying the desired albums and tracks.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful check, or an error.</returns>
|
||||
private static Result<Success> ValidateNoSoftDeletedItemsAreEdited(ArtistEntity foundArtist, ArtistEntity data)
|
||||
{
|
||||
Dictionary<Guid, AlbumEntity> storedAlbums = foundArtist.Albums.ToDictionary(album => album.Id);
|
||||
Dictionary<Guid, TrackEntity> storedTracks = foundArtist.Albums.SelectMany(album => album.Tracks).ToDictionary(track => track.Id);
|
||||
|
||||
foreach (AlbumEntity incomingAlbum in data.Albums)
|
||||
{
|
||||
if (storedAlbums.TryGetValue(incomingAlbum.Id, out AlbumEntity? storedAlbum) && storedAlbum.IsDeleted)
|
||||
return Errors.Music.AlbumNotFound;
|
||||
|
||||
foreach (TrackEntity incomingTrack in incomingAlbum.Tracks)
|
||||
if (storedTracks.TryGetValue(incomingTrack.Id, out TrackEntity? storedTrack) && storedTrack.IsDeleted)
|
||||
return Errors.Music.TrackNotFound;
|
||||
}
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the file system paths of the tracks that are not yet stored and will therefore be inserted when <paramref name="data"/> is applied over <paramref name="foundArtist"/>.
|
||||
/// </summary>
|
||||
@@ -341,7 +383,8 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
private async Task<Result<Updated>> ReconcileTracksAsync(AlbumEntity existingAlbum, AlbumEntity incomingAlbum, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Guid> incomingTrackIds = [.. incomingAlbum.Tracks.Select(track => track.Id)];
|
||||
foreach (TrackEntity removedTrack in existingAlbum.Tracks.Where(track => !incomingTrackIds.Contains(track.Id)).ToList())
|
||||
// A soft deleted track is kept out of every edit, so it is never removed from the tracked album, which would permanently delete it.
|
||||
foreach (TrackEntity removedTrack in existingAlbum.Tracks.Where(track => !track.IsDeleted && !incomingTrackIds.Contains(track.Id)).ToList())
|
||||
existingAlbum.Tracks.Remove(removedTrack);
|
||||
|
||||
foreach (TrackEntity incomingTrack in incomingAlbum.Tracks)
|
||||
@@ -375,40 +418,43 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either an <see cref="ArtistEntity"/>, or an error.</returns>
|
||||
public async Task<Result<ArtistEntity?>> GetByIdAsync(Guid id, bool shouldIncludeNavigationProperties = true, bool shouldTrackEntities = true, CancellationToken cancellationToken = default)
|
||||
{
|
||||
IQueryable<ArtistEntity> query = _luminaDbContext.Artists;
|
||||
// A deleted artist is kept in the storage medium only so that its paths stay reserved and it can be restored, so it is never returned to a caller.
|
||||
IQueryable<ArtistEntity> query = _luminaDbContext.Artists.Where(artist => !artist.IsDeleted);
|
||||
if (!shouldTrackEntities)
|
||||
query = query.AsNoTracking();
|
||||
if (shouldIncludeNavigationProperties)
|
||||
{
|
||||
// The albums and the tracks of an artist are child entities of its aggregate, so the deleted ones are filtered out of the graph
|
||||
// that a caller edits or displays, while the repository keeps them stored for a restore.
|
||||
query = query
|
||||
.Include(artist => artist.Tags)
|
||||
.Include(artist => artist.Genres)
|
||||
.Include(artist => artist.Contributors)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Ratings)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Genres)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tags)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Contributors)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Ratings)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Genres)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Tags)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Moods)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Isrcs)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Contributors)
|
||||
.AsSplitQuery();
|
||||
}
|
||||
@@ -446,7 +492,7 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="PaginatedResultDto{ArtistEntity}"/>, or an error.</returns>
|
||||
public async Task<Result<PaginatedResultDto<ArtistEntity>>> GetAllAsync<TFilter>(PaginationDataDto? paginationData = null, string? sortBy = null, SortOrder? sortOrder = null, TFilter? filterModel = null, bool shouldIncludeNavigationProperties = true, bool shouldTrackEntities = true, CancellationToken cancellationToken = default) where TFilter : BaseFilterDto
|
||||
{
|
||||
IQueryable<ArtistEntity> artistsQuery = _luminaDbContext.Artists;
|
||||
IQueryable<ArtistEntity> artistsQuery = _luminaDbContext.Artists.Where(artist => !artist.IsDeleted);
|
||||
if (!shouldTrackEntities)
|
||||
artistsQuery = artistsQuery.AsNoTracking();
|
||||
if (shouldIncludeNavigationProperties)
|
||||
@@ -455,31 +501,31 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
.Include(artist => artist.Tags)
|
||||
.Include(artist => artist.Genres)
|
||||
.Include(artist => artist.Contributors)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Ratings)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Genres)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tags)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Contributors)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Ratings)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Genres)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Tags)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Moods)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Isrcs)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Contributors)
|
||||
.AsSplitQuery();
|
||||
}
|
||||
@@ -550,13 +596,13 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
return Errors.Library.FilterMustIncludeLibraryId;
|
||||
|
||||
// The lightweight read models are retrieved without tracking by default, because they are never modified by the caller.
|
||||
IQueryable<ArtistEntity> artistsQuery = _luminaDbContext.Artists;
|
||||
IQueryable<ArtistEntity> artistsQuery = _luminaDbContext.Artists.Where(artist => !artist.IsDeleted);
|
||||
if (!shouldTrackEntities)
|
||||
artistsQuery = artistsQuery.AsNoTracking();
|
||||
if (shouldIncludeNavigationProperties)
|
||||
artistsQuery = artistsQuery
|
||||
.Include(artist => artist.Contributors)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.AsSplitQuery();
|
||||
|
||||
artistsQuery = artistsQuery.Where(artist => artist.LibraryId == libraryFilter.LibraryId);
|
||||
@@ -702,8 +748,10 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the <see cref="ArtistEntity"/> with the provided name, or an error.</returns>
|
||||
public async Task<Result<ArtistEntity?>> GetByNameAsync(Guid libraryId, string name, CancellationToken cancellationToken)
|
||||
{
|
||||
// A deleted artist is not returned to the scan, so a scan that finds a new file of the same artist materializes a new, visible artist
|
||||
// instead of attaching the file to the deleted one.
|
||||
ArtistEntity? artist = await _luminaDbContext.Artists
|
||||
.FirstOrDefaultAsync(repositoryArtist => repositoryArtist.LibraryId == libraryId && repositoryArtist.Name == name, cancellationToken).ConfigureAwait(false);
|
||||
.FirstOrDefaultAsync(repositoryArtist => repositoryArtist.LibraryId == libraryId && repositoryArtist.Name == name && !repositoryArtist.IsDeleted, cancellationToken).ConfigureAwait(false);
|
||||
return artist;
|
||||
}
|
||||
|
||||
@@ -729,45 +777,46 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
.Include(artist => artist.Tags)
|
||||
.Include(artist => artist.Ratings)
|
||||
.Include(artist => artist.Contributors)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.ReleaseTypes)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Genres)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tags)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Ratings)
|
||||
.Include(artist => artist.Albums)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Contributors)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Genres)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Tags)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Ratings)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Moods)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Isrcs)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.Contributors)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.WorkLanguages)
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.ThenInclude(track => track.WorkIswcs)
|
||||
.AsSplitQuery()
|
||||
.Where(artist => artist.LibraryId == libraryId
|
||||
&& !artist.IsDeleted
|
||||
&& (artist.MetadataStatus != MetadataStatus.Enriched
|
||||
|| artist.Albums.Any(album => album.MetadataStatus != MetadataStatus.Enriched)
|
||||
|| artist.Albums.Any(album => album.Tracks.Any(track => track.MetadataStatus != MetadataStatus.Enriched)))
|
||||
|| artist.Albums.Any(album => !album.IsDeleted && album.MetadataStatus != MetadataStatus.Enriched)
|
||||
|| artist.Albums.Any(album => !album.IsDeleted && album.Tracks.Any(track => !track.IsDeleted && track.MetadataStatus != MetadataStatus.Enriched)))
|
||||
&& (lastName == null || artist.Name.CompareTo(lastName) > 0))
|
||||
.OrderBy(artist => artist.Name)
|
||||
.Take(pageSize)
|
||||
@@ -784,9 +833,10 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
{
|
||||
return await _luminaDbContext.Artists
|
||||
.CountAsync(artist => artist.LibraryId == libraryId
|
||||
&& !artist.IsDeleted
|
||||
&& (artist.MetadataStatus != MetadataStatus.Enriched
|
||||
|| artist.Albums.Any(album => album.MetadataStatus != MetadataStatus.Enriched)
|
||||
|| artist.Albums.Any(album => album.Tracks.Any(track => track.MetadataStatus != MetadataStatus.Enriched))), cancellationToken).ConfigureAwait(false);
|
||||
|| artist.Albums.Any(album => !album.IsDeleted && album.MetadataStatus != MetadataStatus.Enriched)
|
||||
|| artist.Albums.Any(album => !album.IsDeleted && album.Tracks.Any(track => !track.IsDeleted && track.MetadataStatus != MetadataStatus.Enriched))), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -799,6 +849,7 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
{
|
||||
return await _luminaDbContext.Artists
|
||||
.CountAsync(artist => artist.LibraryId == libraryId
|
||||
&& !artist.IsDeleted
|
||||
&& !_luminaDbContext.MusicArtwork.Any(musicArtwork => musicArtwork.OwnerType == MusicArtworkOwnerType.Artist
|
||||
&& musicArtwork.OwnerId == artist.Id
|
||||
&& (musicArtwork.Status == ArtworkStatus.Enriched || musicArtwork.Status == ArtworkStatus.NotAvailable)), cancellationToken).ConfigureAwait(false);
|
||||
@@ -817,10 +868,11 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
{
|
||||
return await _luminaDbContext.Artists
|
||||
.AsNoTracking()
|
||||
.Include(artist => artist.Albums)
|
||||
.ThenInclude(album => album.Tracks)
|
||||
.Include(artist => artist.Albums.Where(album => !album.IsDeleted))
|
||||
.ThenInclude(album => album.Tracks.Where(track => !track.IsDeleted))
|
||||
.AsSplitQuery()
|
||||
.Where(artist => artist.LibraryId == libraryId
|
||||
&& !artist.IsDeleted
|
||||
&& !_luminaDbContext.MusicArtwork.Any(musicArtwork => musicArtwork.OwnerType == MusicArtworkOwnerType.Artist
|
||||
&& musicArtwork.OwnerId == artist.Id
|
||||
&& (musicArtwork.Status == ArtworkStatus.Enriched || musicArtwork.Status == ArtworkStatus.NotAvailable))
|
||||
@@ -844,6 +896,73 @@ internal sealed class ArtistRepository : IArtistRepository
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the soft deleted artist identified by <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the soft deleted artist to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted <see cref="ArtistEntity"/>, <see langword="null"/> when the artist does not exist or is not soft deleted, or an error.</returns>
|
||||
public async Task<Result<ArtistEntity?>> GetSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Artists
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(artist => artist.Id == id && artist.IsDeleted, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the soft deleted artists of the media library identified by <paramref name="libraryId"/>.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose soft deleted artists are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted artists, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<ArtistEntity>>> GetSoftDeletedByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Artists
|
||||
.AsNoTracking()
|
||||
.Where(artist => artist.LibraryId == libraryId && artist.IsDeleted)
|
||||
// The deletion time is stored when the artist is deleted, so later writes to the hidden row cannot change the order of the deleted items,
|
||||
// and every deleted row carries a deletion time because the delete operation always sets it. All terms sort descending, so the filtered
|
||||
// (LibraryId, IsDeleted, DeletedOnUtc, Name, Id) index can be scanned backwards and the database does not build a temporary B-tree.
|
||||
.OrderByDescending(artist => artist.DeletedOnUtc)
|
||||
.ThenByDescending(artist => artist.Name)
|
||||
.ThenByDescending(artist => artist.Id)
|
||||
.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Soft deletes the artist identified by <paramref name="id"/>, without removing its stored metadata or artwork.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the artist to soft delete.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> SoftDeleteByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
ArtistEntity? artist = await _luminaDbContext.Artists.FirstOrDefaultAsync(repositoryArtist => repositoryArtist.Id == id, cancellationToken).ConfigureAwait(false);
|
||||
if (artist is null || artist.IsDeleted)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
|
||||
artist.IsDeleted = true;
|
||||
artist.DeletedOnUtc = _dateTimeProvider.UtcNow;
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores the soft deleted artist identified by <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the artist to restore.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> RestoreSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
ArtistEntity? artist = await _luminaDbContext.Artists.FirstOrDefaultAsync(repositoryArtist => repositoryArtist.Id == id, cancellationToken).ConfigureAwait(false);
|
||||
if (artist is null || !artist.IsDeleted)
|
||||
return Errors.Music.ArtistNotFound;
|
||||
|
||||
artist.IsDeleted = false;
|
||||
artist.DeletedOnUtc = null;
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes all the artists of the media library identified by <paramref name="libraryId"/>, together with their albums and tracks and their related data.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,6 +3,7 @@ using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MusicLibrary;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.Application.Common.DTO.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.DataAccess.Common.Persistence;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
@@ -26,14 +27,17 @@ namespace Lumina.DataAccess.Core.Repositories.MusicLibrary;
|
||||
internal sealed class TrackRepository : ITrackRepository
|
||||
{
|
||||
private readonly LuminaDbContext _luminaDbContext;
|
||||
private readonly IDateTimeProvider _dateTimeProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TrackRepository"/> class.
|
||||
/// </summary>
|
||||
/// <param name="luminaDbContext">Injected Entity Framework DbContext.</param>
|
||||
public TrackRepository(LuminaDbContext luminaDbContext)
|
||||
/// <param name="dateTimeProvider">Injected provider for the current UTC time, used to stamp deletions deterministically.</param>
|
||||
public TrackRepository(LuminaDbContext luminaDbContext, IDateTimeProvider dateTimeProvider)
|
||||
{
|
||||
_luminaDbContext = luminaDbContext;
|
||||
_dateTimeProvider = dateTimeProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -73,6 +77,10 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
/// <summary>
|
||||
/// Gets the subset of <paramref name="paths"/> that is already used by a track of the library identified by <paramref name="libraryId"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Soft deleted tracks are included on purpose: their paths must still count as taken, so that a scan never materializes a track that the user
|
||||
/// deleted back into the catalogue.
|
||||
/// </remarks>
|
||||
/// <param name="libraryId">The Id of the library whose tracks are searched.</param>
|
||||
/// <param name="paths">The track paths to check.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
@@ -113,7 +121,10 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
.Include(repositoryTrack => repositoryTrack.Moods)
|
||||
.Include(repositoryTrack => repositoryTrack.Isrcs)
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(repositoryTrack => repositoryTrack.Id == data.Id, cancellationToken).ConfigureAwait(false);
|
||||
.FirstOrDefaultAsync(repositoryTrack => repositoryTrack.Id == data.Id
|
||||
&& !repositoryTrack.IsDeleted
|
||||
&& !repositoryTrack.Album!.IsDeleted
|
||||
&& !repositoryTrack.Album!.Artist!.IsDeleted, cancellationToken).ConfigureAwait(false);
|
||||
if (foundTrack is null)
|
||||
return Errors.Music.TrackNotFound;
|
||||
|
||||
@@ -133,9 +144,17 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
// The stored identity is never overwritten by an edit, and the audit columns are only ever written by the auditing interceptor.
|
||||
Guid albumId = foundTrack.AlbumId;
|
||||
Guid libraryId = foundTrack.LibraryId;
|
||||
bool isDeleted = foundTrack.IsDeleted;
|
||||
DateTime? deletedOnUtc = foundTrack.DeletedOnUtc;
|
||||
EditableValuesCopier.CopyEditableValues(_luminaDbContext, foundTrack, data);
|
||||
foundTrack.AlbumId = albumId;
|
||||
foundTrack.LibraryId = libraryId;
|
||||
// The deletion state is owned by the explicit delete and restore operations. Clearing the modified flags keeps it out of the UPDATE statement,
|
||||
// so an edit that raced with a delete can never write the deletion state back and resurrect the track.
|
||||
foundTrack.IsDeleted = isDeleted;
|
||||
foundTrack.DeletedOnUtc = deletedOnUtc;
|
||||
_luminaDbContext.Entry(foundTrack).Property(track => track.IsDeleted).IsModified = false;
|
||||
_luminaDbContext.Entry(foundTrack).Property(track => track.DeletedOnUtc).IsModified = false;
|
||||
|
||||
// Tags and genres are shared across the whole database, so the stored rows whose names already exist are reused, and only the missing names are inserted.
|
||||
Result<Updated> reconcileTagsResult = await SharedReferenceResolver.ReconcileAsync(_luminaDbContext, foundTrack.Tags, data.Tags, Errors.Metadata.TagNameCannotBeEmpty, cancellationToken).ConfigureAwait(false);
|
||||
@@ -212,7 +231,9 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a <see cref="TrackEntity"/>, or an error.</returns>
|
||||
public async Task<Result<TrackEntity?>> GetByIdAsync(Guid id, bool shouldIncludeNavigationProperties = true, bool shouldTrackEntities = true, CancellationToken cancellationToken = default)
|
||||
{
|
||||
IQueryable<TrackEntity> query = _luminaDbContext.Tracks;
|
||||
// A deleted track, or a track of a deleted album or artist, is kept in the storage medium only so that its path stays reserved and it
|
||||
// can be restored, so it is never returned to a caller.
|
||||
IQueryable<TrackEntity> query = _luminaDbContext.Tracks.Where(track => !track.IsDeleted && !track.Album!.IsDeleted && !track.Album!.Artist!.IsDeleted);
|
||||
if (!shouldTrackEntities)
|
||||
query = query.AsNoTracking();
|
||||
if (shouldIncludeNavigationProperties)
|
||||
@@ -232,7 +253,7 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the tracks of the album identified by <paramref name="albumId"/>.
|
||||
/// Gets the tracks of the album identified by <paramref name="albumId"/> that are not soft deleted.
|
||||
/// </summary>
|
||||
/// <param name="albumId">The Id of the album whose tracks are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
@@ -247,8 +268,25 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
.Include(track => track.Isrcs)
|
||||
.Include(track => track.Contributors)
|
||||
.AsSplitQuery()
|
||||
.Where(track => track.AlbumId == albumId && !track.IsDeleted && !track.Album!.IsDeleted && !track.Album!.Artist!.IsDeleted)
|
||||
.OrderBy(track => track.DiscNumber ?? 1) // Some releases don't have a disc number, assume 1.
|
||||
.ThenBy(track => track.TrackNumber)
|
||||
.ThenBy(track => track.Id)
|
||||
.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the tracks of the album identified by <paramref name="albumId"/>, whether they are soft deleted or not.
|
||||
/// </summary>
|
||||
/// <param name="albumId">The Id of the album whose tracks are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of <see cref="TrackEntity"/>, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<TrackEntity>>> GetByAlbumIdIncludingDeletedAsync(Guid albumId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Tracks
|
||||
.AsNoTracking()
|
||||
.Where(track => track.AlbumId == albumId)
|
||||
.OrderBy(track => track.DiscNumber ?? 1) // some releases don't have a disc number, assume 1
|
||||
.OrderBy(track => track.DiscNumber ?? 1)
|
||||
.ThenBy(track => track.TrackNumber)
|
||||
.ThenBy(track => track.Id)
|
||||
.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
@@ -267,8 +305,8 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
// The lightweight read models are always retrieved without tracking, because they are never modified by the caller.
|
||||
IQueryable<TrackLiteRow> liteRowsQuery = _luminaDbContext.Tracks
|
||||
.AsNoTracking()
|
||||
.Where(track => track.AlbumId == albumId)
|
||||
.OrderBy(track => track.DiscNumber ?? 1) // some releases don't have a disc number, assume 1
|
||||
.Where(track => track.AlbumId == albumId && !track.IsDeleted && !track.Album!.IsDeleted && !track.Album!.Artist!.IsDeleted)
|
||||
.OrderBy(track => track.DiscNumber ?? 1) // Some releases don't have a disc number, assume 1.
|
||||
.ThenBy(track => track.TrackNumber)
|
||||
.ThenBy(track => track.Id)
|
||||
.Select(track => new TrackLiteRow(
|
||||
@@ -325,7 +363,7 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
{
|
||||
IQueryable<TrackEntity> query = _luminaDbContext.Tracks
|
||||
.AsNoTracking()
|
||||
.Where(track => track.LibraryId == libraryId);
|
||||
.Where(track => track.LibraryId == libraryId && !track.IsDeleted && !track.Album!.IsDeleted && !track.Album!.Artist!.IsDeleted);
|
||||
|
||||
if (artistId is not null)
|
||||
query = query.Where(track => track.Album!.ArtistId == artistId.Value);
|
||||
@@ -357,6 +395,10 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
/// <summary>
|
||||
/// Gets the track of the library identified by <paramref name="libraryId"/> that is stored at the provided <paramref name="path"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Soft deleted tracks are included on purpose: when the file disappears from disk, the scan deletion strategy must be able to permanently
|
||||
/// remove a track that the user had already deleted, instead of leaving its soft deleted row behind.
|
||||
/// </remarks>
|
||||
/// <param name="libraryId">The Id of the library whose track is retrieved.</param>
|
||||
/// <param name="path">The file system path of the track to retrieve.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
@@ -388,7 +430,13 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
// that is not in the named library, album and artist simply yields no row.
|
||||
return await _luminaDbContext.Tracks
|
||||
.AsNoTracking()
|
||||
.Where(track => track.Id == trackId && track.LibraryId == libraryId && track.AlbumId == albumId && track.Album!.ArtistId == artistId)
|
||||
.Where(track => track.Id == trackId
|
||||
&& track.LibraryId == libraryId
|
||||
&& track.AlbumId == albumId
|
||||
&& track.Album!.ArtistId == artistId
|
||||
&& !track.IsDeleted
|
||||
&& !track.Album!.IsDeleted
|
||||
&& !track.Album!.Artist!.IsDeleted)
|
||||
.Select(track => new TrackStreamDto(
|
||||
track.Path,
|
||||
track.LibraryId,
|
||||
@@ -424,7 +472,13 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
// that is not in the named library, album and artist simply yields no row.
|
||||
return await _luminaDbContext.Tracks
|
||||
.AsNoTracking()
|
||||
.Where(track => track.Id == trackId && track.LibraryId == libraryId && track.AlbumId == albumId && track.Album!.ArtistId == artistId)
|
||||
.Where(track => track.Id == trackId
|
||||
&& track.LibraryId == libraryId
|
||||
&& track.AlbumId == albumId
|
||||
&& track.Album!.ArtistId == artistId
|
||||
&& !track.IsDeleted
|
||||
&& !track.Album!.IsDeleted
|
||||
&& !track.Album!.Artist!.IsDeleted)
|
||||
.Select(track => new TrackPlaybackManifestDto(
|
||||
track.Path,
|
||||
track.Container,
|
||||
@@ -441,6 +495,89 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
.FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the soft deleted track identified by <paramref name="id"/>, when its album and artist are not soft deleted.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the soft deleted track to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted <see cref="TrackEntity"/>, <see langword="null"/> when the track does not exist, is not soft deleted, or its album or artist is soft deleted, or an error.</returns>
|
||||
public async Task<Result<TrackEntity?>> GetSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Tracks
|
||||
.AsNoTracking()
|
||||
.FirstOrDefaultAsync(track => track.Id == id
|
||||
&& track.IsDeleted
|
||||
&& !track.Album!.IsDeleted
|
||||
&& !track.Album!.Artist!.IsDeleted, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the soft deleted tracks of the media library identified by <paramref name="libraryId"/>, whose album and artist are not soft deleted.
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library whose soft deleted tracks are retrieved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the soft deleted tracks, or an error.</returns>
|
||||
public async Task<Result<IReadOnlyList<TrackEntity>>> GetSoftDeletedByLibraryIdAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Tracks
|
||||
.AsNoTracking()
|
||||
.Include(track => track.Album)
|
||||
.ThenInclude(album => album!.Artist)
|
||||
.Where(track => track.LibraryId == libraryId
|
||||
&& track.IsDeleted
|
||||
&& !track.Album!.IsDeleted
|
||||
&& !track.Album!.Artist!.IsDeleted)
|
||||
// The deletion time is stored when the track is deleted, so later writes to the hidden row cannot change the order of the deleted items,
|
||||
// and every deleted row carries a deletion time because the delete operation always sets it. All terms sort descending, so the filtered
|
||||
// (LibraryId, IsDeleted, DeletedOnUtc, Title, Id) index can be scanned backwards and the database does not build a temporary B-tree.
|
||||
.OrderByDescending(track => track.DeletedOnUtc)
|
||||
.ThenByDescending(track => track.Title)
|
||||
.ThenByDescending(track => track.Id)
|
||||
.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Soft deletes the track identified by <paramref name="id"/>, without removing its stored metadata or artwork.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The update is executed directly against the storage medium, so an entity already tracked by the caller is not refreshed, and the audit fields
|
||||
/// stamped by the change tracker are not updated; the deletion time is stored in <see cref="TrackEntity.DeletedOnUtc"/> instead.
|
||||
/// </remarks>
|
||||
/// <param name="id">The Id of the track to soft delete.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> SoftDeleteByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
DateTime deletedOnUtc = _dateTimeProvider.UtcNow;
|
||||
|
||||
// The update covers the existence check and the transition in one statement, so two concurrent deletes of the same track cannot both succeed.
|
||||
int updatedRows = await _luminaDbContext.Tracks
|
||||
.Where(track => track.Id == id && !track.IsDeleted)
|
||||
.ExecuteUpdateAsync(setters => setters
|
||||
.SetProperty(track => track.IsDeleted, true)
|
||||
.SetProperty(track => track.DeletedOnUtc, deletedOnUtc), cancellationToken).ConfigureAwait(false);
|
||||
if (updatedRows == 0)
|
||||
return Errors.Music.TrackNotFound;
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores the soft deleted track identified by <paramref name="id"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The Id of the track to restore.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public async Task<Result<Updated>> RestoreSoftDeletedByIdAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
TrackEntity? track = await _luminaDbContext.Tracks.FirstOrDefaultAsync(repositoryTrack => repositoryTrack.Id == id, cancellationToken).ConfigureAwait(false);
|
||||
if (track is null || !track.IsDeleted)
|
||||
return Errors.Music.TrackNotFound;
|
||||
|
||||
track.IsDeleted = false;
|
||||
track.DeletedOnUtc = null;
|
||||
return Result.Updated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the track identified by <paramref name="id"/>, together with its owned collections and contributions, by the database cascade.
|
||||
/// </summary>
|
||||
@@ -529,7 +666,11 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
public async Task<Result<int>> GetTracksNeedingMetadataCountAsync(Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Tracks
|
||||
.CountAsync(track => track.LibraryId == libraryId && track.MetadataStatus != MetadataStatus.Enriched, cancellationToken).ConfigureAwait(false);
|
||||
.CountAsync(track => track.LibraryId == libraryId
|
||||
&& !track.IsDeleted
|
||||
&& !track.Album!.IsDeleted
|
||||
&& !track.Album!.Artist!.IsDeleted
|
||||
&& track.MetadataStatus != MetadataStatus.Enriched, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -566,7 +707,7 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
{
|
||||
List<TrackLibraryCount> chunkCounts = await _luminaDbContext.Tracks
|
||||
.AsNoTracking()
|
||||
.Where(track => chunk.Contains(track.Id))
|
||||
.Where(track => chunk.Contains(track.Id) && !track.IsDeleted && !track.Album!.IsDeleted && !track.Album!.Artist!.IsDeleted)
|
||||
.GroupBy(track => track.LibraryId)
|
||||
.Select(group => new TrackLibraryCount
|
||||
{
|
||||
@@ -616,7 +757,7 @@ internal sealed class TrackRepository : ITrackRepository
|
||||
.Include(track => track.Contributors)
|
||||
.AsSplitQuery();
|
||||
}
|
||||
tracks.AddRange(await query.Where(track => chunk.Contains(track.Id)).ToListAsync(cancellationToken).ConfigureAwait(false));
|
||||
tracks.AddRange(await query.Where(track => chunk.Contains(track.Id) && !track.IsDeleted && !track.Album!.IsDeleted && !track.Album!.Artist!.IsDeleted).ToListAsync(cancellationToken).ConfigureAwait(false));
|
||||
}
|
||||
return Result.From<IReadOnlyList<TrackEntity>>(tracks);
|
||||
}
|
||||
|
||||
@@ -578,6 +578,9 @@ internal sealed class PlaylistRepository : IPlaylistRepository
|
||||
INNER JOIN Albums AS album ON album.Id = track.AlbumId
|
||||
INNER JOIN Artists AS artist ON artist.Id = album.ArtistId
|
||||
WHERE track.LibraryId = @libraryId
|
||||
AND track.IsDeleted = 0
|
||||
AND album.IsDeleted = 0
|
||||
AND artist.IsDeleted = 0
|
||||
""");
|
||||
if (artistId is not null)
|
||||
insertSql.Append(" AND album.ArtistId = @artistId");
|
||||
@@ -965,7 +968,7 @@ internal sealed class PlaylistRepository : IPlaylistRepository
|
||||
List<PlaylistEntryDisplayDto> chunkDetails = await (from track in _luminaDbContext.Tracks.AsNoTracking()
|
||||
join album in _luminaDbContext.Albums on track.AlbumId equals album.Id
|
||||
join artist in _luminaDbContext.Artists on album.ArtistId equals artist.Id
|
||||
where chunk.Contains(track.Id)
|
||||
where chunk.Contains(track.Id) && !track.IsDeleted && !album.IsDeleted && !artist.IsDeleted
|
||||
select new PlaylistEntryDisplayDto(
|
||||
track.Id,
|
||||
track.Title,
|
||||
|
||||
@@ -145,7 +145,7 @@ public class UnitOfWork : IUnitOfWork, IDisposable
|
||||
{
|
||||
get
|
||||
{
|
||||
_artistRepository ??= new ArtistRepository(_luminaDbContext, AlbumRepository, TrackRepository);
|
||||
_artistRepository ??= new ArtistRepository(_luminaDbContext, AlbumRepository, TrackRepository, _dateTimeProvider);
|
||||
return _artistRepository;
|
||||
}
|
||||
}
|
||||
@@ -157,7 +157,7 @@ public class UnitOfWork : IUnitOfWork, IDisposable
|
||||
{
|
||||
get
|
||||
{
|
||||
_albumRepository ??= new AlbumRepository(_luminaDbContext, TrackRepository);
|
||||
_albumRepository ??= new AlbumRepository(_luminaDbContext, TrackRepository, _dateTimeProvider);
|
||||
return _albumRepository;
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,7 @@ public class UnitOfWork : IUnitOfWork, IDisposable
|
||||
{
|
||||
get
|
||||
{
|
||||
_trackRepository ??= new TrackRepository(_luminaDbContext);
|
||||
_trackRepository ??= new TrackRepository(_luminaDbContext, _dateTimeProvider);
|
||||
return _trackRepository;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public static partial class Errors
|
||||
public static Error PathMustBeMaximum260CharactersLong => Error.Failure(description: nameof(PathMustBeMaximum260CharactersLong));
|
||||
public static Error FileCopyError => Error.Failure(description: nameof(FileCopyError));
|
||||
public static Error FileMoveError => Error.Failure(description: nameof(FileMoveError));
|
||||
public static Error FileDeleteError => Error.Failure(description: nameof(FileDeleteError));
|
||||
public static Error DirectoryCopyError => Error.Failure(description: nameof(DirectoryCopyError));
|
||||
public static Error DirectoryMoveError => Error.Failure(description: nameof(DirectoryMoveError));
|
||||
public static Error FileNotFound => Error.NotFound(description: nameof(FileNotFound));
|
||||
|
||||
+17
-4
@@ -433,6 +433,20 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
return Result.Created;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures the provided <paramref name="album"/> can be removed from the artist, without leaving the artist without albums.
|
||||
/// </summary>
|
||||
/// <param name="album">The album that is about to be removed or deleted.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful check, or an error.</returns>
|
||||
public Result<bool> CanRemoveAlbum(Album album)
|
||||
{
|
||||
if (!_albums.Contains(album))
|
||||
return Errors.Music.TheArtistDoesNotHaveTheAlbum;
|
||||
if (_albums.Count is 1)
|
||||
return Errors.Music.ArtistMustHaveAtLeastOneAlbum;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an album from the artist.
|
||||
/// </summary>
|
||||
@@ -440,10 +454,9 @@ public sealed class Artist : AggregateRoot<ArtistId>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Deleted> RemoveAlbum(Album album)
|
||||
{
|
||||
if (!_albums.Contains(album))
|
||||
return Errors.Music.TheArtistDoesNotHaveTheAlbum;
|
||||
if (_albums.Count is 1)
|
||||
return Errors.Music.ArtistMustHaveAtLeastOneAlbum;
|
||||
Result<bool> canRemoveAlbumResult = CanRemoveAlbum(album);
|
||||
if (canRemoveAlbumResult.IsFailure)
|
||||
return canRemoveAlbumResult.Errors;
|
||||
_albums.Remove(album);
|
||||
return Result.Deleted;
|
||||
}
|
||||
|
||||
+14
-2
@@ -284,7 +284,19 @@ internal class FileProviderService : IFileProviderService
|
||||
// Check if the user has access permissions to the provided path.
|
||||
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.Delete))
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
_fileSystem.File.Delete(path.Path);
|
||||
return Result.Deleted;
|
||||
try
|
||||
{
|
||||
_fileSystem.File.Delete(path.Path);
|
||||
return Result.Deleted;
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return Errors.Permission.UnauthorizedAccess;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
// A file that is locked by another process, or is read-only, cannot be deleted, but that must not abort the caller.
|
||||
return Errors.FileSystemManagement.FileDeleteError;
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -80,6 +80,15 @@ public interface IPathService
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the sanitized path segment, or an error.</returns>
|
||||
Result<PathSegment> SanitizeSegment(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Sanitizes a human-readable <paramref name="name"/> into a safe path segment that ends with <paramref name="identifier"/>,
|
||||
/// truncating only the name when the combined segment would exceed the maximum segment length.
|
||||
/// </summary>
|
||||
/// <param name="name">The human-readable name to sanitize.</param>
|
||||
/// <param name="identifier">The identifier that must be preserved at the end of the segment.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the sanitized path segment, or an error.</returns>
|
||||
Result<PathSegment> SanitizeCompositeSegment(string name, string identifier);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the root portion of the given path.
|
||||
/// </summary>
|
||||
|
||||
+21
@@ -185,6 +185,27 @@ public class PathService : IPathService
|
||||
return PathSegment.Create(sanitized, isDirectory: true, isDrive: false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sanitizes a human-readable <paramref name="name"/> into a safe path segment that ends with <paramref name="identifier"/>,
|
||||
/// truncating only the name when the combined segment would exceed the maximum segment length.
|
||||
/// </summary>
|
||||
/// <param name="name">The human-readable name to sanitize.</param>
|
||||
/// <param name="identifier">The identifier that must be preserved at the end of the segment.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing the sanitized path segment, or an error.</returns>
|
||||
public Result<PathSegment> SanitizeCompositeSegment(string name, string identifier)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(identifier))
|
||||
return Errors.FileSystemManagement.NameCannotBeEmpty;
|
||||
|
||||
// The identifier is the part that tells two items with the same name apart, so only the name is ever shortened to fit the limit.
|
||||
string suffix = $"-{identifier}";
|
||||
if (suffix.Length >= MAX_DIRECTORY_SEGMENT_LENGTH)
|
||||
return Errors.FileSystemManagement.InvalidPath;
|
||||
int nameLengthBudget = MAX_DIRECTORY_SEGMENT_LENGTH - suffix.Length;
|
||||
string nameWithinBudget = name.Length > nameLengthBudget ? name[..nameLengthBudget].TrimEnd() : name;
|
||||
return SanitizeSegment($"{nameWithinBudget}{suffix}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the root portion of the given path.
|
||||
/// </summary>
|
||||
|
||||
+30
-20
@@ -55,15 +55,16 @@ internal sealed class MusicArtworkService : IMusicArtworkService
|
||||
/// <param name="libraryId">The Id of the media library the album belongs to.</param>
|
||||
/// <param name="albumId">The Id of the album.</param>
|
||||
/// <param name="libraryName">The name of the media library the album belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist of the album.</param>
|
||||
/// <param name="artistName">The name of the artist of the album.</param>
|
||||
/// <param name="albumTitle">The title of the album.</param>
|
||||
/// <param name="artwork">The artwork to store.</param>
|
||||
/// <param name="releaseTypeName">The name of the release type directory the album is stored under on disk, used to group the artwork of the different releases of an artist. When <see langword="null"/>, no release type segment is added.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the relative path of the stored artwork, or an error.</returns>
|
||||
public async Task<Result<string>> SaveAlbumArtworkAsync(Guid libraryId, Guid albumId, string libraryName, string artistName, string albumTitle, ArtworkDto artwork, string? releaseTypeName, CancellationToken cancellationToken)
|
||||
public async Task<Result<string>> SaveAlbumArtworkAsync(Guid libraryId, Guid albumId, string libraryName, Guid artistId, string artistName, string albumTitle, ArtworkDto artwork, string? releaseTypeName, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<string> artworkDirectoryPathResult = BuildAlbumArtworkDirectoryPath(libraryId, albumId, libraryName, artistName, albumTitle, releaseTypeName);
|
||||
Result<string> artworkDirectoryPathResult = BuildAlbumArtworkDirectoryPath(libraryId, albumId, libraryName, artistId, artistName, albumTitle, releaseTypeName);
|
||||
if (artworkDirectoryPathResult.IsFailure)
|
||||
return artworkDirectoryPathResult.Errors;
|
||||
return await SaveArtworkAsync(artworkDirectoryPathResult.Value, artwork, cancellationToken).ConfigureAwait(false);
|
||||
@@ -74,13 +75,14 @@ internal sealed class MusicArtworkService : IMusicArtworkService
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library the artist belongs to.</param>
|
||||
/// <param name="libraryName">The name of the media library the artist belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist.</param>
|
||||
/// <param name="artistName">The name of the artist.</param>
|
||||
/// <param name="artwork">The artwork to store.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the relative path of the stored artwork, or an error.</returns>
|
||||
public async Task<Result<string>> SaveArtistArtworkAsync(Guid libraryId, string libraryName, string artistName, ArtworkDto artwork, CancellationToken cancellationToken)
|
||||
public async Task<Result<string>> SaveArtistArtworkAsync(Guid libraryId, string libraryName, Guid artistId, string artistName, ArtworkDto artwork, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<string> artworkDirectoryPathResult = BuildArtistArtworkDirectoryPath(libraryId, libraryName, artistName);
|
||||
Result<string> artworkDirectoryPathResult = BuildArtistArtworkDirectoryPath(libraryId, libraryName, artistId, artistName);
|
||||
if (artworkDirectoryPathResult.IsFailure)
|
||||
return artworkDirectoryPathResult.Errors;
|
||||
return await SaveArtworkAsync(artworkDirectoryPathResult.Value, artwork, cancellationToken).ConfigureAwait(false);
|
||||
@@ -92,6 +94,7 @@ internal sealed class MusicArtworkService : IMusicArtworkService
|
||||
/// <param name="libraryId">The Id of the media library the album belongs to.</param>
|
||||
/// <param name="albumId">The Id of the album.</param>
|
||||
/// <param name="libraryName">The name of the media library the album belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist of the album.</param>
|
||||
/// <param name="artistName">The name of the artist of the album.</param>
|
||||
/// <param name="albumTitle">The title of the album.</param>
|
||||
/// <param name="artwork">The stream of the uploaded artwork to store.</param>
|
||||
@@ -99,14 +102,14 @@ internal sealed class MusicArtworkService : IMusicArtworkService
|
||||
/// <param name="releaseTypeName">The name of the release type directory the album is stored under on disk, used to group the artwork of the different releases of an artist. When <see langword="null"/>, no release type segment is added.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the relative path of the stored artwork, or an error.</returns>
|
||||
public async Task<Result<string>> SaveAlbumArtworkAsync(Guid libraryId, Guid albumId, string libraryName, string artistName, string albumTitle, Stream artwork, string fileName, string? releaseTypeName, CancellationToken cancellationToken)
|
||||
public async Task<Result<string>> SaveAlbumArtworkAsync(Guid libraryId, Guid albumId, string libraryName, Guid artistId, string artistName, string albumTitle, Stream artwork, string fileName, string? releaseTypeName, CancellationToken cancellationToken)
|
||||
{
|
||||
// The uploaded bytes are persisted to a temporary file first, so that the storage pipeline can treat the upload like any other local artwork source and clean it up afterwards.
|
||||
string temporaryPath = BuildTemporaryUploadPath(fileName);
|
||||
try
|
||||
{
|
||||
await WriteUploadedArtworkAsync(artwork, temporaryPath, cancellationToken).ConfigureAwait(false);
|
||||
return await SaveAlbumArtworkAsync(libraryId, albumId, libraryName, artistName, albumTitle, new ArtworkDto(ArtworkType.Cover, 0, temporaryPath, null, IsTemporary: true), releaseTypeName, cancellationToken).ConfigureAwait(false);
|
||||
return await SaveAlbumArtworkAsync(libraryId, albumId, libraryName, artistId, artistName, albumTitle, new ArtworkDto(ArtworkType.Cover, 0, temporaryPath, null, IsTemporary: true), releaseTypeName, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -119,19 +122,20 @@ internal sealed class MusicArtworkService : IMusicArtworkService
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library the artist belongs to.</param>
|
||||
/// <param name="libraryName">The name of the media library the artist belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist.</param>
|
||||
/// <param name="artistName">The name of the artist.</param>
|
||||
/// <param name="artwork">The stream of the uploaded artwork to store.</param>
|
||||
/// <param name="fileName">The name of the uploaded artwork file.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the relative path of the stored artwork, or an error.</returns>
|
||||
public async Task<Result<string>> SaveArtistArtworkAsync(Guid libraryId, string libraryName, string artistName, Stream artwork, string fileName, CancellationToken cancellationToken)
|
||||
public async Task<Result<string>> SaveArtistArtworkAsync(Guid libraryId, string libraryName, Guid artistId, string artistName, Stream artwork, string fileName, CancellationToken cancellationToken)
|
||||
{
|
||||
// The uploaded bytes are persisted to a temporary file first, so that the storage pipeline can treat the upload like any other local artwork source and clean it up afterwards.
|
||||
string temporaryPath = BuildTemporaryUploadPath(fileName);
|
||||
try
|
||||
{
|
||||
await WriteUploadedArtworkAsync(artwork, temporaryPath, cancellationToken).ConfigureAwait(false);
|
||||
return await SaveArtistArtworkAsync(libraryId, libraryName, artistName, new ArtworkDto(ArtworkType.Cover, 0, temporaryPath, null, IsTemporary: true), cancellationToken).ConfigureAwait(false);
|
||||
return await SaveArtistArtworkAsync(libraryId, libraryName, artistId, artistName, new ArtworkDto(ArtworkType.Cover, 0, temporaryPath, null, IsTemporary: true), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -232,13 +236,14 @@ internal sealed class MusicArtworkService : IMusicArtworkService
|
||||
/// <param name="libraryId">The Id of the media library the album belongs to.</param>
|
||||
/// <param name="albumId">The Id of the album.</param>
|
||||
/// <param name="libraryName">The name of the media library the album belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist of the album.</param>
|
||||
/// <param name="artistName">The name of the artist of the album.</param>
|
||||
/// <param name="albumTitle">The title of the album.</param>
|
||||
/// <param name="releaseTypeName">The name of the release type directory the album is stored under on disk, used to group the artwork of the different releases of an artist. When omitted, no release type segment is added.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Deleted> DeleteAlbumArtwork(Guid libraryId, Guid albumId, string libraryName, string artistName, string albumTitle, string? releaseTypeName = null)
|
||||
public Result<Deleted> DeleteAlbumArtwork(Guid libraryId, Guid albumId, string libraryName, Guid artistId, string artistName, string albumTitle, string? releaseTypeName = null)
|
||||
{
|
||||
Result<string> artworkDirectoryPathResult = BuildAlbumArtworkDirectoryPath(libraryId, albumId, libraryName, artistName, albumTitle, releaseTypeName);
|
||||
Result<string> artworkDirectoryPathResult = BuildAlbumArtworkDirectoryPath(libraryId, albumId, libraryName, artistId, artistName, albumTitle, releaseTypeName);
|
||||
if (artworkDirectoryPathResult.IsFailure)
|
||||
return artworkDirectoryPathResult.Errors;
|
||||
return DeleteArtworkInDirectory(artworkDirectoryPathResult.Value);
|
||||
@@ -249,11 +254,12 @@ internal sealed class MusicArtworkService : IMusicArtworkService
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library the artist belongs to.</param>
|
||||
/// <param name="libraryName">The name of the media library the artist belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist.</param>
|
||||
/// <param name="artistName">The name of the artist.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
|
||||
public Result<Deleted> DeleteArtistArtwork(Guid libraryId, string libraryName, string artistName)
|
||||
public Result<Deleted> DeleteArtistArtwork(Guid libraryId, string libraryName, Guid artistId, string artistName)
|
||||
{
|
||||
Result<string> artworkDirectoryPathResult = BuildArtistArtworkDirectoryPath(libraryId, libraryName, artistName);
|
||||
Result<string> artworkDirectoryPathResult = BuildArtistArtworkDirectoryPath(libraryId, libraryName, artistId, artistName);
|
||||
if (artworkDirectoryPathResult.IsFailure)
|
||||
return artworkDirectoryPathResult.Errors;
|
||||
return DeleteArtworkInDirectory(artworkDirectoryPathResult.Value);
|
||||
@@ -281,8 +287,7 @@ internal sealed class MusicArtworkService : IMusicArtworkService
|
||||
if (!fileExistsResult.Value)
|
||||
return Result.Deleted;
|
||||
|
||||
_environmentContext.FileProviderService.DeleteFile(filePathIdResult.Value);
|
||||
return Result.Deleted;
|
||||
return _environmentContext.FileProviderService.DeleteFile(filePathIdResult.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -469,13 +474,14 @@ internal sealed class MusicArtworkService : IMusicArtworkService
|
||||
/// <param name="libraryId">The Id of the media library the album belongs to.</param>
|
||||
/// <param name="albumId">The Id of the album.</param>
|
||||
/// <param name="libraryName">The name of the media library the album belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist of the album.</param>
|
||||
/// <param name="artistName">The name of the artist of the album.</param>
|
||||
/// <param name="albumTitle">The title of the album.</param>
|
||||
/// <param name="releaseTypeName">The name of the release type directory the album is stored under on disk, or <see langword="null"/> to store the artwork directly under the artist directory.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the file system path of the album artwork directory, or an error.</returns>
|
||||
private Result<string> BuildAlbumArtworkDirectoryPath(Guid libraryId, Guid albumId, string libraryName, string artistName, string albumTitle, string? releaseTypeName)
|
||||
private Result<string> BuildAlbumArtworkDirectoryPath(Guid libraryId, Guid albumId, string libraryName, Guid artistId, string artistName, string albumTitle, string? releaseTypeName)
|
||||
{
|
||||
Result<string> artistPathResult = BuildArtistArtworkDirectoryPath(libraryId, libraryName, artistName);
|
||||
Result<string> artistPathResult = BuildArtistArtworkDirectoryPath(libraryId, libraryName, artistId, artistName);
|
||||
if (artistPathResult.IsFailure)
|
||||
return artistPathResult.Errors;
|
||||
|
||||
@@ -492,7 +498,7 @@ internal sealed class MusicArtworkService : IMusicArtworkService
|
||||
albumParentPathResult = releaseTypePathResult;
|
||||
}
|
||||
|
||||
Result<PathSegment> albumSegmentResult = _pathService.SanitizeSegment($"{albumTitle}-{albumId}");
|
||||
Result<PathSegment> albumSegmentResult = _pathService.SanitizeCompositeSegment(albumTitle, albumId.ToString());
|
||||
if (albumSegmentResult.IsFailure)
|
||||
return albumSegmentResult.Errors;
|
||||
return _pathService.CombinePath(albumParentPathResult.Value, albumSegmentResult.Value.Name);
|
||||
@@ -504,15 +510,19 @@ internal sealed class MusicArtworkService : IMusicArtworkService
|
||||
/// </summary>
|
||||
/// <param name="libraryId">The Id of the media library the artist belongs to.</param>
|
||||
/// <param name="libraryName">The name of the media library the artist belongs to.</param>
|
||||
/// <param name="artistId">The Id of the artist.</param>
|
||||
/// <param name="artistName">The name of the artist.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> containing either the file system path of the artist artwork directory, or an error.</returns>
|
||||
private Result<string> BuildArtistArtworkDirectoryPath(Guid libraryId, string libraryName, string artistName)
|
||||
private Result<string> BuildArtistArtworkDirectoryPath(Guid libraryId, string libraryName, Guid artistId, string artistName)
|
||||
{
|
||||
Result<string> libraryPathResult = BuildLibraryArtworkDirectoryPath(libraryId, libraryName);
|
||||
if (libraryPathResult.IsFailure)
|
||||
return libraryPathResult.Errors;
|
||||
|
||||
Result<PathSegment> artistSegmentResult = _pathService.SanitizeSegment(string.IsNullOrWhiteSpace(artistName) ? "Unknown" : artistName);
|
||||
// The Id is part of the segment because a deleted artist and a visible artist can share a name, and each must keep its own artwork.
|
||||
// The composite segment keeps the Id even when the name is long enough to need shortening.
|
||||
string resolvedArtistName = string.IsNullOrWhiteSpace(artistName) ? "Unknown" : artistName;
|
||||
Result<PathSegment> artistSegmentResult = _pathService.SanitizeCompositeSegment(resolvedArtistName, artistId.ToString());
|
||||
if (artistSegmentResult.IsFailure)
|
||||
return artistSegmentResult.Errors;
|
||||
return _pathService.CombinePath(libraryPathResult.Value, artistSegmentResult.Value.Name);
|
||||
@@ -533,7 +543,7 @@ internal sealed class MusicArtworkService : IMusicArtworkService
|
||||
if (musicPathResult.IsFailure)
|
||||
return musicPathResult.Errors;
|
||||
|
||||
Result<PathSegment> librarySegmentResult = _pathService.SanitizeSegment($"{libraryName}-{libraryId}");
|
||||
Result<PathSegment> librarySegmentResult = _pathService.SanitizeCompositeSegment(libraryName, libraryId.ToString());
|
||||
if (librarySegmentResult.IsFailure)
|
||||
return librarySegmentResult.Errors;
|
||||
return _pathService.CombinePath(musicPathResult.Value, librarySegmentResult.Value.Name);
|
||||
|
||||
+4
-4
@@ -329,8 +329,8 @@ internal sealed class MusicMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
||||
artworkProviders,
|
||||
musicArtworkService,
|
||||
fileHashService,
|
||||
() => musicArtworkService!.DeleteArtistArtwork(artistEntity.LibraryId, libraryName, artistName),
|
||||
(artwork, token) => musicArtworkService!.SaveArtistArtworkAsync(artistEntity.LibraryId, libraryName, artistName, artwork, token),
|
||||
() => musicArtworkService!.DeleteArtistArtwork(artistEntity.LibraryId, libraryName, artistEntity.Id, artistName),
|
||||
(artwork, token) => musicArtworkService!.SaveArtistArtworkAsync(artistEntity.LibraryId, libraryName, artistEntity.Id, artistName, artwork, token),
|
||||
shouldAggregateArtworkWhenMissing,
|
||||
unitOfWork,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
@@ -380,8 +380,8 @@ internal sealed class MusicMediaLibraryScanArtworkEnricher : IMediaLibraryScanAr
|
||||
artworkProviders,
|
||||
musicArtworkService,
|
||||
fileHashService,
|
||||
() => musicArtworkService!.DeleteAlbumArtwork(albumEntity.LibraryId, albumEntity.Id, libraryName, artistName, albumEntity.Title, releaseTypeName),
|
||||
(artwork, token) => musicArtworkService!.SaveAlbumArtworkAsync(albumEntity.LibraryId, albumEntity.Id, libraryName, artistName, albumEntity.Title, artwork, releaseTypeName, token),
|
||||
() => musicArtworkService!.DeleteAlbumArtwork(albumEntity.LibraryId, albumEntity.Id, libraryName, albumEntity.ArtistId, artistName, albumEntity.Title, releaseTypeName),
|
||||
(artwork, token) => musicArtworkService!.SaveAlbumArtworkAsync(albumEntity.LibraryId, albumEntity.Id, libraryName, albumEntity.ArtistId, artistName, albumEntity.Title, artwork, releaseTypeName, token),
|
||||
shouldAggregateArtworkWhenMissing,
|
||||
unitOfWork,
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
|
||||
+2
-2
@@ -327,13 +327,13 @@ internal sealed class BookArtworkService : IBookArtworkService
|
||||
if (booksPathResult.IsFailure)
|
||||
return booksPathResult.Errors;
|
||||
|
||||
Result<PathSegment> librarySegmentResult = _pathService.SanitizeSegment($"{libraryName}-{libraryId}");
|
||||
Result<PathSegment> librarySegmentResult = _pathService.SanitizeCompositeSegment(libraryName, libraryId.ToString());
|
||||
if (librarySegmentResult.IsFailure)
|
||||
return librarySegmentResult.Errors;
|
||||
Result<PathSegment> authorSegmentResult = _pathService.SanitizeSegment(string.IsNullOrWhiteSpace(authorName) ? "Unknown" : authorName);
|
||||
if (authorSegmentResult.IsFailure)
|
||||
return authorSegmentResult.Errors;
|
||||
Result<PathSegment> bookSegmentResult = _pathService.SanitizeSegment($"{bookTitle}-{bookId}");
|
||||
Result<PathSegment> bookSegmentResult = _pathService.SanitizeCompositeSegment(bookTitle, bookId.ToString());
|
||||
if (bookSegmentResult.IsFailure)
|
||||
return bookSegmentResult.Errors;
|
||||
|
||||
|
||||
+2
@@ -17,6 +17,8 @@ public static partial class ApiRoutes
|
||||
public const string UPDATE_ALBUM = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}";
|
||||
public const string UPDATE_ALBUM_COVER = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/cover";
|
||||
public const string DELETE_ALBUM = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}";
|
||||
public const string GET_DELETED_ALBUMS = "/libraries/{libraryId}/albums/deleted-items";
|
||||
public const string RESTORE_ALBUM = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/restore";
|
||||
public const string GET_ALBUM_TRACKS = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks";
|
||||
public const string GET_ALBUM_TRACKS_LITE = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite";
|
||||
}
|
||||
|
||||
+2
@@ -17,5 +17,7 @@ public static partial class ApiRoutes
|
||||
public const string UPDATE_ARTIST = "/libraries/{libraryId}/artists/{artistId}";
|
||||
public const string UPDATE_ARTIST_COVER = "/libraries/{libraryId}/artists/{artistId}/cover";
|
||||
public const string DELETE_ARTIST = "/libraries/{libraryId}/artists/{artistId}";
|
||||
public const string GET_DELETED_ARTISTS = "/libraries/{libraryId}/artists/deleted-items";
|
||||
public const string RESTORE_ARTIST = "/libraries/{libraryId}/artists/{artistId}/restore";
|
||||
}
|
||||
}
|
||||
+2
@@ -15,6 +15,8 @@ public static partial class ApiRoutes
|
||||
public const string SHUFFLE_TRACKS = "/libraries/{libraryId}/tracks/shuffle";
|
||||
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}";
|
||||
public const string GET_DELETED_TRACKS = "/libraries/{libraryId}/tracks/deleted-items";
|
||||
public const string RESTORE_TRACK = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/restore";
|
||||
public const string STREAM_TRACK = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/stream";
|
||||
public const string STREAM_TRACK_SEGMENT = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/stream/deliveries/{deliveryId}/segments/{segmentIndex}";
|
||||
public const string GET_PLAYBACK_MANIFEST = "/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/playback-manifest";
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ public class DeleteAlbumEndpointSummary : Summary<DeleteAlbumEndpoint, EmptyRequ
|
||||
public DeleteAlbumEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes an existing album.";
|
||||
Description = "Deletes the album identified by the route, together with its tracks. An artist must always keep at least one album. The album is deleted by an Admin, who can delete the albums of all libraries, or by the owner of the library of the album.";
|
||||
Description = "Soft deletes the album identified by the route, so its metadata, artwork and track paths are kept and the album can be restored. An artist must always keep at least one album, so the last album of an artist cannot be deleted. The album is deleted by an Admin, who can delete the albums of all libraries, or by the owner of the library of the album.";
|
||||
|
||||
Response(200, "The album was successfully deleted.");
|
||||
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Queries.GetDeletedAlbums;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetDeletedAlbums;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/albums/deleted-items</c> route.
|
||||
/// </summary>
|
||||
public class GetDeletedAlbumsEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetDeletedAlbumsQuery, Result<IReadOnlyList<DeletedAlbumResponse>>> _getDeletedAlbumsQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDeletedAlbumsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getDeletedAlbumsQueryHandler">Injected service for handling get deleted albums queries.</param>
|
||||
public GetDeletedAlbumsEndpoint(IQueryHandler<GetDeletedAlbumsQuery, Result<IReadOnlyList<DeletedAlbumResponse>>> getDeletedAlbumsQueryHandler)
|
||||
{
|
||||
_getDeletedAlbumsQueryHandler = getDeletedAlbumsQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Albums.GET_DELETED_ALBUMS);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the deleted albums of the library identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Take the unique identifier of the library from the route.
|
||||
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
|
||||
Result<IReadOnlyList<DeletedAlbumResponse>> result = await _getDeletedAlbumsQueryHandler.HandleAsync(new GetDeletedAlbumsQuery(libraryId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetDeletedAlbums;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetDeletedAlbumsEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDeletedAlbumsEndpointSummary : Summary<GetDeletedAlbumsEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDeletedAlbumsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetDeletedAlbumsEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the deleted albums of a media library.";
|
||||
Description = "Returns the albums of the media library identified by the route that the user deleted and that can still be restored, ordered by the time they were deleted, most recent first. An album whose artist is also deleted is not returned until the artist is restored. The list is returned to an Admin, who can see the deleted albums of all libraries, or to the owner of the library.";
|
||||
|
||||
ResponseParam<DeletedAlbumResponse>(response => response.Id, "The Id of the deleted album.");
|
||||
ResponseParam<DeletedAlbumResponse>(response => response.LibraryId, "The Id of the media library the deleted album belongs to.");
|
||||
ResponseParam<DeletedAlbumResponse>(response => response.ArtistId, "The Id of the artist the deleted album belongs to.");
|
||||
ResponseParam<DeletedAlbumResponse>(response => response.ArtistName, "The name of the artist the deleted album belongs to.");
|
||||
ResponseParam<DeletedAlbumResponse>(response => response.Title, "The title of the deleted album.");
|
||||
ResponseParam<DeletedAlbumResponse>(response => response.DeletedOnUtc, "The date and time when the album was deleted.");
|
||||
ResponseParam<DeletedAlbumResponse>(response => response.CoverPath, "The path of the cover image of the deleted album, if available.");
|
||||
|
||||
Response(200, "The deleted albums are returned.",
|
||||
example: new DeletedAlbumResponse[]
|
||||
{
|
||||
new(
|
||||
Id: Guid.Parse("b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e"),
|
||||
LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"),
|
||||
ArtistId: Guid.Parse("a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d"),
|
||||
ArtistName: "Queen",
|
||||
Title: "A Night at the Opera",
|
||||
DeletedOnUtc: DateTime.UtcNow,
|
||||
CoverPath: "/media/music/queen/a-night-at-the-opera/cover.jpg"
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/albums/deleted-items"
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/albums/deleted-items",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/albums/deleted-items",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.RestoreAlbum;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.RestoreAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/restore</c> route.
|
||||
/// </summary>
|
||||
public class RestoreAlbumEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<RestoreAlbumCommand, Result<Updated>> _restoreAlbumCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreAlbumEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="restoreAlbumCommandHandler">Injected service for handling restore album commands.</param>
|
||||
public RestoreAlbumEndpoint(ICommandHandler<RestoreAlbumCommand, Result<Updated>> restoreAlbumCommandHandler)
|
||||
{
|
||||
_restoreAlbumCommandHandler = restoreAlbumCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.Albums.RESTORE_ALBUM);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores the deleted album identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Take the unique identifiers from the route.
|
||||
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
|
||||
string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString();
|
||||
string? albumId = HttpContext.Request.RouteValues["albumId"]?.ToString();
|
||||
Result<Updated> result = await _restoreAlbumCommandHandler.HandleAsync(new RestoreAlbumCommand(libraryId, artistId, albumId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.RestoreAlbum;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="RestoreAlbumEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RestoreAlbumEndpointSummary : Summary<RestoreAlbumEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreAlbumEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public RestoreAlbumEndpointSummary()
|
||||
{
|
||||
Summary = "Restores a deleted album.";
|
||||
Description = "Restores the album identified by the route, together with its stored metadata, artwork and the tracks that were not deleted on their own. The album is restored by an Admin, who can restore the albums of all libraries, or by the owner of the library of the album.";
|
||||
|
||||
Response(200, "The album was successfully restored.");
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/restore"
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/restore",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the requested album does not exist, is not deleted, or its artist is deleted.", "application/problem+json",
|
||||
example: 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()}/restore",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/restore",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty",
|
||||
"ArtistIdCannotBeEmpty",
|
||||
"AlbumIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -19,7 +19,7 @@ public class DeleteArtistEndpointSummary : Summary<DeleteArtistEndpoint, EmptyRe
|
||||
public DeleteArtistEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes an existing artist.";
|
||||
Description = "Deletes the artist identified by the route, together with its albums and tracks. The artist is deleted by an Admin, who can delete the artists of all libraries, or by the owner of the library of the artist.";
|
||||
Description = "Soft deletes the artist identified by the route, so its metadata, artwork and track paths are kept and the artist can be restored. The artist is deleted by an Admin, who can delete the artists of all libraries, or by the owner of the library of the artist.";
|
||||
|
||||
Response(200, "The artist was successfully deleted.");
|
||||
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetDeletedArtists;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetDeletedArtists;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/deleted-items</c> route.
|
||||
/// </summary>
|
||||
public class GetDeletedArtistsEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetDeletedArtistsQuery, Result<IReadOnlyList<DeletedArtistResponse>>> _getDeletedArtistsQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDeletedArtistsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getDeletedArtistsQueryHandler">Injected service for handling get deleted artists queries.</param>
|
||||
public GetDeletedArtistsEndpoint(IQueryHandler<GetDeletedArtistsQuery, Result<IReadOnlyList<DeletedArtistResponse>>> getDeletedArtistsQueryHandler)
|
||||
{
|
||||
_getDeletedArtistsQueryHandler = getDeletedArtistsQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Artists.GET_DELETED_ARTISTS);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the deleted artists of the library identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Take the unique identifier of the library from the route.
|
||||
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
|
||||
Result<IReadOnlyList<DeletedArtistResponse>> result = await _getDeletedArtistsQueryHandler.HandleAsync(new GetDeletedArtistsQuery(libraryId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetDeletedArtists;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetDeletedArtistsEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDeletedArtistsEndpointSummary : Summary<GetDeletedArtistsEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDeletedArtistsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetDeletedArtistsEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the deleted artists of a media library.";
|
||||
Description = "Returns the artists of the media library identified by the route that the user deleted and that can still be restored, ordered by the time they were deleted, most recent first. The list is returned to an Admin, who can see the deleted artists of all libraries, or to the owner of the library.";
|
||||
|
||||
ResponseParam<DeletedArtistResponse>(response => response.Id, "The Id of the deleted artist.");
|
||||
ResponseParam<DeletedArtistResponse>(response => response.LibraryId, "The Id of the media library the deleted artist belongs to.");
|
||||
ResponseParam<DeletedArtistResponse>(response => response.Name, "The name of the deleted artist.");
|
||||
ResponseParam<DeletedArtistResponse>(response => response.DeletedOnUtc, "The date and time when the artist was deleted.");
|
||||
ResponseParam<DeletedArtistResponse>(response => response.CoverPath, "The path of the cover image of the deleted artist, if available.");
|
||||
|
||||
Response(200, "The deleted artists are returned.",
|
||||
example: new DeletedArtistResponse[]
|
||||
{
|
||||
new(
|
||||
Id: Guid.Parse("a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d"),
|
||||
LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"),
|
||||
Name: "Queen",
|
||||
DeletedOnUtc: DateTime.UtcNow,
|
||||
CoverPath: "/media/music/queen/cover.jpg"
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/deleted-items"
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/deleted-items",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/deleted-items",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.RestoreArtist;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.RestoreArtist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/restore</c> route.
|
||||
/// </summary>
|
||||
public class RestoreArtistEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<RestoreArtistCommand, Result<Updated>> _restoreArtistCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreArtistEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="restoreArtistCommandHandler">Injected service for handling restore artist commands.</param>
|
||||
public RestoreArtistEndpoint(ICommandHandler<RestoreArtistCommand, Result<Updated>> restoreArtistCommandHandler)
|
||||
{
|
||||
_restoreArtistCommandHandler = restoreArtistCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.Artists.RESTORE_ARTIST);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores the deleted artist identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Take the unique identifiers from the route.
|
||||
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
|
||||
string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString();
|
||||
Result<Updated> result = await _restoreArtistCommandHandler.HandleAsync(new RestoreArtistCommand(libraryId, artistId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.RestoreArtist;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="RestoreArtistEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RestoreArtistEndpointSummary : Summary<RestoreArtistEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreArtistEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public RestoreArtistEndpointSummary()
|
||||
{
|
||||
Summary = "Restores a deleted artist.";
|
||||
Description = "Restores the artist identified by the route, together with its stored metadata, artwork and the tracks that were not deleted on their own. The artist is restored by an Admin, who can restore the artists of all libraries, or by the owner of the library of the artist.";
|
||||
|
||||
Response(200, "The artist was successfully restored.");
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/restore"
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/restore",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the requested artist does not exist or is not deleted.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "ArtistNotFound",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/restore",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because a visible artist with the same name already exists in the library.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "ArtistAlreadyExists",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/restore",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/restore",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty",
|
||||
"ArtistIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -19,7 +19,7 @@ public class DeleteTrackEndpointSummary : Summary<DeleteTrackEndpoint, EmptyRequ
|
||||
public DeleteTrackEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes an existing track.";
|
||||
Description = "Deletes the track identified by the route. The track is deleted by an Admin, who can delete the tracks of all libraries, or by the owner of the library of the track.";
|
||||
Description = "Soft deletes the track identified by the route, so its metadata, artwork and file path are kept and the track can be restored. The track is deleted by an Admin, who can delete the tracks of all libraries, or by the owner of the library of the track.";
|
||||
|
||||
Response(200, "The track was successfully deleted.");
|
||||
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.GetDeletedTracks;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.GetDeletedTracks;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/tracks/deleted-items</c> route.
|
||||
/// </summary>
|
||||
public class GetDeletedTracksEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetDeletedTracksQuery, Result<IReadOnlyList<DeletedTrackResponse>>> _getDeletedTracksQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDeletedTracksEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getDeletedTracksQueryHandler">Injected service for handling get deleted tracks queries.</param>
|
||||
public GetDeletedTracksEndpoint(IQueryHandler<GetDeletedTracksQuery, Result<IReadOnlyList<DeletedTrackResponse>>> getDeletedTracksQueryHandler)
|
||||
{
|
||||
_getDeletedTracksQueryHandler = getDeletedTracksQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.Tracks.GET_DELETED_TRACKS);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the deleted tracks of the library identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Take the unique identifier of the library from the route.
|
||||
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
|
||||
Result<IReadOnlyList<DeletedTrackResponse>> result = await _getDeletedTracksQueryHandler.HandleAsync(new GetDeletedTracksQuery(libraryId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.GetDeletedTracks;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetDeletedTracksEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDeletedTracksEndpointSummary : Summary<GetDeletedTracksEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDeletedTracksEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetDeletedTracksEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves the deleted tracks of a media library.";
|
||||
Description = "Returns the tracks of the media library identified by the route that the user deleted and that can still be restored, ordered by the time they were deleted, most recent first. A track whose album or artist is also deleted is not returned until the album and the artist are restored. The list is returned to an Admin, who can see the deleted tracks of all libraries, or to the owner of the library.";
|
||||
|
||||
ResponseParam<DeletedTrackResponse>(response => response.Id, "The Id of the deleted track.");
|
||||
ResponseParam<DeletedTrackResponse>(response => response.LibraryId, "The Id of the media library the deleted track belongs to.");
|
||||
ResponseParam<DeletedTrackResponse>(response => response.ArtistId, "The Id of the artist the deleted track belongs to.");
|
||||
ResponseParam<DeletedTrackResponse>(response => response.ArtistName, "The name of the artist the deleted track belongs to.");
|
||||
ResponseParam<DeletedTrackResponse>(response => response.AlbumId, "The Id of the album the deleted track belongs to.");
|
||||
ResponseParam<DeletedTrackResponse>(response => response.AlbumTitle, "The title of the album the deleted track belongs to.");
|
||||
ResponseParam<DeletedTrackResponse>(response => response.Title, "The title of the deleted track.");
|
||||
ResponseParam<DeletedTrackResponse>(response => response.Path, "The file system path of the deleted track.");
|
||||
ResponseParam<DeletedTrackResponse>(response => response.DeletedOnUtc, "The date and time when the track was deleted.");
|
||||
|
||||
Response(200, "The deleted tracks are returned.",
|
||||
example: new DeletedTrackResponse[]
|
||||
{
|
||||
new(
|
||||
Id: Guid.Parse("c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f"),
|
||||
LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"),
|
||||
ArtistId: Guid.Parse("a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d"),
|
||||
ArtistName: "Queen",
|
||||
AlbumId: Guid.Parse("b2c3d4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e"),
|
||||
AlbumTitle: "A Night at the Opera",
|
||||
Title: "Bohemian Rhapsody",
|
||||
Path: "/music/queen/a-night-at-the-opera/01 - Bohemian Rhapsody.flac",
|
||||
DeletedOnUtc: DateTime.UtcNow
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/tracks/deleted-items"
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/tracks/deleted-items",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/tracks/deleted-items",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.RestoreTrack;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.RestoreTrack;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/restore</c> route.
|
||||
/// </summary>
|
||||
public class RestoreTrackEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<RestoreTrackCommand, Result<Updated>> _restoreTrackCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreTrackEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="restoreTrackCommandHandler">Injected service for handling restore track commands.</param>
|
||||
public RestoreTrackEndpoint(ICommandHandler<RestoreTrackCommand, Result<Updated>> restoreTrackCommandHandler)
|
||||
{
|
||||
_restoreTrackCommandHandler = restoreTrackCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.Tracks.RESTORE_TRACK);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores the deleted track identified by the route.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Take the unique identifiers from the route.
|
||||
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
|
||||
string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString();
|
||||
string? albumId = HttpContext.Request.RouteValues["albumId"]?.ToString();
|
||||
string? trackId = HttpContext.Request.RouteValues["trackId"]?.ToString();
|
||||
Result<Updated> result = await _restoreTrackCommandHandler.HandleAsync(new RestoreTrackCommand(libraryId, artistId, albumId, trackId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.RestoreTrack;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="RestoreTrackEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RestoreTrackEndpointSummary : Summary<RestoreTrackEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestoreTrackEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public RestoreTrackEndpointSummary()
|
||||
{
|
||||
Summary = "Restores a deleted track.";
|
||||
Description = "Restores the track identified by the route, together with its stored metadata and artwork. The track is restored by an Admin, who can restore the tracks of all libraries, or by the owner of the library of the track.";
|
||||
|
||||
Response(200, "The track was successfully restored.");
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Authentication failed",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}/restore"
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}/restore",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the requested track does not exist, is not deleted, or its album or artist is deleted.", "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()}/restore",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums/{Guid.NewGuid()}/tracks/{Guid.NewGuid()}/restore",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty",
|
||||
"ArtistIdCannotBeEmpty",
|
||||
"AlbumIdCannotBeEmpty",
|
||||
"TrackIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
+27
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a music album that the user deleted and can restore.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the deleted album.</param>
|
||||
/// <param name="LibraryId">The Id of the media library the deleted album belongs to.</param>
|
||||
/// <param name="ArtistId">The Id of the artist the deleted album belongs to.</param>
|
||||
/// <param name="ArtistName">The name of the artist the deleted album belongs to.</param>
|
||||
/// <param name="Title">The title of the deleted album.</param>
|
||||
/// <param name="DeletedOnUtc">The date and time when the album was deleted.</param>
|
||||
/// <param name="CoverPath">The relative path of the stored cover image of the deleted album, when it has one.</param>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public sealed record DeletedMusicAlbumDto(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
Guid ArtistId,
|
||||
string ArtistName,
|
||||
string Title,
|
||||
DateTime DeletedOnUtc,
|
||||
string? CoverPath
|
||||
);
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a music artist that the user deleted and can restore.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the deleted artist.</param>
|
||||
/// <param name="LibraryId">The Id of the media library the deleted artist belongs to.</param>
|
||||
/// <param name="Name">The name of the deleted artist.</param>
|
||||
/// <param name="DeletedOnUtc">The date and time when the artist was deleted.</param>
|
||||
/// <param name="CoverPath">The relative path of the stored cover image of the deleted artist, when it has one.</param>
|
||||
[DebuggerDisplay("Name: {Name}")]
|
||||
public sealed record DeletedMusicArtistDto(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
string Name,
|
||||
DateTime DeletedOnUtc,
|
||||
string? CoverPath
|
||||
);
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object carrying the data needed by the deleted items page of a music library.
|
||||
/// </summary>
|
||||
/// <param name="Library">The media library whose deleted music items are shown.</param>
|
||||
/// <param name="DeletedArtists">The deleted artists of the media library, ordered by the time they were deleted, most recent first.</param>
|
||||
/// <param name="DeletedAlbums">The deleted albums of the media library, ordered by the time they were deleted, most recent first.</param>
|
||||
/// <param name="DeletedTracks">The deleted tracks of the media library, ordered by the time they were deleted, most recent first.</param>
|
||||
public sealed record DeletedMusicItemsPageDto(
|
||||
LibraryDto Library,
|
||||
IReadOnlyList<DeletedMusicArtistDto> DeletedArtists,
|
||||
IReadOnlyList<DeletedMusicAlbumDto> DeletedAlbums,
|
||||
IReadOnlyList<DeletedMusicTrackDto> DeletedTracks
|
||||
);
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a music track that the user deleted and can restore.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the deleted track.</param>
|
||||
/// <param name="LibraryId">The Id of the media library the deleted track belongs to.</param>
|
||||
/// <param name="ArtistId">The Id of the artist the deleted track belongs to.</param>
|
||||
/// <param name="ArtistName">The name of the artist the deleted track belongs to.</param>
|
||||
/// <param name="AlbumId">The Id of the album the deleted track belongs to.</param>
|
||||
/// <param name="AlbumTitle">The title of the album the deleted track belongs to.</param>
|
||||
/// <param name="Title">The title of the deleted track.</param>
|
||||
/// <param name="Path">The file system path of the deleted track.</param>
|
||||
/// <param name="DeletedOnUtc">The date and time when the track was deleted.</param>
|
||||
[DebuggerDisplay("Title: {Title}")]
|
||||
public sealed record DeletedMusicTrackDto(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
Guid ArtistId,
|
||||
string ArtistName,
|
||||
Guid AlbumId,
|
||||
string AlbumTitle,
|
||||
string Title,
|
||||
string Path,
|
||||
DateTime DeletedOnUtc
|
||||
);
|
||||
@@ -15,16 +15,22 @@ public static partial class ApiRoutes
|
||||
public const string UPDATE_ARTIST = "libraries/{libraryId}/artists/{artistId}";
|
||||
public const string UPDATE_ARTIST_COVER = "libraries/{libraryId}/artists/{artistId}/cover";
|
||||
public const string DELETE_ARTIST = "libraries/{libraryId}/artists/{artistId}";
|
||||
public const string GET_DELETED_ARTISTS = "libraries/{libraryId}/artists/deleted-items";
|
||||
public const string RESTORE_ARTIST = "libraries/{libraryId}/artists/{artistId}/restore";
|
||||
public const string GET_ARTIST_ALBUMS_LITE = "libraries/{libraryId}/artists/{artistId}/albums/lite";
|
||||
public const string GET_ALBUM = "libraries/{libraryId}/artists/{artistId}/albums/{albumId}";
|
||||
public const string UPDATE_ALBUM = "libraries/{libraryId}/artists/{artistId}/albums/{albumId}";
|
||||
public const string UPDATE_ALBUM_COVER = "libraries/{libraryId}/artists/{artistId}/albums/{albumId}/cover";
|
||||
public const string DELETE_ALBUM = "libraries/{libraryId}/artists/{artistId}/albums/{albumId}";
|
||||
public const string GET_DELETED_ALBUMS = "libraries/{libraryId}/albums/deleted-items";
|
||||
public const string RESTORE_ALBUM = "libraries/{libraryId}/artists/{artistId}/albums/{albumId}/restore";
|
||||
public const string GET_ALBUM_TRACKS_LITE = "libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite";
|
||||
public const string SHUFFLE_TRACKS = "libraries/{libraryId}/tracks/shuffle";
|
||||
public const string GET_TRACK = "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}";
|
||||
public const string GET_DELETED_TRACKS = "libraries/{libraryId}/tracks/deleted-items";
|
||||
public const string RESTORE_TRACK = "libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/restore";
|
||||
public const string STREAM_TRACK = "libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/stream";
|
||||
public const string STREAM_TRACK_SEGMENT = "libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/stream/deliveries/{deliveryId}/segments/{segmentIndex}";
|
||||
public const string GET_PLAYBACK_MANIFEST = "libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/playback-manifest";
|
||||
|
||||
@@ -11,24 +11,28 @@ public static partial class WebRoutes
|
||||
public static class Music
|
||||
{
|
||||
public const string ARTISTS_INDEX = "{culture}/library/audio-library/music-library/artists";
|
||||
public const string DELETED_MUSIC_ITEMS = "{culture}/library/audio-library/music-library/deleted-items";
|
||||
public const string GET_ARTISTS = "{culture}/library/audio-library/music-library/artists/api-get-artists";
|
||||
public const string ARTIST = "{culture}/library/audio-library/music-library/artists/{artistId}";
|
||||
public const string GET_ARTIST = "{culture}/library/audio-library/music-library/artists/{artistId}/api-get-artist";
|
||||
public const string SAVE_ARTIST = "{culture}/library/audio-library/music-library/artists/{artistId}/api-save-artist";
|
||||
public const string UPDATE_ARTIST_COVER = "{culture}/library/audio-library/music-library/artists/{artistId}/api-update-cover";
|
||||
public const string DELETE_ARTIST = "{culture}/library/audio-library/music-library/artists/{artistId}/api-delete-artist";
|
||||
public const string RESTORE_ARTIST = "{culture}/library/audio-library/music-library/artists/{artistId}/api-restore-artist";
|
||||
public const string GET_ARTIST_ALBUMS = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/api-get-albums";
|
||||
public const string ALBUM = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}";
|
||||
public const string GET_ALBUM = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/api-get-album";
|
||||
public const string SAVE_ALBUM = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/api-save-album";
|
||||
public const string UPDATE_ALBUM_COVER = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/api-update-cover";
|
||||
public const string DELETE_ALBUM = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/api-delete-album";
|
||||
public const string RESTORE_ALBUM = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/api-restore-album";
|
||||
public const string GET_ALBUM_TRACKS = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/api-get-tracks";
|
||||
public const string SHUFFLE_TRACKS = "{culture}/library/audio-library/music-library/tracks/api-shuffle-tracks";
|
||||
public const string TRACK = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/{trackId}";
|
||||
public const string GET_TRACK = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/{trackId}/api-get-track";
|
||||
public const string SAVE_TRACK = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/{trackId}/api-save-track";
|
||||
public const string DELETE_TRACK = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/{trackId}/api-delete-track";
|
||||
public const string RESTORE_TRACK = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/{trackId}/api-restore-track";
|
||||
public const string STREAM_TRACK = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/{trackId}/api-stream-track";
|
||||
public const string STREAM_TRACK_SEGMENT = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/{trackId}/api-stream-track-segment/{deliveryId}/{segmentIndex}";
|
||||
public const string GET_PLAYBACK_MANIFEST = "{culture}/library/audio-library/music-library/artists/{artistId}/albums/{albumId}/tracks/{trackId}/api-get-playback-manifest";
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public class DeleteMusicAlbumEndpointSummary : Summary<DeleteMusicAlbumEndpoint>
|
||||
public DeleteMusicAlbumEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes a music album.";
|
||||
Description = "Deletes the music album identified by the route, together with its tracks.";
|
||||
Description = "Soft deletes the music album identified by the route, so its metadata, artwork and track paths are kept and the album can be restored.";
|
||||
|
||||
Response(200, "The music album was deleted.");
|
||||
}
|
||||
|
||||
Loaded 100 of 224 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user