Refactors the book, artist, and album slices across the stack

This commit is contained in:
BinaryAlley committed 2026-09-17 13:30:48 -07:00
1 parent 8aaf9fe64e
commit ea6eb9f796
439 files changed
+28235 -3156

No files matched your search

@@ -0,0 +1,57 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.AddAlbum;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.AddAlbum;
/// <summary>
/// API endpoint for the <c>/{libraryId}/artists/{artistId}/albums</c> route.
/// </summary>
public class AddAlbumEndpoint : BaseEndpoint<AddAlbumRequest, IResult>
{
private readonly ICommandHandler<AddAlbumCommand, Result<AlbumResponse>> _addAlbumCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="AddAlbumEndpoint"/> class.
/// </summary>
/// <param name="addAlbumCommandHandler">Injected service for handling add album commands.</param>
public AddAlbumEndpoint(ICommandHandler<AddAlbumCommand, Result<AlbumResponse>> addAlbumCommandHandler)
{
_addAlbumCommandHandler = addAlbumCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.POST);
Routes(ApiRoutes.Albums.ADD_ALBUM);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Adds an album stored in <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the album to be added.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(AddAlbumRequest request, CancellationToken cancellationToken)
{
// Take unique identifiers from the route.
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString();
Result<AlbumResponse> result = await _addAlbumCommandHandler.HandleAsync(request.ToCommand(libraryId, artistId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1/libraries/{libraryId}/artists/{artistId}/albums/{result.Value.Id}", result.Value), Problem);
}
}
@@ -0,0 +1,779 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.AddAlbum;
/// <summary>
/// Class used for providing a textual description for the <see cref="AddAlbumEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddAlbumEndpointSummary : Summary<AddAlbumEndpoint, AddAlbumRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="AddAlbumEndpointSummary"/> class.
/// </summary>
public AddAlbumEndpointSummary()
{
Summary = "Adds a new album to an artist.";
Description = "Creates a new album and returns its details, including the location of the newly created resource. The request is handled by an Admin, who can add albums to all libraries, or by the owner of the library.";
Guid artistId = Guid.NewGuid();
Guid albumId = Guid.NewGuid();
Guid libraryId = Guid.NewGuid();
ExampleRequest = new AddAlbumRequest(
Metadata: new(
Title: "A Night at the Opera",
OriginalTitle: "A Night at the Opera",
Description: "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.",
ReleaseInfo: new(
OriginalReleaseDate: new DateOnly(1975, 11, 21),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Remastered"
),
ReleaseType: MusicReleaseType.Album,
ReleaseStatus: MusicReleaseStatus.Official,
TotalDiscs: 1,
TotalTracks: 12,
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres:
[
new(Name: "Rock"),
new(Name: "Progressive Rock")
],
Tags:
[
new(Name: "classic"),
new(Name: "vinyl")
]
),
MediaFormat: MusicMediaFormat.CD,
Barcode: "0042282778329",
CatalogNumber: "EMC 4008",
MusicBrainzReleaseId: Guid.NewGuid(),
MusicBrainzReleaseGroupId: Guid.NewGuid(),
MusicBrainzReleaseArtistId: Guid.NewGuid(),
Contributors:
[
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Producer
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Engineer
)
],
Ratings:
[
new(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Tracks:
[
new(
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
Metadata: new(
Title: "Bohemian Rhapsody",
OriginalTitle: "Bohemian Rhapsody",
Description: "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
DurationInSeconds: 354,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 980,
ReleaseInfo: new(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres:
[
new(Name: "Rock"),
new(Name: "Progressive Rock")
],
Tags:
[
new(Name: "classic"),
new(Name: "epic")
]
),
TrackNumber: 1,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 72,
Work: "Bohemian Rhapsody",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
Contributors:
[
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings:
[
new(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Moods:
[
new(Name: "dramatic"),
new(Name: "anxious")
],
Isrcs:
[
new(Value: "GBUM71029604")
]
),
new(
Path: "/music/queen/a-night-at-the-opera/02-youre-my-best-friend.flac",
Metadata: new(
Title: "You're My Best Friend",
OriginalTitle: "You're My Best Friend",
Description: "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.",
DurationInSeconds: 181,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 912,
ReleaseInfo: new(
OriginalReleaseDate: new DateOnly(1976, 6, 18),
OriginalReleaseYear: 1976,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres:
[
new(Name: "Rock"),
new(Name: "Pop Rock")
],
Tags:
[
new(Name: "classic"),
new(Name: "love")
]
),
TrackNumber: 7,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.BMajor,
Bpm: 118,
Work: "You're My Best Friend",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
Contributors:
[
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.BassGuitar
)
],
Ratings:
[
new(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Moods:
[
new(Name: "happy"),
new(Name: "romantic")
],
Isrcs:
[
new(Value: "GBUM71029605")
]
)
]
);
RequestParam(r => r.Metadata, "The album metadata of the album. Required.");
RequestParam(r => r.Metadata!.Title, "The title of the album. Required.");
RequestParam(r => r.Metadata!.OriginalTitle, "The original title of the album. Optional.");
RequestParam(r => r.Metadata!.Description, "The description of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Required.");
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release or reissue year of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseType, "The type of the release. Optional.");
RequestParam(r => r.Metadata!.ReleaseStatus, "The status of the release. Optional.");
RequestParam(r => r.Metadata!.TotalDiscs, "The number of discs of the release. Optional.");
RequestParam(r => r.Metadata!.TotalTracks, "The number of tracks of the release. Optional.");
RequestParam(r => r.Metadata!.Language, "The language of the album. Optional.");
RequestParam(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the album. Required.");
RequestParam(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the album in English. Required.");
RequestParam(r => r.Metadata!.Language!.NativeName, "The native name of the language of the album. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage, "The original language of the album, if it has been translated. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the album. Required.");
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the album in English. Required.");
RequestParam(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the album. Optional.");
RequestParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album. Required.");
RequestParam(r => r.Metadata!.Genres, "The list of genres associated with the album. Required.");
RequestParam(r => r.MediaFormat, "The physical or digital medium of the album. Optional.");
RequestParam(r => r.Barcode, "The barcode of the album. Optional.");
RequestParam(r => r.CatalogNumber, "The catalog number of the album. Optional.");
RequestParam(r => r.MusicBrainzReleaseId, "The MusicBrainz identifier of the release. Optional.");
RequestParam(r => r.MusicBrainzReleaseGroupId, "The MusicBrainz identifier of the release group. Optional.");
RequestParam(r => r.MusicBrainzReleaseArtistId, "The MusicBrainz identifier of the release artist. Optional.");
RequestParam(r => r.Contributors, "The list of media contributors that performed on the album. Required.");
RequestParam(r => r.Ratings, "The list of ratings for this album. Required.");
RequestParam(r => r.Tracks, "The list of tracks of the album. Required.");
ResponseParam<AlbumResponse>(r => r.Id, "The Id of the album.");
ResponseParam<AlbumResponse>(r => r.ArtistId, "The Id of the artist the album belongs to.");
ResponseParam<AlbumResponse>(r => r.LibraryId, "The Id of the media library the album belongs to.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Title, "The title of the album.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalTitle, "The original title of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Description, "The description of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseType, "The type of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseStatus, "The status of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.TotalDiscs, "The number of discs of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.TotalTracks, "The number of tracks of the release.");
ResponseParam<AlbumResponse>(r => r.MediaFormat, "The physical or digital medium of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Barcode, "The barcode of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.CatalogNumber, "The catalog number of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.MusicBrainzReleaseId, "The MusicBrainz identifier of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.MusicBrainzReleaseGroupId, "The MusicBrainz identifier of the release group, if applicable.");
ResponseParam<AlbumResponse>(r => r.MusicBrainzReleaseArtistId, "The MusicBrainz identifier of the release artist, if applicable.");
ResponseParam<AlbumResponse>(r => r.CreatedOnUtc, "The date and time when the album was created.");
ResponseParam<AlbumResponse>(r => r.UpdatedOnUtc, "The date and time when the album was last updated, if applicable.");
ResponseParam<AlbumResponse>(r => r.Contributors, "The list of references to the media contributors that performed on the album, each with the role they played.");
ResponseParam<AlbumResponse>(r => r.Ratings, "The list of ratings for this album.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release or reissue year of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the album in English, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Language!.NativeName, "The native name of the language of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the album in English, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Genres, "The list of genres associated with the album.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album.");
ResponseParam<AlbumResponse>(r => r.Tracks, "The list of tracks of the album.");
Response(201, "The newly created album is returned.",
example: new AlbumResponse(
Id: albumId,
ArtistId: artistId,
LibraryId: libraryId,
Metadata: new(
Title: "A Night at the Opera",
OriginalTitle: "A Night at the Opera",
Description: "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.",
ReleaseInfo: new(
OriginalReleaseDate: new DateOnly(1975, 11, 21),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Remastered"
),
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres: [
new(Name: "Rock"),
new(Name: "Progressive Rock")
],
Tags: [
new(Name: "classic"),
new(Name: "vinyl")
],
ReleaseType: MusicReleaseType.Album,
ReleaseStatus: MusicReleaseStatus.Official,
TotalDiscs: 1,
TotalTracks: 12
),
MediaFormat: MusicMediaFormat.CD,
Barcode: "0042282778329",
CatalogNumber: "EMC 4008",
MusicBrainzReleaseId: Guid.NewGuid(),
MusicBrainzReleaseGroupId: Guid.NewGuid(),
MusicBrainzReleaseArtistId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default,
Contributors: [
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Producer
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Engineer
)
],
Ratings: [
new(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Tracks:
[
new(
Id: Guid.NewGuid(),
AlbumId: albumId,
LibraryId: libraryId,
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
Metadata: new(
Title: "Bohemian Rhapsody",
OriginalTitle: "Bohemian Rhapsody",
Description: "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
ReleaseInfo: new(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new(Name: "classic"),
new(Name: "epic")
],
Genres: [
new(Name: "Rock"),
new(Name: "Progressive Rock")
],
DurationInSeconds: 354,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 980
),
TrackNumber: 1,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 72,
Work: "Bohemian Rhapsody",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default,
Contributors: [
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings: [
new(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Moods: [
new(Name: "dramatic"),
new(Name: "anxious")
],
Isrcs: [
new(Value: "GBUM71029604")
]
),
new(
Id: Guid.NewGuid(),
AlbumId: albumId,
LibraryId: libraryId,
Path: "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac",
Metadata: new(
Title: "You're My Best Friend",
OriginalTitle: "You're My Best Friend",
Description: "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.",
ReleaseInfo: new(
OriginalReleaseDate: new DateOnly(1976, 6, 18),
OriginalReleaseYear: 1976,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new(Name: "classic"),
new(Name: "love")
],
Genres: [
new(Name: "Rock"),
new(Name: "Pop Rock")
],
DurationInSeconds: 181,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 912
),
TrackNumber: 7,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.BMajor,
Bpm: 118,
Work: "You're My Best Friend",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default,
Contributors: [
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings: [
new(
Value: 4.2M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 1234
),
new(
Value: 4.4M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 567
)
],
Moods: [
new(Name: "happy"),
new(Name: "warm")
],
Isrcs: [
new(Value: "GBUM71029609")
]
)
]
)
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
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"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token has expired",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums"
}
}
);
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",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested artist, its media library, or one of the referenced media contributors does not exist.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ArtistNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "MediaContributorNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
}
);
Response(409, "The request failed because an album with the same identity already exists, or because a unique constraint was violated.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
title = "General.Conflict",
status = 409,
detail = "AlbumAlreadyExists",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
title = "General.Conflict",
status = 409,
detail = "UniqueConstraintViolation",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}/albums",
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/{Guid.NewGuid()}/albums",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"ArtistIdCannotBeEmpty",
"MetadataCannotBeNull",
"AlbumTitleCannotBeEmpty",
"AlbumTitleMustBeMaximum255CharactersLong",
"OriginalTitleMustBeMaximum255CharactersLong",
"DescriptionMustBeMaximum2000CharactersLong",
"UnknownMusicReleaseType",
"UnknownMusicReleaseStatus",
"TotalDiscsMustBeGreaterThanZero",
"TotalTracksMustBeGreaterThanZero",
"ReleaseInfoCannotBeNull",
"OriginalReleaseYearMustBeBetween1And9999",
"ReReleaseYearMustBeBetween1And9999",
"ReleaseVersionMustBeMaximum50CharactersLong",
"OriginalReleaseDateAndYearMustMatch",
"ReReleaseDateAndYearMustMatch",
"ReReleaseYearCannotBeEarlierThanOriginalReleaseYear",
"ReReleaseDateCannotBeEarlierThanOriginalReleaseDate",
"GenresListCannotBeNull",
"GenreNameCannotBeEmpty",
"GenreNameMustBeMaximum50CharactersLong",
"TagsListCannotBeNull",
"TagNameCannotBeEmpty",
"TagNameMustBeMaximum50CharactersLong",
"LanguageCodeCannotBeEmpty",
"LanguageCodeMustBe2CharactersLong",
"LanguageNameCannotBeEmpty",
"LanguageNameMustBeMaximum50CharactersLong",
"LanguageNativeNameMustBeMaximum50CharactersLong",
"UnknownMusicMediaFormat",
"CatalogNumberMustBeMaximum50CharactersLong",
"MusicBrainzIdInvalidFormat",
"ContributorsListCannotBeNull",
"MediaContributorIdCannotBeEmpty",
"UnknownMediaContributorRole",
"RatingsListCannotBeNull",
"RatingValueMustBePositive",
"RatingValueCannotBeGreaterThanMaxValue",
"RatingMaxValueMustBePositive",
"RatingVoteCountMustBePositive",
"TracksListCannotBeNull",
"TrackPathCannotBeEmpty",
"TrackPathMustBeMaximum2048CharactersLong",
"TitleCannotBeEmpty",
"TitleMustBeMaximum255CharactersLong",
"TrackNumberMustBeGreaterThanZero",
"DiscNumberMustBeGreaterThanZero",
"ScriptMustBeMaximum50CharactersLong",
"UnknownMusicKey",
"BpmMustBeGreaterThanZero",
"WorkMustBeMaximum255CharactersLong",
"MoodNameCannotBeEmpty",
"IsrcValueCannotBeEmpty",
"TrackPathMustBeWithinLibraryContentLocations"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.DeleteAlbum;
using Lumina.Contracts.Requests.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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.DeleteAlbum;
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums/{albumId}</c> route.
/// </summary>
public class DeleteAlbumEndpoint : BaseEndpoint<DeleteAlbumRequest, IResult>
{
private readonly ICommandHandler<DeleteAlbumCommand, Result<Deleted>> _deleteAlbumCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="DeleteAlbumEndpoint"/> class.
/// </summary>
/// <param name="deleteAlbumCommandHandler">Injected service for handling delete album commands.</param>
public DeleteAlbumEndpoint(ICommandHandler<DeleteAlbumCommand, Result<Deleted>> deleteAlbumCommandHandler)
{
_deleteAlbumCommandHandler = deleteAlbumCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.DELETE);
Routes(ApiRoutes.Albums.DELETE_ALBUM);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Deletes an album by Id.
/// </summary>
/// <param name="request">The request containing the id of the album to be deleted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(DeleteAlbumRequest request, CancellationToken cancellationToken)
{
Result<Deleted> result = await _deleteAlbumCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,110 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.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.DeleteAlbum;
/// <summary>
/// Class used for providing a textual description for the <see cref="DeleteAlbumEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteAlbumEndpointSummary : Summary<DeleteAlbumEndpoint, DeleteAlbumRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="DeleteAlbumEndpointSummary"/> class.
/// </summary>
public DeleteAlbumEndpointSummary()
{
Summary = "Deletes an existing album.";
Description = "Deletes the album identified by the request, together with its tracks. 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.";
ExampleRequest = new DeleteAlbumRequest(
ArtistId: Guid.NewGuid(),
AlbumId: Guid.NewGuid()
);
RequestParam(r => r.ArtistId, "The unique identifier of the artist the album belongs to, taken from the route.");
RequestParam(r => r.AlbumId, "The Id of the album to delete, taken from the route. Required.");
Response(200, "The album was successfully deleted.");
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
}
}
);
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/{libraryId}/artists/{artistId}/albums/{albumId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested album does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "AlbumNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}",
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/{libraryId}/artists/{artistId}/albums/{albumId}",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"AlbumIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Queries.GetAlbum;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetAlbum;
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums/{albumId}</c> route.
/// </summary>
public class GetAlbumEndpoint : BaseEndpoint<GetAlbumRequest, IResult>
{
private readonly IQueryHandler<GetAlbumQuery, Result<AlbumResponse>> _getAlbumQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetAlbumEndpoint"/> class.
/// </summary>
/// <param name="getAlbumQueryHandler">Injected service for handling get album queries.</param>
public GetAlbumEndpoint(IQueryHandler<GetAlbumQuery, Result<AlbumResponse>> getAlbumQueryHandler)
{
_getAlbumQueryHandler = getAlbumQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Albums.GET_ALBUM_BY_ID);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets an album by Id.
/// </summary>
/// <param name="request">The request containing the id of the album to be retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetAlbumRequest request, CancellationToken cancellationToken)
{
Result<AlbumResponse> result = await _getAlbumQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,228 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetAlbum;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetAlbumEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetAlbumEndpointSummary : Summary<GetAlbumEndpoint, GetAlbumRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetAlbumEndpointSummary"/> class.
/// </summary>
public GetAlbumEndpointSummary()
{
Summary = "Gets an album by its Id.";
Description = "Returns the full details of the album identified by the request. The album is returned to an Admin, who can see the albums of all libraries, or to the owner of the library of the album.";
ExampleRequest = new GetAlbumRequest(
ArtistId: Guid.NewGuid(),
AlbumId: Guid.NewGuid()
);
RequestParam(r => r.ArtistId, "The unique identifier of the artist the album belongs to, taken from the route.");
RequestParam(r => r.AlbumId, "The Id of the album to get. Required.");
ResponseParam<AlbumResponse>(r => r.Id, "The Id of the album.");
ResponseParam<AlbumResponse>(r => r.ArtistId, "The Id of the artist the album belongs to.");
ResponseParam<AlbumResponse>(r => r.LibraryId, "The Id of the media library the album belongs to.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Title, "The title of the album.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalTitle, "The original title of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Description, "The description of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseType, "The type of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseStatus, "The status of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.TotalDiscs, "The number of discs of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.TotalTracks, "The number of tracks of the release.");
ResponseParam<AlbumResponse>(r => r.MediaFormat, "The physical or digital medium of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Barcode, "The barcode of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.CatalogNumber, "The catalog number of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.MusicBrainzReleaseId, "The MusicBrainz identifier of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.MusicBrainzReleaseGroupId, "The MusicBrainz identifier of the release group, if applicable.");
ResponseParam<AlbumResponse>(r => r.MusicBrainzReleaseArtistId, "The MusicBrainz identifier of the release artist, if applicable.");
ResponseParam<AlbumResponse>(r => r.CreatedOnUtc, "The date and time when the album was created.");
ResponseParam<AlbumResponse>(r => r.UpdatedOnUtc, "The date and time when the album was last updated, if applicable.");
ResponseParam<AlbumResponse>(r => r.Contributors, "The list of references to the media contributors that performed on the album, each with the role they played.");
ResponseParam<AlbumResponse>(r => r.Ratings, "The list of ratings for this album.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release or reissue year of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the album in English, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Language!.NativeName, "The native name of the language of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the album in English, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Genres, "The list of genres associated with the album.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album.");
ResponseParam<AlbumResponse>(r => r.Tracks, "The list of tracks of the album.");
Response(200, "The requested album is returned.",
example: new AlbumResponse(
Id: Guid.NewGuid(),
ArtistId: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Metadata: new AlbumMetadataDto(
Title: "A Night at the Opera",
OriginalTitle: "A Night at the Opera",
Description: "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 11, 21),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Remastered"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres: [
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
Tags: [
new TagDto(Name: "classic"),
new TagDto(Name: "vinyl")
],
ReleaseType: MusicReleaseType.Album,
ReleaseStatus: MusicReleaseStatus.Official,
TotalDiscs: 1,
TotalTracks: 12
),
MediaFormat: MusicMediaFormat.CD,
Barcode: "0042282778329",
CatalogNumber: "EMC 4008",
MusicBrainzReleaseId: Guid.NewGuid(),
MusicBrainzReleaseGroupId: Guid.NewGuid(),
MusicBrainzReleaseArtistId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow,
Contributors: [
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Producer
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Engineer
)
],
Ratings: [
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Tracks: []
)
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
}
}
);
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/{libraryId}/artists/{artistId}/albums/{albumId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested album does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "AlbumNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}",
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/{libraryId}/artists/{artistId}/albums/{albumId}",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"AlbumIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Queries.GetAlbumTracks;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
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.Albums.GetAlbumTracks;
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums/{albumId}/tracks</c> route.
/// </summary>
public class GetAlbumTracksEndpoint : BaseEndpoint<GetAlbumTracksRequest, IResult>
{
private readonly IQueryHandler<GetAlbumTracksQuery, Result<IReadOnlyList<TrackResponse>>> _getAlbumTracksQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetAlbumTracksEndpoint"/> class.
/// </summary>
/// <param name="getAlbumTracksQueryHandler">Injected service for handling get album tracks queries.</param>
public GetAlbumTracksEndpoint(IQueryHandler<GetAlbumTracksQuery, Result<IReadOnlyList<TrackResponse>>> getAlbumTracksQueryHandler)
{
_getAlbumTracksQueryHandler = getAlbumTracksQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Albums.GET_ALBUM_TRACKS);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the list of all the tracks of the album identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the id of the album whose tracks are retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetAlbumTracksRequest request, CancellationToken cancellationToken)
{
Result<IReadOnlyList<TrackResponse>> result = await _getAlbumTracksQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,335 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetAlbumTracks;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetAlbumTracksEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetAlbumTracksEndpointSummary : Summary<GetAlbumTracksEndpoint, GetAlbumTracksRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetAlbumTracksEndpointSummary"/> class.
/// </summary>
public GetAlbumTracksEndpointSummary()
{
Summary = "Retrieves the list of tracks of an album.";
Description = "Returns the full details of the tracks of the album identified by the request. The list is returned to an Admin, who can see the tracks of the albums of all libraries, or to the owner of the library of the album.";
ExampleRequest = new GetAlbumTracksRequest(
ArtistId: Guid.NewGuid(),
AlbumId: Guid.NewGuid()
);
RequestParam(r => r.ArtistId, "The unique identifier of the artist the album belongs to, taken from the route.");
RequestParam(r => r.AlbumId, "The Id of the album whose tracks are retrieved, taken from the route. Required.");
ResponseParam<TrackResponse>(r => r.Id, "The Id of the track.");
ResponseParam<TrackResponse>(r => r.AlbumId, "The Id of the album the track belongs to.");
ResponseParam<TrackResponse>(r => r.LibraryId, "The Id of the media library the track belongs to.");
ResponseParam<TrackResponse>(r => r.Path, "The file system path of the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.Title, "The title of the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalTitle, "The original title of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Description, "The description of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.TrackNumber, "The number of the track on its disc.");
ResponseParam<TrackResponse>(r => r.DiscNumber, "The number of the disc the track belongs to, if applicable.");
ResponseParam<TrackResponse>(r => r.Script, "The script used by the language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Key, "The musical key of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Bpm, "The tempo of the track in beats per minute, if applicable.");
ResponseParam<TrackResponse>(r => r.Work, "The title of the work the track is a recording of, if applicable.");
ResponseParam<TrackResponse>(r => r.MusicBrainzRecordingId, "The MusicBrainz identifier of the recording, if applicable.");
ResponseParam<TrackResponse>(r => r.MusicBrainzTrackId, "The MusicBrainz identifier of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
ResponseParam<TrackResponse>(r => r.CreatedOnUtc, "The date and time when the track was created.");
ResponseParam<TrackResponse>(r => r.UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
ResponseParam<TrackResponse>(r => r.Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
ResponseParam<TrackResponse>(r => r.Ratings, "The list of ratings for this track.");
ResponseParam<TrackResponse>(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
ResponseParam<TrackResponse>(r => r.Metadata!.SampleRate, "The sample rate of the audio of the track in Hz.");
ResponseParam<TrackResponse>(r => r.Metadata!.Channels, "The number of audio channels of the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.BitDepth, "The bit depth of the audio of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.AudioCodec, "The audio codec used by the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Bitrate, "The bitrate of the audio of the track in kbps, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release or reissue year of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the track in English, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Language!.NativeName, "The native name of the language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the track in English, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Genres, "The list of genres associated with the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track.");
ResponseParam<TrackResponse>(r => r.Moods, "The list of moods of the track.");
ResponseParam<TrackResponse>(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
Response(200, "The list of tracks of the album is returned.",
example: new TrackResponse[]
{
new TrackResponse(
Id: Guid.NewGuid(),
AlbumId: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
Metadata: new AudioMetadataDto(
Title: "Bohemian Rhapsody",
OriginalTitle: "Bohemian Rhapsody",
Description: "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new TagDto(Name: "classic"),
new TagDto(Name: "epic")
],
Genres: [
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
DurationInSeconds: 354,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 980
),
TrackNumber: 1,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 72,
Work: "Bohemian Rhapsody",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow,
Contributors: [
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings: [
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Moods: [
new MoodDto(Name: "dramatic"),
new MoodDto(Name: "anxious")
],
Isrcs: [
new IsrcDto(Value: "GBUM71029604")
]
),
new TrackResponse(
Id: Guid.NewGuid(),
AlbumId: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Path: "/music/queen/a-night-at-the-opera/02-youre-my-best-friend.flac",
Metadata: new AudioMetadataDto(
Title: "You're My Best Friend",
OriginalTitle: "You're My Best Friend",
Description: "A song by the British rock band Queen, written by bass guitarist John Deacon. It was released as the second single from the album A Night at the Opera in 1975.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new TagDto(Name: "classic"),
new TagDto(Name: "love")
],
Genres: [
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Pop Rock")
],
DurationInSeconds: 174,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 912
),
TrackNumber: 2,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 110,
Work: "You're My Best Friend",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow,
Contributors: [
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings: [
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Moods: [
new MoodDto(Name: "happy"),
new MoodDto(Name: "romantic")
],
Isrcs: [
new IsrcDto(Value: "GBUM71029605")
]
)
}
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks"
}
}
);
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/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested album does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "AlbumNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
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/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"AlbumIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Queries.GetAlbumTracksLite;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Contracts.Responses.Common;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.GetAlbumTracksLite;
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums/{albumId}/tracks/lite</c> route.
/// </summary>
public class GetAlbumTracksLiteEndpoint : BaseEndpoint<GetAlbumTracksLiteRequest, IResult>
{
private readonly IQueryHandler<GetAlbumTracksLiteQuery, Result<PaginatedResponse<TrackLiteResponse>>> _getAlbumTracksLiteQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetAlbumTracksLiteEndpoint"/> class.
/// </summary>
/// <param name="getAlbumTracksLiteQueryHandler">Injected service for handling get album tracks lite queries.</param>
public GetAlbumTracksLiteEndpoint(IQueryHandler<GetAlbumTracksLiteQuery, Result<PaginatedResponse<TrackLiteResponse>>> getAlbumTracksLiteQueryHandler)
{
_getAlbumTracksLiteQueryHandler = getAlbumTracksLiteQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Albums.GET_ALBUM_TRACKS_LITE);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the lightweight read models of all the tracks of the album identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the id of the album whose tracks are retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetAlbumTracksLiteRequest request, CancellationToken cancellationToken)
{
Result<PaginatedResponse<TrackLiteResponse>> result = await _getAlbumTracksLiteQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,144 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Contracts.Responses.Common;
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.Albums.GetAlbumTracksLite;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetAlbumTracksLiteEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetAlbumTracksLiteEndpointSummary : Summary<GetAlbumTracksLiteEndpoint, GetAlbumTracksLiteRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetAlbumTracksLiteEndpointSummary"/> class.
/// </summary>
public GetAlbumTracksLiteEndpointSummary()
{
Summary = "Retrieves the lightweight read models of the tracks of an album.";
Description = "Returns the lightweight read models of the tracks of the album identified by its Id, projecting only the fields needed to display the songs of an album, without loading the full track entities and their related data. The page is returned to an Admin, who can see the tracks of the albums of all libraries, or to the owner of the library of the album.";
ExampleRequest = new GetAlbumTracksLiteRequest(
ArtistId: Guid.NewGuid(),
AlbumId: Guid.NewGuid(),
CurrentPage: 1,
PerPage: 48
);
RequestParam(r => r.ArtistId, "The unique identifier of the artist the album belongs to, taken from the route.");
RequestParam(r => r.AlbumId, "The Id of the album whose tracks are retrieved. Required.");
RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional.");
RequestParam(r => r.PerPage, "The maximum number of tracks to retrieve per page. Optional.");
ResponseParam<TrackLiteResponse>(r => r.Id, "The Id of the track.");
ResponseParam<TrackLiteResponse>(r => r.Title, "The title of the track.");
ResponseParam<TrackLiteResponse>(r => r.TrackNumber, "The number of the track on its disc.");
ResponseParam<TrackLiteResponse>(r => r.DiscNumber, "The number of the disc the track belongs to, if applicable.");
Response(200, "The paginated list of the lightweight read models of the tracks of the album is returned.",
example: new PaginatedResponse<TrackLiteResponse>
{
Data =
[
new TrackLiteResponse(
Id: Guid.NewGuid(),
Title: "Bohemian Rhapsody",
TrackNumber: 1,
DiscNumber: 1
),
new TrackLiteResponse(
Id: Guid.NewGuid(),
Title: "You're My Best Friend",
TrackNumber: 2,
DiscNumber: 1
)
],
CurrentPage = 1,
PerPage = 10,
Count = 2,
NumberOfPages = 1
}
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite"
}
}
);
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/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested album does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "AlbumNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite",
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/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/lite",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"AlbumIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,58 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Albums.Commands.UpdateAlbum;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.UpdateAlbum;
/// <summary>
/// API endpoint for the <c>/{libraryId}/artists/{artistId}/albums/{albumId}</c> route.
/// </summary>
public class UpdateAlbumEndpoint : BaseEndpoint<UpdateAlbumRequest, IResult>
{
private readonly ICommandHandler<UpdateAlbumCommand, Result<AlbumResponse>> _updateAlbumCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="UpdateAlbumEndpoint"/> class.
/// </summary>
/// <param name="updateAlbumCommandHandler">Injected service for handling update album commands.</param>
public UpdateAlbumEndpoint(ICommandHandler<UpdateAlbumCommand, Result<AlbumResponse>> updateAlbumCommandHandler)
{
_updateAlbumCommandHandler = updateAlbumCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.PUT);
Routes(ApiRoutes.Albums.UPDATE_ALBUM);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Updates an album stored in <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the album to be updated.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(UpdateAlbumRequest request, CancellationToken cancellationToken)
{
// Take 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<AlbumResponse> result = await _updateAlbumCommandHandler.HandleAsync(request.ToCommand(libraryId, artistId, albumId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,388 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Albums.UpdateAlbum;
/// <summary>
/// Class used for providing a textual description for the <see cref="UpdateAlbumEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdateAlbumEndpointSummary : Summary<UpdateAlbumEndpoint, UpdateAlbumRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="UpdateAlbumEndpointSummary"/> class.
/// </summary>
public UpdateAlbumEndpointSummary()
{
Summary = "Updates an existing album.";
Description = "Updates the details of the album identified by the request, returning the full details of the updated album. The tracks of the album are left untouched. The album is updated by an Admin, who can update the albums of all libraries, or by the owner of the library of the album.";
ExampleRequest = new UpdateAlbumRequest(
Metadata: new AlbumMetadataDto(
Title: "A Night at the Opera",
OriginalTitle: "A Night at the Opera",
Description: "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 11, 21),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Remastered"
),
ReleaseType: MusicReleaseType.Album,
ReleaseStatus: MusicReleaseStatus.Official,
TotalDiscs: 1,
TotalTracks: 12,
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres:
[
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
Tags:
[
new TagDto(Name: "classic"),
new TagDto(Name: "vinyl")
]
),
MediaFormat: MusicMediaFormat.CD,
Barcode: "0042282778329",
CatalogNumber: "EMC 4008",
MusicBrainzReleaseId: Guid.NewGuid(),
MusicBrainzReleaseGroupId: Guid.NewGuid(),
MusicBrainzReleaseArtistId: Guid.NewGuid(),
Contributors:
[
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Producer
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Engineer
)
],
Ratings:
[
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
]
);
RequestParam(r => r.Metadata, "The album metadata of the album. Required.");
RequestParam(r => r.Metadata!.Title, "The title of the album. Required.");
RequestParam(r => r.Metadata!.OriginalTitle, "The original title of the album. Optional.");
RequestParam(r => r.Metadata!.Description, "The description of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release or reissue year of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the album. Optional.");
RequestParam(r => r.Metadata!.ReleaseType, "The type of the release. Optional.");
RequestParam(r => r.Metadata!.ReleaseStatus, "The status of the release. Optional.");
RequestParam(r => r.Metadata!.TotalDiscs, "The number of discs of the release. Optional.");
RequestParam(r => r.Metadata!.TotalTracks, "The number of tracks of the release. Optional.");
RequestParam(r => r.Metadata!.Language, "The language of the album. Optional.");
RequestParam(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the album. Optional.");
RequestParam(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the album in English. Optional.");
RequestParam(r => r.Metadata!.Language!.NativeName, "The native name of the language of the album. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage, "The original language of the album, if it has been translated. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the album. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the album in English. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the album. Optional.");
RequestParam(r => r.Metadata!.Genres, "The list of genres associated with the album. Optional.");
RequestParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album. Optional.");
RequestParam(r => r.MediaFormat, "The physical or digital medium of the album. Optional.");
RequestParam(r => r.Barcode, "The barcode of the album. Optional.");
RequestParam(r => r.CatalogNumber, "The catalog number of the album. Optional.");
RequestParam(r => r.MusicBrainzReleaseId, "The MusicBrainz identifier of the release. Optional.");
RequestParam(r => r.MusicBrainzReleaseGroupId, "The MusicBrainz identifier of the release group. Optional.");
RequestParam(r => r.MusicBrainzReleaseArtistId, "The MusicBrainz identifier of the release artist. Optional.");
RequestParam(r => r.Contributors, "The list of media contributors that performed on the album. Required.");
RequestParam(r => r.Ratings, "The list of ratings for this album. Required.");
ResponseParam<AlbumResponse>(r => r.Id, "The Id of the album.");
ResponseParam<AlbumResponse>(r => r.ArtistId, "The Id of the artist the album belongs to.");
ResponseParam<AlbumResponse>(r => r.LibraryId, "The Id of the media library the album belongs to.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Title, "The title of the album.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalTitle, "The original title of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Description, "The description of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseType, "The type of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseStatus, "The status of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.TotalDiscs, "The number of discs of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.TotalTracks, "The number of tracks of the release.");
ResponseParam<AlbumResponse>(r => r.MediaFormat, "The physical or digital medium of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Barcode, "The barcode of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.CatalogNumber, "The catalog number of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.MusicBrainzReleaseId, "The MusicBrainz identifier of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.MusicBrainzReleaseGroupId, "The MusicBrainz identifier of the release group, if applicable.");
ResponseParam<AlbumResponse>(r => r.MusicBrainzReleaseArtistId, "The MusicBrainz identifier of the release artist, if applicable.");
ResponseParam<AlbumResponse>(r => r.CreatedOnUtc, "The date and time when the album was created.");
ResponseParam<AlbumResponse>(r => r.UpdatedOnUtc, "The date and time when the album was last updated, if applicable.");
ResponseParam<AlbumResponse>(r => r.Contributors, "The list of references to the media contributors that performed on the album, each with the role they played.");
ResponseParam<AlbumResponse>(r => r.Ratings, "The list of ratings for this album.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release or reissue year of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the album in English, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Language!.NativeName, "The native name of the language of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the album in English, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Genres, "The list of genres associated with the album.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album.");
ResponseParam<AlbumResponse>(r => r.Tracks, "The list of tracks of the album.");
Response(200, "The updated album is returned.",
example: new AlbumResponse(
Id: Guid.NewGuid(),
ArtistId: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Metadata: new AlbumMetadataDto(
Title: "A Night at the Opera",
OriginalTitle: "A Night at the Opera",
Description: "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 11, 21),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Remastered"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres: [
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
Tags: [
new TagDto(Name: "classic"),
new TagDto(Name: "vinyl")
],
ReleaseType: MusicReleaseType.Album,
ReleaseStatus: MusicReleaseStatus.Official,
TotalDiscs: 1,
TotalTracks: 12
),
MediaFormat: MusicMediaFormat.CD,
Barcode: "0042282778329",
CatalogNumber: "EMC 4008",
MusicBrainzReleaseId: Guid.NewGuid(),
MusicBrainzReleaseGroupId: Guid.NewGuid(),
MusicBrainzReleaseArtistId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow,
Contributors: [
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Producer
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Engineer
)
],
Ratings: [
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Tracks: []
)
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}"
}
}
);
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/{libraryId}/artists/{artistId}/albums/{albumId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested album, its media library, or one of the referenced media contributors does not exist.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "AlbumNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "MediaContributorNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}",
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/{libraryId}/artists/{artistId}/albums/{albumId}",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"ArtistIdCannotBeEmpty",
"AlbumIdCannotBeEmpty",
"MetadataCannotBeNull",
"AlbumTitleCannotBeEmpty",
"AlbumTitleMustBeMaximum255CharactersLong",
"OriginalTitleMustBeMaximum255CharactersLong",
"DescriptionMustBeMaximum2000CharactersLong",
"UnknownMusicReleaseType",
"UnknownMusicReleaseStatus",
"TotalDiscsMustBeGreaterThanZero",
"TotalTracksMustBeGreaterThanZero",
"ReleaseInfoCannotBeNull",
"OriginalReleaseYearMustBeBetween1And9999",
"ReReleaseYearMustBeBetween1And9999",
"ReleaseVersionMustBeMaximum50CharactersLong",
"OriginalReleaseDateAndYearMustMatch",
"ReReleaseDateAndYearMustMatch",
"ReReleaseYearCannotBeEarlierThanOriginalReleaseYear",
"ReReleaseDateCannotBeEarlierThanOriginalReleaseDate",
"GenresListCannotBeNull",
"GenreNameCannotBeEmpty",
"GenreNameMustBeMaximum50CharactersLong",
"TagsListCannotBeNull",
"TagNameCannotBeEmpty",
"TagNameMustBeMaximum50CharactersLong",
"LanguageCodeCannotBeEmpty",
"LanguageCodeMustBe2CharactersLong",
"LanguageNameCannotBeEmpty",
"LanguageNameMustBeMaximum50CharactersLong",
"LanguageNativeNameMustBeMaximum50CharactersLong",
"UnknownMusicMediaFormat",
"CatalogNumberMustBeMaximum50CharactersLong",
"MusicBrainzIdInvalidFormat",
"ContributorsListCannotBeNull",
"MediaContributorIdCannotBeEmpty",
"UnknownMediaContributorRole",
"RatingsListCannotBeNull",
"RatingValueMustBePositive",
"RatingValueCannotBeGreaterThanMaxValue",
"RatingMaxValueMustBePositive",
"RatingVoteCountMustBePositive"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.AddArtist;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.AddArtist;
/// <summary>
/// API endpoint for the <c>/{libraryId}/artists</c> route.
/// </summary>
public class AddArtistEndpoint : BaseEndpoint<AddArtistRequest, IResult>
{
private readonly ICommandHandler<AddArtistCommand, Result<ArtistResponse>> _addArtistCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="AddArtistEndpoint"/> class.
/// </summary>
/// <param name="addArtistCommandHandler">Injected service for handling add artist commands.</param>
public AddArtistEndpoint(ICommandHandler<AddArtistCommand, Result<ArtistResponse>> addArtistCommandHandler)
{
_addArtistCommandHandler = addArtistCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.POST);
Routes(ApiRoutes.Artists.ADD_ARTIST);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Adds an artist stored in <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the artist to be added.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(AddArtistRequest request, CancellationToken cancellationToken)
{
// Take unique identifiers from the route.
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
Result<ArtistResponse> result = await _addArtistCommandHandler.HandleAsync(request.ToCommand(libraryId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1/libraries/{libraryId}/artists/{result.Value.Id}", result.Value), Problem);
}
}
@@ -0,0 +1,917 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.AddArtist;
/// <summary>
/// Class used for providing a textual description for the <see cref="AddArtistEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddArtistEndpointSummary : Summary<AddArtistEndpoint, AddArtistRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="AddArtistEndpointSummary"/> class.
/// </summary>
public AddArtistEndpointSummary()
{
Summary = "Adds a new artist.";
Description = "Creates a new artist and returns its details, including the location of the newly created resource. The request is handled by an Admin, who can add artists to all libraries, or by the owner of the library.";
Guid artistId = Guid.NewGuid();
Guid albumId = Guid.NewGuid();
Guid libraryId = Guid.NewGuid();
ExampleRequest = new AddArtistRequest(
Name: "Queen",
Website: "https://www.queenonline.com",
MusicBrainzArtistId: Guid.NewGuid(),
Contributors:
[
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Albums: [
new(
Metadata: new(
Title: "A Night at the Opera",
OriginalTitle: "A Night at the Opera",
Description: "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.",
ReleaseInfo: new(
OriginalReleaseDate: new DateOnly(1975, 11, 21),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Remastered"
),
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new(Name: "classic"),
new(Name: "vinyl")
],
Genres: [
new(Name: "Rock"),
new(Name: "Progressive Rock")
],
ReleaseType: MusicReleaseType.Album,
ReleaseStatus: MusicReleaseStatus.Official,
TotalDiscs: 1,
TotalTracks: 12
),
MediaFormat: MusicMediaFormat.CD,
Barcode: "0042282778329",
CatalogNumber: "EMC 4008",
MusicBrainzReleaseId: Guid.NewGuid(),
MusicBrainzReleaseGroupId: Guid.NewGuid(),
MusicBrainzReleaseArtistId: Guid.NewGuid(),
Contributors:
[
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Producer
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Engineer
)
],
Ratings: [
new(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Tracks: [
new(
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
Metadata: new(
Title: "Bohemian Rhapsody",
OriginalTitle: "Bohemian Rhapsody",
Description: "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
ReleaseInfo: new(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new(Name: "classic"),
new(Name: "epic")
],
Genres: [
new(Name: "Rock"),
new(Name: "Progressive Rock")
],
DurationInSeconds: 354,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 980
),
TrackNumber: 1,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 72,
Work: "Bohemian Rhapsody",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
Moods: [
new(Name: "dramatic"),
new(Name: "anxious")
],
Isrcs: [
new(Value: "GBUM71029604")
],
Contributors:
[
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings: [
new(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
]
),
new(
Path: "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac",
Metadata: new(
Title: "You're My Best Friend",
OriginalTitle: "You're My Best Friend",
Description: "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.",
ReleaseInfo: new(
OriginalReleaseDate: new DateOnly(1976, 6, 18),
OriginalReleaseYear: 1976,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new(Name: "classic"),
new(Name: "love")
],
Genres: [
new(Name: "Rock"),
new(Name: "Pop Rock")
],
DurationInSeconds: 181,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 912
),
TrackNumber: 7,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.BMajor,
Bpm: 118,
Work: "You're My Best Friend",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
Moods: [
new(Name: "happy"),
new(Name: "warm")
],
Isrcs: [
new(Value: "GBUM71029609")
],
Contributors:
[
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.BassGuitar
)
],
Ratings: [
new(
Value: 4.2M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 1234
),
new(
Value: 4.4M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 567
)
]
)
]
)
]
);
RequestParam(r => r.Name, "The name of the artist. Required.");
RequestParam(r => r.Website, "The website of the artist. Optional.");
RequestParam(r => r.MusicBrainzArtistId, "The MusicBrainz identifier of the artist. Optional.");
RequestParam(r => r.Contributors, "The list of media contributors that make up the artist. Required.");
RequestParam(r => r.Albums, "The list of albums of the artist, each with its own list of tracks. Required.");
RequestParam(r => r.Albums![0].Metadata, "The album metadata of the album. Required.");
RequestParam(r => r.Albums![0].Metadata!.Title, "The title of the album. Required.");
RequestParam(r => r.Albums![0].Metadata!.OriginalTitle, "The original title of the album, if different from the current title. Optional.");
RequestParam(r => r.Albums![0].Metadata!.Description, "A brief description or summary of the album. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Required.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the content. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the content. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release date of the content. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release year of the content. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo!.ReleaseCountry, "The country where the content was released. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the content's release. Optional.");
RequestParam(r => r.Albums![0].Metadata!.Language, "The language of the album. Optional.");
RequestParam(r => r.Albums![0].Metadata!.Language!.LanguageCode, "The ISO code of the language (e.g., \"en\" for English). Required.");
RequestParam(r => r.Albums![0].Metadata!.Language!.LanguageName, "The name of the language in English. Required.");
RequestParam(r => r.Albums![0].Metadata!.Language!.NativeName, "The native name of the language (e.g., \"Español\" for Spanish). Optional.");
RequestParam(r => r.Albums![0].Metadata!.OriginalLanguage, "The original language of the album, if it has been translated. Optional.");
RequestParam(r => r.Albums![0].Metadata!.OriginalLanguage!.LanguageCode, "The ISO code of the language (e.g., \"en\" for English). Required.");
RequestParam(r => r.Albums![0].Metadata!.OriginalLanguage!.LanguageName, "The name of the language in English. Required.");
RequestParam(r => r.Albums![0].Metadata!.OriginalLanguage!.NativeName, "The native name of the language (e.g., \"Español\" for Spanish). Optional.");
RequestParam(r => r.Albums![0].Metadata!.Tags, "The list of tags that further describe or categorize the album. Required.");
RequestParam(r => r.Albums![0].Metadata!.Genres, "The list of genres associated with the album. Required.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseType, "The type of the release. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseStatus, "The status of the release. Optional.");
RequestParam(r => r.Albums![0].Metadata!.TotalDiscs, "The number of discs of the release. Optional.");
RequestParam(r => r.Albums![0].Metadata!.TotalTracks, "The number of tracks of the release. Optional.");
RequestParam(r => r.Albums![0].MediaFormat, "The physical or digital medium of the album. Optional.");
RequestParam(r => r.Albums![0].Barcode, "The barcode of the album. Optional.");
RequestParam(r => r.Albums![0].CatalogNumber, "The catalog number of the album. Optional.");
RequestParam(r => r.Albums![0].MusicBrainzReleaseId, "The MusicBrainz identifier of the release. Optional.");
RequestParam(r => r.Albums![0].MusicBrainzReleaseGroupId, "The MusicBrainz identifier of the release group. Optional.");
RequestParam(r => r.Albums![0].MusicBrainzReleaseArtistId, "The MusicBrainz identifier of the release artist. Optional.");
RequestParam(r => r.Albums![0].Contributors, "The list of media contributors that performed on the album. Required.");
RequestParam(r => r.Albums![0].Ratings, "The list of ratings for this album. Required.");
RequestParam(r => r.Albums![0].Tracks, "The list of tracks of the album. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Path, "The file system path of the track. It must be inside one of the content locations of the media library that owns it. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata, "The audio metadata of the track. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Title, "The title of the track. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.OriginalTitle, "The original title of the track, if different from the current title. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Description, "A brief description or summary of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the content. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the content. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release date of the content. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release year of the content. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReleaseCountry, "The country where the content was released. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the content's release. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Language, "The language of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Language!.LanguageCode, "The ISO code of the language (e.g., \"en\" for English). Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Language!.LanguageName, "The name of the language in English. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Language!.NativeName, "The native name of the language (e.g., \"Español\" for Spanish). Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage, "The original language of the track, if it has been translated. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage!.LanguageCode, "The ISO code of the language (e.g., \"en\" for English). Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage!.LanguageName, "The name of the language in English. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage!.NativeName, "The native name of the language (e.g., \"Español\" for Spanish). Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Tags, "The list of tags that further describe or categorize the track. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Genres, "The list of genres associated with the track. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.SampleRate, "The sample rate of the audio of the track in Hz. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Channels, "The number of audio channels of the track. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.BitDepth, "The bit depth of the audio of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.AudioCodec, "The audio codec used by the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Bitrate, "The bitrate of the audio of the track in kbps. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].TrackNumber, "The number of the track on its disc. Required.");
RequestParam(r => r.Albums![0].Tracks![0].DiscNumber, "The number of the disc the track belongs to. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Script, "The script used by the language of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Key, "The musical key of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Bpm, "The tempo of the track in beats per minute. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Work, "The title of the work the track is a recording of. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].MusicBrainzRecordingId, "The MusicBrainz identifier of the recording. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].MusicBrainzTrackId, "The MusicBrainz identifier of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].MusicBrainzWorkId, "The MusicBrainz identifier of the work. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Moods, "The list of moods of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Isrcs, "The list of ISRC (International Standard Recording Code) of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Contributors, "The list of media contributors that performed on the track. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Ratings, "The list of ratings for this track. Required.");
ResponseParam<ArtistResponse>(r => r.Id, "The Id of the artist.");
ResponseParam<ArtistResponse>(r => r.LibraryId, "The Id of the media library this artist belongs to.");
ResponseParam<ArtistResponse>(r => r.Name, "The name of the artist.");
ResponseParam<ArtistResponse>(r => r.Website, "The website of the artist, if applicable.");
ResponseParam<ArtistResponse>(r => r.MusicBrainzArtistId, "The MusicBrainz identifier of the artist, if applicable.");
ResponseParam<ArtistResponse>(r => r.Contributors, "The list of references to the media contributors that make up the artist, each with the role they played.");
ResponseParam<ArtistResponse>(r => r.Albums, "The list of albums of the artist, each with its own list of tracks.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Id, "The Id of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].ArtistId, "The Id of the artist the album belongs to.");
ResponseParam<ArtistResponse>(r => r.Albums![0].LibraryId, "The Id of the media library this album belongs to.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata, "The album metadata of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Title, "The title of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.OriginalTitle, "The original title of the album, if different from the current title.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Description, "A brief description or summary of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo, "The release information of the album, including its release date and other relevant details.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release date of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release year of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo!.ReleaseCountry, "The country where the album was released.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Language, "The language of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Language!.LanguageCode, "The ISO code of the language of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Language!.LanguageName, "The name of the language of the album in English.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Language!.NativeName, "The native name of the language of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.OriginalLanguage, "The original language of the album, if it has been translated.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.OriginalLanguage!.LanguageCode, "The ISO code of the original language of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.OriginalLanguage!.LanguageName, "The name of the original language of the album in English.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Tags, "The list of tags of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Genres, "The list of genres of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseType, "The type of the release of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseStatus, "The status of the release of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.TotalDiscs, "The number of discs of the release of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.TotalTracks, "The number of tracks of the release of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].MediaFormat, "The physical or digital medium of the album, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Barcode, "The barcode of the album, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].CatalogNumber, "The catalog number of the album, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].MusicBrainzReleaseId, "The MusicBrainz identifier of the release, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].MusicBrainzReleaseGroupId, "The MusicBrainz identifier of the release group, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].MusicBrainzReleaseArtistId, "The MusicBrainz identifier of the release artist, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].CreatedOnUtc, "The date and time when the album was created.");
ResponseParam<ArtistResponse>(r => r.Albums![0].UpdatedOnUtc, "The date and time when the album was last updated, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Contributors, "The list of references to the media contributors that performed on the album, each with the role they played.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Ratings, "The list of ratings for the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks, "The list of tracks of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Id, "The Id of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].AlbumId, "The Id of the album the track belongs to.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].LibraryId, "The Id of the media library this track belongs to.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Path, "The file system path of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata, "The audio metadata of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Title, "The title of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.OriginalTitle, "The original title of the track, if different from the current title.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Description, "A brief description or summary of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo, "The release information of the track, including its release date and other relevant details.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release date of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release year of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReleaseCountry, "The country where the track was released.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Language, "The language of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Language!.LanguageCode, "The ISO code of the language of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Language!.LanguageName, "The name of the language of the track in English.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Language!.NativeName, "The native name of the language of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage, "The original language of the track, if it has been translated.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage!.LanguageCode, "The ISO code of the original language of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage!.LanguageName, "The name of the original language of the track in English.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Tags, "The list of tags of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Genres, "The list of genres of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.SampleRate, "The sample rate of the audio of the track in Hz.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Channels, "The number of audio channels of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.BitDepth, "The bit depth of the audio of the track, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.AudioCodec, "The audio codec used by the track, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Bitrate, "The bitrate of the audio of the track in kbps, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].TrackNumber, "The number of the track on its disc.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].DiscNumber, "The number of the disc the track belongs to, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Script, "The script used by the language of the track, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Key, "The musical key of the track, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Bpm, "The tempo of the track in beats per minute, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Work, "The title of the work the track is a recording of, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].MusicBrainzRecordingId, "The MusicBrainz identifier of the recording, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].MusicBrainzTrackId, "The MusicBrainz identifier of the track, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].CreatedOnUtc, "The date and time when the track was created.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Ratings, "The list of ratings for the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Moods, "The list of moods of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
ResponseParam<ArtistResponse>(r => r.CreatedOnUtc, "The date and time when the artist was created.");
ResponseParam<ArtistResponse>(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable.");
Response(201, "The new artist is returned.",
example: new ArtistResponse(
Id: artistId,
LibraryId: libraryId,
Name: "Queen",
Website: "https://www.queenonline.com",
MusicBrainzArtistId: Guid.NewGuid(),
Contributors:
[
new(ContributorId: Guid.NewGuid(), Role: MediaContributorRole.Vocals),
new(ContributorId: Guid.NewGuid(), Role: MediaContributorRole.Guitar)
],
Albums:
[
new(
Id: albumId,
ArtistId: artistId,
LibraryId: libraryId,
Metadata: new(
Title: "A Night at the Opera",
OriginalTitle: "A Night at the Opera",
Description: "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.",
ReleaseInfo: new(
OriginalReleaseDate: new DateOnly(1975, 11, 21),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Remastered"
),
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres:
[
new(Name: "Rock"),
new(Name: "Progressive Rock")
],
Tags:
[
new(Name: "classic"),
new(Name: "vinyl")
],
ReleaseType: MusicReleaseType.Album,
ReleaseStatus: MusicReleaseStatus.Official,
TotalDiscs: 1,
TotalTracks: 12
),
MediaFormat: MusicMediaFormat.CD,
Barcode: "0042282778329",
CatalogNumber: "EMC 4008",
MusicBrainzReleaseId: Guid.NewGuid(),
MusicBrainzReleaseGroupId: Guid.NewGuid(),
MusicBrainzReleaseArtistId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default,
Contributors: [
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Producer
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Engineer
)
],
Ratings:
[
new(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Tracks:
[
new(
Id: Guid.NewGuid(),
AlbumId: albumId,
LibraryId: libraryId,
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
Metadata: new(
Title: "Bohemian Rhapsody",
OriginalTitle: "Bohemian Rhapsody",
Description: "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
ReleaseInfo: new(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags:
[
new(Name: "classic"),
new(Name: "epic")
],
Genres:
[
new(Name: "Rock"),
new(Name: "Progressive Rock")
],
DurationInSeconds: 354,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 980
),
TrackNumber: 1,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 72,
Work: "Bohemian Rhapsody",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default,
Contributors:
[
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings:
[
new(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Moods:
[
new(Name: "dramatic"),
new(Name: "anxious")
],
Isrcs:
[
new(Value: "GBUM71029604")
]
),
new(
Id: Guid.NewGuid(),
AlbumId: albumId,
LibraryId: libraryId,
Path: "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac",
Metadata: new(
Title: "You're My Best Friend",
OriginalTitle: "You're My Best Friend",
Description: "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.",
ReleaseInfo: new(
OriginalReleaseDate: new DateOnly(1976, 6, 18),
OriginalReleaseYear: 1976,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags:
[
new(Name: "classic"),
new(Name: "love")
],
Genres:
[
new(Name: "Rock"),
new(Name: "Pop Rock")
],
DurationInSeconds: 181,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 912
),
TrackNumber: 7,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.BMajor,
Bpm: 118,
Work: "You're My Best Friend",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default,
Contributors:
[
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings:
[
new(
Value: 4.2M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 1234
),
new(
Value: 4.4M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 567
)
],
Moods:
[
new(Name: "happy"),
new(Name: "warm")
],
Isrcs:
[
new(Value: "GBUM71029609")
]
)
]
)
],
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default
)
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
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"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token has expired",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists"
}
}
);
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",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the media library or one of the referenced media contributors does not exist.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "MediaContributorNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
}
);
Response(409, "The request failed because an artist with the same identity already exists, or because a unique constraint was violated.", "application/problem+json",
example: new[]
{
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",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
title = "General.Conflict",
status = 409,
detail = "UniqueConstraintViolation",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists",
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",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"ArtistNameCannotBeEmpty",
"ArtistNameMustBeMaximum255CharactersLong",
"ArtistWebsiteMustBeMaximum2048CharactersLong",
"MusicBrainzIdInvalidFormat",
"ContributorsListCannotBeNull",
"MediaContributorIdCannotBeEmpty",
"UnknownMediaContributorRole",
"AlbumsListCannotBeNull",
"MetadataCannotBeNull",
"AlbumTitleCannotBeEmpty",
"AlbumTitleMustBeMaximum255CharactersLong",
"TitleCannotBeEmpty",
"TitleMustBeMaximum255CharactersLong",
"OriginalTitleMustBeMaximum255CharactersLong",
"DescriptionMustBeMaximum2000CharactersLong",
"UnknownMusicReleaseType",
"UnknownMusicReleaseStatus",
"TotalDiscsMustBeGreaterThanZero",
"TotalTracksMustBeGreaterThanZero",
"ReleaseInfoCannotBeNull",
"OriginalReleaseYearMustBeBetween1And9999",
"ReReleaseYearMustBeBetween1And9999",
"ReleaseVersionMustBeMaximum50CharactersLong",
"OriginalReleaseDateAndYearMustMatch",
"ReReleaseDateAndYearMustMatch",
"ReReleaseYearCannotBeEarlierThanOriginalReleaseYear",
"ReReleaseDateCannotBeEarlierThanOriginalReleaseDate",
"GenresListCannotBeNull",
"GenreNameCannotBeEmpty",
"GenreNameMustBeMaximum50CharactersLong",
"TagsListCannotBeNull",
"TagNameCannotBeEmpty",
"TagNameMustBeMaximum50CharactersLong",
"LanguageCodeCannotBeEmpty",
"LanguageCodeMustBe2CharactersLong",
"LanguageNameCannotBeEmpty",
"LanguageNameMustBeMaximum50CharactersLong",
"LanguageNativeNameMustBeMaximum50CharactersLong",
"UnknownMusicMediaFormat",
"CatalogNumberMustBeMaximum50CharactersLong",
"RatingsListCannotBeNull",
"RatingValueMustBePositive",
"RatingValueCannotBeGreaterThanMaxValue",
"RatingMaxValueMustBePositive",
"RatingVoteCountMustBePositive",
"TracksListCannotBeNull",
"TrackPathCannotBeEmpty",
"TrackPathMustBeMaximum2048CharactersLong",
"TrackNumberMustBeGreaterThanZero",
"DiscNumberMustBeGreaterThanZero",
"ScriptMustBeMaximum50CharactersLong",
"UnknownMusicKey",
"BpmMustBeGreaterThanZero",
"WorkMustBeMaximum255CharactersLong",
"MoodNameCannotBeEmpty",
"IsrcValueCannotBeEmpty",
"TrackPathMustBeWithinLibraryContentLocations",
"ArtistMustHaveAtLeastOneAlbum"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.DeleteArtist;
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.DeleteArtist;
/// <summary>
/// API endpoint for the <c>/{libraryId}/artists/{artistId}</c> route.
/// </summary>
public class DeleteArtistEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
{
private readonly ICommandHandler<DeleteArtistCommand, Result<Deleted>> _deleteArtistCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="DeleteArtistEndpoint"/> class.
/// </summary>
/// <param name="deleteArtistCommandHandler">Injected service for handling delete artist commands.</param>
public DeleteArtistEndpoint(ICommandHandler<DeleteArtistCommand, Result<Deleted>> deleteArtistCommandHandler)
{
_deleteArtistCommandHandler = deleteArtistCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.DELETE);
Routes(ApiRoutes.Artists.DELETE_ARTIST);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Deletes an artist by Id.
/// </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 unique identifiers from the route.
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString();
Result<Deleted> result = await _deleteArtistCommandHandler.HandleAsync(new DeleteArtistCommand(libraryId, artistId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,114 @@
#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.DeleteArtist;
/// <summary>
/// Class used for providing a textual description for the <see cref="DeleteArtistEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteArtistEndpointSummary : Summary<DeleteArtistEndpoint, EmptyRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="DeleteArtistEndpointSummary"/> class.
/// </summary>
public DeleteArtistEndpointSummary()
{
Summary = "Deletes an existing artist.";
Description = "Deletes the artist identified by the request, 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.";
Response(200, "The artist was successfully deleted.");
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
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()}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token has expired",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}"
}
}
);
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()}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested artist or its media library does not exist.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ArtistNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}",
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()}",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"ArtistIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtist;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetArtist;
/// <summary>
/// API endpoint for the <c>/artists/{artistId}</c> route.
/// </summary>
public class GetArtistEndpoint : BaseEndpoint<GetArtistRequest, IResult>
{
private readonly IQueryHandler<GetArtistQuery, Result<ArtistResponse>> _getArtistQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetArtistEndpoint"/> class.
/// </summary>
/// <param name="getArtistQueryHandler">Injected service for handling get artist queries.</param>
public GetArtistEndpoint(IQueryHandler<GetArtistQuery, Result<ArtistResponse>> getArtistQueryHandler)
{
_getArtistQueryHandler = getArtistQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Artists.GET_ARTIST_BY_ID);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets an artist by Id.
/// </summary>
/// <param name="request">The request containing the id of the artist to be retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetArtistRequest request, CancellationToken cancellationToken)
{
Result<ArtistResponse> result = await _getArtistQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,136 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetArtist;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetArtistEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetArtistEndpointSummary : Summary<GetArtistEndpoint, GetArtistRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetArtistEndpointSummary"/> class.
/// </summary>
public GetArtistEndpointSummary()
{
Summary = "Gets an artist by its Id.";
Description = "Returns the full details of the artist identified by the request. The artist is returned to an Admin, who can see the artists of all libraries, or to the owner of the library of the artist.";
ExampleRequest = new GetArtistRequest(
ArtistId: Guid.NewGuid()
);
RequestParam(r => r.ArtistId, "The Id of the artist to get. Required.");
ResponseParam<ArtistResponse>(r => r.Id, "The Id of the artist.");
ResponseParam<ArtistResponse>(r => r.LibraryId, "The Id of the media library this artist belongs to.");
ResponseParam<ArtistResponse>(r => r.Name, "The name of the artist.");
ResponseParam<ArtistResponse>(r => r.Website, "The website of the artist, if applicable.");
ResponseParam<ArtistResponse>(r => r.MusicBrainzArtistId, "The MusicBrainz identifier of the artist, if applicable.");
ResponseParam<ArtistResponse>(r => r.Contributors, "The list of references to the media contributors that make up the artist, each with the role they played.");
ResponseParam<ArtistResponse>(r => r.Albums, "The list of albums of the artist, each with its own list of tracks.");
ResponseParam<ArtistResponse>(r => r.CreatedOnUtc, "The date and time when the artist was created.");
ResponseParam<ArtistResponse>(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable.");
Response(200, "The requested artist is returned.",
example: new ArtistResponse(
Id: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Name: "Queen",
Website: "https://www.queenonline.com",
MusicBrainzArtistId: Guid.NewGuid(),
Contributors:
[
new(ContributorId: Guid.NewGuid(), Role: MediaContributorRole.Vocals),
new(ContributorId: Guid.NewGuid(), Role: MediaContributorRole.Guitar)
],
Albums: [],
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow
)
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}"
}
}
);
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/{libraryId}/artists/{artistId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested artist does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ArtistNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}",
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/{libraryId}/artists/{artistId}",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"ArtistIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtistAlbums;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
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.Artists.GetArtistAlbums;
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums</c> route.
/// </summary>
public class GetArtistAlbumsEndpoint : BaseEndpoint<GetArtistAlbumsRequest, IResult>
{
private readonly IQueryHandler<GetArtistAlbumsQuery, Result<IReadOnlyList<AlbumResponse>>> _getArtistAlbumsQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetArtistAlbumsEndpoint"/> class.
/// </summary>
/// <param name="getArtistAlbumsQueryHandler">Injected service for handling get artist albums queries.</param>
public GetArtistAlbumsEndpoint(IQueryHandler<GetArtistAlbumsQuery, Result<IReadOnlyList<AlbumResponse>>> getArtistAlbumsQueryHandler)
{
_getArtistAlbumsQueryHandler = getArtistAlbumsQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Albums.GET_ARTIST_ALBUMS);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the list of all the albums of the artist identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the id of the artist whose albums are retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetArtistAlbumsRequest request, CancellationToken cancellationToken)
{
Result<IReadOnlyList<AlbumResponse>> result = await _getArtistAlbumsQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,302 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetArtistAlbums;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetArtistAlbumsEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetArtistAlbumsEndpointSummary : Summary<GetArtistAlbumsEndpoint, GetArtistAlbumsRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetArtistAlbumsEndpointSummary"/> class.
/// </summary>
public GetArtistAlbumsEndpointSummary()
{
Summary = "Retrieves the list of albums of an artist.";
Description = "Returns the full details of the albums of the artist identified by the request, with the full details of each album. The list is returned to an Admin, who can see the albums of the artists of all libraries, or to the owner of the library of the artist.";
ExampleRequest = new GetArtistAlbumsRequest(
ArtistId: Guid.NewGuid()
);
RequestParam(r => r.ArtistId, "The Id of the artist whose albums are retrieved, taken from the route. Required.");
ResponseParam<AlbumResponse>(r => r.Id, "The Id of the album.");
ResponseParam<AlbumResponse>(r => r.ArtistId, "The Id of the artist the album belongs to.");
ResponseParam<AlbumResponse>(r => r.LibraryId, "The Id of the media library the album belongs to.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Title, "The title of the album.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalTitle, "The original title of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Description, "The description of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseType, "The type of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseStatus, "The status of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.TotalDiscs, "The number of discs of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.TotalTracks, "The number of tracks of the release.");
ResponseParam<AlbumResponse>(r => r.MediaFormat, "The physical or digital medium of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Barcode, "The barcode of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.CatalogNumber, "The catalog number of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.MusicBrainzReleaseId, "The MusicBrainz identifier of the release, if applicable.");
ResponseParam<AlbumResponse>(r => r.MusicBrainzReleaseGroupId, "The MusicBrainz identifier of the release group, if applicable.");
ResponseParam<AlbumResponse>(r => r.MusicBrainzReleaseArtistId, "The MusicBrainz identifier of the release artist, if applicable.");
ResponseParam<AlbumResponse>(r => r.CreatedOnUtc, "The date and time when the album was created.");
ResponseParam<AlbumResponse>(r => r.UpdatedOnUtc, "The date and time when the album was last updated, if applicable.");
ResponseParam<AlbumResponse>(r => r.Contributors, "The list of references to the media contributors that performed on the album, each with the role they played.");
ResponseParam<AlbumResponse>(r => r.Ratings, "The list of ratings for this album.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release or reissue year of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the album in English, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Language!.NativeName, "The native name of the language of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the album in English, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the album, if applicable.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Genres, "The list of genres associated with the album.");
ResponseParam<AlbumResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the album.");
ResponseParam<AlbumResponse>(r => r.Tracks, "The list of tracks of the album.");
Response(200, "The list of albums of the artist is returned.",
example: new AlbumResponse[]
{
new AlbumResponse(
Id: Guid.NewGuid(),
ArtistId: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Metadata: new AlbumMetadataDto(
Title: "A Night at the Opera",
OriginalTitle: "A Night at the Opera",
Description: "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 11, 21),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Remastered"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres: [
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
Tags: [
new TagDto(Name: "classic"),
new TagDto(Name: "vinyl")
],
ReleaseType: MusicReleaseType.Album,
ReleaseStatus: MusicReleaseStatus.Official,
TotalDiscs: 1,
TotalTracks: 12
),
MediaFormat: MusicMediaFormat.CD,
Barcode: "0042282778329",
CatalogNumber: "EMC 4008",
MusicBrainzReleaseId: Guid.NewGuid(),
MusicBrainzReleaseGroupId: Guid.NewGuid(),
MusicBrainzReleaseArtistId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow,
Contributors: [
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Producer
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Engineer
)
],
Ratings: [
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Tracks: []
),
new AlbumResponse(
Id: Guid.NewGuid(),
ArtistId: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Metadata: new AlbumMetadataDto(
Title: "The Works",
OriginalTitle: "The Works",
Description: "The eleventh studio album by the British rock band Queen, released in 1984. It was the first Queen album to be released on CD.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1984, 2, 27),
OriginalReleaseYear: 1984,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres: [
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Pop Rock")
],
Tags: [
new TagDto(Name: "classic"),
new TagDto(Name: "compact disc")
],
ReleaseType: MusicReleaseType.Album,
ReleaseStatus: MusicReleaseStatus.Official,
TotalDiscs: 1,
TotalTracks: 9
),
MediaFormat: MusicMediaFormat.CD,
Barcode: "0042282771043",
CatalogNumber: "EMC 2400141",
MusicBrainzReleaseId: Guid.NewGuid(),
MusicBrainzReleaseGroupId: Guid.NewGuid(),
MusicBrainzReleaseArtistId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow,
Contributors: [
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Producer
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Engineer
)
],
Ratings: [
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Tracks: []
)
}
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums"
}
}
);
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/{libraryId}/artists/{artistId}/albums",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested artist does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ArtistNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums",
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/{libraryId}/artists/{artistId}/albums",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"ArtistIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtistAlbumsLite;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Contracts.Responses.Common;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetArtistAlbumsLite;
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums/lite</c> route.
/// </summary>
public class GetArtistAlbumsLiteEndpoint : BaseEndpoint<GetArtistAlbumsLiteRequest, IResult>
{
private readonly IQueryHandler<GetArtistAlbumsLiteQuery, Result<PaginatedResponse<AlbumLiteResponse>>> _getArtistAlbumsLiteQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetArtistAlbumsLiteEndpoint"/> class.
/// </summary>
/// <param name="getArtistAlbumsLiteQueryHandler">Injected service for handling get artist albums lite queries.</param>
public GetArtistAlbumsLiteEndpoint(IQueryHandler<GetArtistAlbumsLiteQuery, Result<PaginatedResponse<AlbumLiteResponse>>> getArtistAlbumsLiteQueryHandler)
{
_getArtistAlbumsLiteQueryHandler = getArtistAlbumsLiteQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Albums.GET_ARTIST_ALBUMS_LITE);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the lightweight read models of all the albums of the artist identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the id of the artist whose albums are retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetArtistAlbumsLiteRequest request, CancellationToken cancellationToken)
{
Result<PaginatedResponse<AlbumLiteResponse>> result = await _getArtistAlbumsLiteQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,139 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Contracts.Responses.Common;
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.Artists.GetArtistAlbumsLite;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetArtistAlbumsLiteEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetArtistAlbumsLiteEndpointSummary : Summary<GetArtistAlbumsLiteEndpoint, GetArtistAlbumsLiteRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetArtistAlbumsLiteEndpointSummary"/> class.
/// </summary>
public GetArtistAlbumsLiteEndpointSummary()
{
Summary = "Retrieves the lightweight read models of the albums of an artist.";
Description = "Returns the lightweight read models of the albums of the artist identified by its Id, projecting only the fields needed to display the albums in a card-based grid, without loading the full album entities and their related data. The page is returned to an Admin, who can see the albums of the artists of all libraries, or to the owner of the library of the artist.";
ExampleRequest = new GetArtistAlbumsLiteRequest(
ArtistId: Guid.NewGuid(),
CurrentPage: 1,
PerPage: 48
);
RequestParam(r => r.ArtistId, "The Id of the artist whose albums are retrieved. Required.");
RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional.");
RequestParam(r => r.PerPage, "The maximum number of albums to retrieve per page. Optional.");
ResponseParam<AlbumLiteResponse>(r => r.Id, "The Id of the album.");
ResponseParam<AlbumLiteResponse>(r => r.Title, "The title of the album.");
ResponseParam<AlbumLiteResponse>(r => r.TotalTracks, "The number of tracks of the release.");
Response(200, "The paginated list of the lightweight read models of the albums of the artist is returned.",
example: new PaginatedResponse<AlbumLiteResponse>
{
Data =
[
new AlbumLiteResponse(
Id: Guid.NewGuid(),
Title: "A Night at the Opera",
TotalTracks: 12
),
new AlbumLiteResponse(
Id: Guid.NewGuid(),
Title: "The Works",
TotalTracks: 9
)
],
CurrentPage = 1,
PerPage = 10,
Count = 2,
NumberOfPages = 1
}
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/lite"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/lite"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/lite"
}
}
);
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/{libraryId}/artists/{artistId}/albums/lite",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested artist does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ArtistNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/lite",
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/{libraryId}/artists/{artistId}/albums/lite",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"ArtistIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtists;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Contracts.Responses.Common;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetArtists;
/// <summary>
/// API endpoint for the <c>/artists</c> route.
/// </summary>
public class GetArtistsEndpoint : BaseEndpoint<GetArtistsRequest, IResult>
{
private readonly IQueryHandler<GetArtistsQuery, Result<PaginatedResponse<ArtistResponse>>> _getArtistsQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetArtistsEndpoint"/> class.
/// </summary>
/// <param name="getArtistsQueryHandler">Injected service for handling get artists queries.</param>
public GetArtistsEndpoint(IQueryHandler<GetArtistsQuery, Result<PaginatedResponse<ArtistResponse>>> getArtistsQueryHandler)
{
_getArtistsQueryHandler = getArtistsQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Artists.GET_ARTISTS);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the list of all the artists of the media library identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the Id of the media library whose artists are retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetArtistsRequest request, CancellationToken cancellationToken)
{
Result<PaginatedResponse<ArtistResponse>> result = await _getArtistsQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,147 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Contracts.Responses.Common;
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.GetArtists;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetArtistsEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetArtistsEndpointSummary : Summary<GetArtistsEndpoint, GetArtistsRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetArtistsEndpointSummary"/> class.
/// </summary>
public GetArtistsEndpointSummary()
{
Summary = "Retrieves the list of artists of a media library.";
Description = "Returns the paginated list of the artists of the media library identified by the request, with the full details of each artist. The page is returned to an Admin, who can see the artists of all libraries, or to the owner of the library.";
ExampleRequest = new GetArtistsRequest(
LibraryId: Guid.NewGuid(),
CurrentPage: 1,
PerPage: 48,
SearchTerm: "queen"
);
RequestParam(r => r.LibraryId, "The Id of the media library whose artists are retrieved. Required.");
RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional.");
RequestParam(r => r.PerPage, "The maximum number of artists to retrieve per page. Optional.");
RequestParam(r => r.SearchTerm, "The search term used to filter the artists by name. Optional.");
ResponseParam<ArtistResponse>(r => r.Id, "The Id of the artist.");
ResponseParam<ArtistResponse>(r => r.LibraryId, "The Id of the media library this artist belongs to.");
ResponseParam<ArtistResponse>(r => r.Name, "The name of the artist.");
ResponseParam<ArtistResponse>(r => r.Website, "The website of the artist, if applicable.");
ResponseParam<ArtistResponse>(r => r.MusicBrainzArtistId, "The MusicBrainz identifier of the artist, if applicable.");
ResponseParam<ArtistResponse>(r => r.Contributors, "The list of references to the media contributors that make up the artist, each with the role they played.");
ResponseParam<ArtistResponse>(r => r.Albums, "The list of albums of the artist, each with its own list of tracks.");
ResponseParam<ArtistResponse>(r => r.CreatedOnUtc, "The date and time when the artist was created.");
ResponseParam<ArtistResponse>(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable.");
Response(200, "The paginated list of the artists of the media library is returned.",
example: new PaginatedResponse<ArtistResponse>
{
Data =
[
new ArtistResponse(
Id: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Name: "Queen",
Website: "https://www.queenonline.com",
MusicBrainzArtistId: Guid.NewGuid(),
Contributors: [],
Albums: [],
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow
),
new ArtistResponse(
Id: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Name: "David Bowie",
Website: "https://www.davidbowie.com",
MusicBrainzArtistId: Guid.NewGuid(),
Contributors: [],
Albums: [],
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow
)
],
CurrentPage = 1,
PerPage = 10,
Count = 2,
NumberOfPages = 1
}
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists"
}
}
);
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/{libraryId}/artists",
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/{libraryId}/artists",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Queries.GetArtistsLite;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Contracts.Responses.Common;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.GetArtistsLite;
/// <summary>
/// API endpoint for the <c>/artists/lite</c> route.
/// </summary>
public class GetArtistsLiteEndpoint : BaseEndpoint<GetArtistsLiteRequest, IResult>
{
private readonly IQueryHandler<GetArtistsLiteQuery, Result<PaginatedResponse<ArtistLiteResponse>>> _getArtistsLiteQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetArtistsLiteEndpoint"/> class.
/// </summary>
/// <param name="getArtistsLiteQueryHandler">Injected service for handling get artists lite queries.</param>
public GetArtistsLiteEndpoint(IQueryHandler<GetArtistsLiteQuery, Result<PaginatedResponse<ArtistLiteResponse>>> getArtistsLiteQueryHandler)
{
_getArtistsLiteQueryHandler = getArtistsLiteQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Artists.GET_ARTISTS_LITE);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the lightweight read models of all the artists of the media library identified by <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the Id of the media library whose artists are retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetArtistsLiteRequest request, CancellationToken cancellationToken)
{
Result<PaginatedResponse<ArtistLiteResponse>> result = await _getArtistsLiteQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,126 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Contracts.Responses.Common;
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.GetArtistsLite;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetArtistsLiteEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetArtistsLiteEndpointSummary : Summary<GetArtistsLiteEndpoint, GetArtistsLiteRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetArtistsLiteEndpointSummary"/> class.
/// </summary>
public GetArtistsLiteEndpointSummary()
{
Summary = "Retrieves the lightweight read models of the artists of a media library.";
Description = "Returns the lightweight read models of the artists of a media library, projecting only the fields needed to display the artists in a card-based grid, without loading the full artist entities and their related data. The page is returned to an Admin, who can see the artists of all libraries, or to the owner of the library.";
ExampleRequest = new GetArtistsLiteRequest(
LibraryId: Guid.NewGuid(),
CurrentPage: 1,
PerPage: 48,
SearchTerm: "queen"
);
RequestParam(r => r.LibraryId, "The Id of the media library whose artists are retrieved. Required.");
RequestParam(r => r.CurrentPage, "The page of results to retrieve. Optional.");
RequestParam(r => r.PerPage, "The maximum number of artists to retrieve per page. Optional.");
RequestParam(r => r.SearchTerm, "The search term used to filter the artists by name. Optional.");
ResponseParam<ArtistLiteResponse>(r => r.Id, "The Id of the artist.");
ResponseParam<ArtistLiteResponse>(r => r.Name, "The name of the artist.");
Response(200, "The paginated list of the lightweight read models of the artists is returned.",
example: new PaginatedResponse<ArtistLiteResponse>
{
Data =
[
new ArtistLiteResponse(
Id: Guid.NewGuid(),
Name: "Queen"
),
new ArtistLiteResponse(
Id: Guid.NewGuid(),
Name: "David Bowie"
)
],
CurrentPage = 1,
PerPage = 10,
Count = 2,
NumberOfPages = 1
}
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/lite"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/lite"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/lite"
}
}
);
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/{libraryId}/artists/lite",
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/{libraryId}/artists/lite",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,57 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Artists.Commands.UpdateArtist;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.UpdateArtist;
/// <summary>
/// API endpoint for the <c>/{libraryId}/artists/{artistId}</c> route.
/// </summary>
public class UpdateArtistEndpoint : BaseEndpoint<UpdateArtistRequest, IResult>
{
private readonly ICommandHandler<UpdateArtistCommand, Result<ArtistResponse>> _updateArtistCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="UpdateArtistEndpoint"/> class.
/// </summary>
/// <param name="updateArtistCommandHandler">Injected service for handling update artist commands.</param>
public UpdateArtistEndpoint(ICommandHandler<UpdateArtistCommand, Result<ArtistResponse>> updateArtistCommandHandler)
{
_updateArtistCommandHandler = updateArtistCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.PUT);
Routes(ApiRoutes.Artists.UPDATE_ARTIST);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Updates the artist described in <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the edited details of the artist.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(UpdateArtistRequest request, CancellationToken cancellationToken)
{
// Take unique identifiers from the route.
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString();
Result<ArtistResponse> result = await _updateArtistCommandHandler.HandleAsync(request.ToCommand(libraryId, artistId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,903 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Artists.UpdateArtist;
/// <summary>
/// Class used for providing a textual description for the <see cref="UpdateArtistEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdateArtistEndpointSummary : Summary<UpdateArtistEndpoint, UpdateArtistRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="UpdateArtistEndpointSummary"/> class.
/// </summary>
public UpdateArtistEndpointSummary()
{
Summary = "Updates an existing artist.";
Description = "Updates the details of the artist identified by the request, together with its contributors and albums, returning the full details of the updated artist. The artist is updated by an Admin, who can update the artists of all libraries, or by the owner of the library of the artist.";
RequestParam(r => r.Name, "The name of the artist. Required.");
RequestParam(r => r.Website, "The website of the artist. Optional.");
RequestParam(r => r.MusicBrainzArtistId, "The MusicBrainz identifier of the artist. Optional.");
RequestParam(r => r.Contributors, "The list of media contributors that make up the artist. Required.");
RequestParam(r => r.Albums, "The list of albums of the artist, each with its own list of tracks. Required.");
RequestParam(r => r.Albums![0].Metadata, "The album metadata of the album. Required.");
RequestParam(r => r.Albums![0].Metadata!.Title, "The title of the album. Required.");
RequestParam(r => r.Albums![0].Metadata!.OriginalTitle, "The original title of the album, if different from the current title. Optional.");
RequestParam(r => r.Albums![0].Metadata!.Description, "A brief description or summary of the album. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Required.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the content. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the content. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release date of the content. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release year of the content. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo!.ReleaseCountry, "The country where the content was released. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the content's release. Optional.");
RequestParam(r => r.Albums![0].Metadata!.Language, "The language of the album. Optional.");
RequestParam(r => r.Albums![0].Metadata!.Language!.LanguageCode, "The ISO code of the language (e.g., \"en\" for English). Required.");
RequestParam(r => r.Albums![0].Metadata!.Language!.LanguageName, "The name of the language in English. Required.");
RequestParam(r => r.Albums![0].Metadata!.Language!.NativeName, "The native name of the language (e.g., \"Español\" for Spanish). Optional.");
RequestParam(r => r.Albums![0].Metadata!.OriginalLanguage, "The original language of the album, if it has been translated. Optional.");
RequestParam(r => r.Albums![0].Metadata!.OriginalLanguage!.LanguageCode, "The ISO code of the language (e.g., \"en\" for English). Required.");
RequestParam(r => r.Albums![0].Metadata!.OriginalLanguage!.LanguageName, "The name of the language in English. Required.");
RequestParam(r => r.Albums![0].Metadata!.OriginalLanguage!.NativeName, "The native name of the language (e.g., \"Español\" for Spanish). Optional.");
RequestParam(r => r.Albums![0].Metadata!.Tags, "The list of tags that further describe or categorize the album. Required.");
RequestParam(r => r.Albums![0].Metadata!.Genres, "The list of genres associated with the album. Required.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseType, "The type of the release. Optional.");
RequestParam(r => r.Albums![0].Metadata!.ReleaseStatus, "The status of the release. Optional.");
RequestParam(r => r.Albums![0].Metadata!.TotalDiscs, "The number of discs of the release. Optional.");
RequestParam(r => r.Albums![0].Metadata!.TotalTracks, "The number of tracks of the release. Optional.");
RequestParam(r => r.Albums![0].MediaFormat, "The physical or digital medium of the album. Optional.");
RequestParam(r => r.Albums![0].Barcode, "The barcode of the album. Optional.");
RequestParam(r => r.Albums![0].CatalogNumber, "The catalog number of the album. Optional.");
RequestParam(r => r.Albums![0].MusicBrainzReleaseId, "The MusicBrainz identifier of the release. Optional.");
RequestParam(r => r.Albums![0].MusicBrainzReleaseGroupId, "The MusicBrainz identifier of the release group. Optional.");
RequestParam(r => r.Albums![0].MusicBrainzReleaseArtistId, "The MusicBrainz identifier of the release artist. Optional.");
RequestParam(r => r.Albums![0].Contributors, "The list of media contributors that performed on the album. Required.");
RequestParam(r => r.Albums![0].Ratings, "The list of ratings for this album. Required.");
RequestParam(r => r.Albums![0].Tracks, "The list of tracks of the album. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Path, "The file system path of the track. It must be inside one of the content locations of the media library that owns it. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata, "The audio metadata of the track. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Title, "The title of the track. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.OriginalTitle, "The original title of the track, if different from the current title. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Description, "A brief description or summary of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the content. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the content. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release date of the content. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release year of the content. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReleaseCountry, "The country where the content was released. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the content's release. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Language, "The language of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Language!.LanguageCode, "The ISO code of the language (e.g., \"en\" for English). Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Language!.LanguageName, "The name of the language in English. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Language!.NativeName, "The native name of the language (e.g., \"Español\" for Spanish). Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage, "The original language of the track, if it has been translated. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage!.LanguageCode, "The ISO code of the language (e.g., \"en\" for English). Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage!.LanguageName, "The name of the language in English. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage!.NativeName, "The native name of the language (e.g., \"Español\" for Spanish). Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Tags, "The list of tags that further describe or categorize the track. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Genres, "The list of genres associated with the track. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.SampleRate, "The sample rate of the audio of the track in Hz. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Channels, "The number of audio channels of the track. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.BitDepth, "The bit depth of the audio of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.AudioCodec, "The audio codec used by the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Metadata!.Bitrate, "The bitrate of the audio of the track in kbps. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].TrackNumber, "The number of the track on its disc. Required.");
RequestParam(r => r.Albums![0].Tracks![0].DiscNumber, "The number of the disc the track belongs to. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Script, "The script used by the language of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Key, "The musical key of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Bpm, "The tempo of the track in beats per minute. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Work, "The title of the work the track is a recording of. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].MusicBrainzRecordingId, "The MusicBrainz identifier of the recording. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].MusicBrainzTrackId, "The MusicBrainz identifier of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].MusicBrainzWorkId, "The MusicBrainz identifier of the work. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Moods, "The list of moods of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Isrcs, "The list of ISRC (International Standard Recording Code) of the track. Optional.");
RequestParam(r => r.Albums![0].Tracks![0].Contributors, "The list of media contributors that performed on the track. Required.");
RequestParam(r => r.Albums![0].Tracks![0].Ratings, "The list of ratings for this track. Required.");
ExampleRequest = new UpdateArtistRequest(
Name: "Queen",
Website: "https://www.queenonline.com",
MusicBrainzArtistId: Guid.NewGuid(),
Contributors:
[
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Albums: [
new AddAlbumRequest(
Metadata: new AlbumMetadataDto(
Title: "A Night at the Opera",
OriginalTitle: "A Night at the Opera",
Description: "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 11, 21),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Remastered"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new TagDto(Name: "classic"),
new TagDto(Name: "vinyl")
],
Genres: [
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
ReleaseType: MusicReleaseType.Album,
ReleaseStatus: MusicReleaseStatus.Official,
TotalDiscs: 1,
TotalTracks: 12
),
MediaFormat: MusicMediaFormat.CD,
Barcode: "0042282778329",
CatalogNumber: "EMC 4008",
MusicBrainzReleaseId: Guid.NewGuid(),
MusicBrainzReleaseGroupId: Guid.NewGuid(),
MusicBrainzReleaseArtistId: Guid.NewGuid(),
Contributors:
[
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Producer
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Engineer
)
],
Ratings: [
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Tracks: [
new AddTrackRequest(
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
Metadata: new AudioMetadataDto(
Title: "Bohemian Rhapsody",
OriginalTitle: "Bohemian Rhapsody",
Description: "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new TagDto(Name: "classic"),
new TagDto(Name: "epic")
],
Genres: [
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
DurationInSeconds: 354,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 980
),
TrackNumber: 1,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 72,
Work: "Bohemian Rhapsody",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
Moods: [
new MoodDto(Name: "dramatic"),
new MoodDto(Name: "anxious")
],
Isrcs: [
new IsrcDto(Value: "GBUM71029604")
],
Contributors:
[
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings: [
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
]
),
new AddTrackRequest(
Path: "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac",
Metadata: new AudioMetadataDto(
Title: "You're My Best Friend",
OriginalTitle: "You're My Best Friend",
Description: "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1976, 6, 18),
OriginalReleaseYear: 1976,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new TagDto(Name: "classic"),
new TagDto(Name: "love")
],
Genres: [
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Pop Rock")
],
DurationInSeconds: 181,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 912
),
TrackNumber: 7,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.BMajor,
Bpm: 118,
Work: "You're My Best Friend",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
Moods: [
new MoodDto(Name: "happy"),
new MoodDto(Name: "warm")
],
Isrcs: [
new IsrcDto(Value: "GBUM71029609")
],
Contributors:
[
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.BassGuitar
)
],
Ratings: [
new AudioRatingDto(
Value: 4.2M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 1234
),
new AudioRatingDto(
Value: 4.4M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 567
)
]
)
]
)
]
);
ResponseParam<ArtistResponse>(r => r.Id, "The Id of the artist.");
ResponseParam<ArtistResponse>(r => r.LibraryId, "The Id of the media library this artist belongs to.");
ResponseParam<ArtistResponse>(r => r.Name, "The name of the artist.");
ResponseParam<ArtistResponse>(r => r.Website, "The website of the artist, if applicable.");
ResponseParam<ArtistResponse>(r => r.MusicBrainzArtistId, "The MusicBrainz identifier of the artist, if applicable.");
ResponseParam<ArtistResponse>(r => r.Contributors, "The list of references to the media contributors that make up the artist, each with the role they played.");
ResponseParam<ArtistResponse>(r => r.Albums, "The list of albums of the artist, each with its own list of tracks.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Id, "The Id of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].ArtistId, "The Id of the artist the album belongs to.");
ResponseParam<ArtistResponse>(r => r.Albums![0].LibraryId, "The Id of the media library this album belongs to.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata, "The album metadata of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Title, "The title of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.OriginalTitle, "The original title of the album, if different from the current title.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Description, "A brief description or summary of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo, "The release information of the album, including its release date and other relevant details.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release date of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release year of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo!.ReleaseCountry, "The country where the album was released.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Language, "The language of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Language!.LanguageCode, "The ISO code of the language of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Language!.LanguageName, "The name of the language of the album in English.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Language!.NativeName, "The native name of the language of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.OriginalLanguage, "The original language of the album, if it has been translated.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.OriginalLanguage!.LanguageCode, "The ISO code of the original language of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.OriginalLanguage!.LanguageName, "The name of the original language of the album in English.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Tags, "The list of tags of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.Genres, "The list of genres of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseType, "The type of the release of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.ReleaseStatus, "The status of the release of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.TotalDiscs, "The number of discs of the release of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Metadata!.TotalTracks, "The number of tracks of the release of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].MediaFormat, "The physical or digital medium of the album, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Barcode, "The barcode of the album, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].CatalogNumber, "The catalog number of the album, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].MusicBrainzReleaseId, "The MusicBrainz identifier of the release, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].MusicBrainzReleaseGroupId, "The MusicBrainz identifier of the release group, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].MusicBrainzReleaseArtistId, "The MusicBrainz identifier of the release artist, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].CreatedOnUtc, "The date and time when the album was created.");
ResponseParam<ArtistResponse>(r => r.Albums![0].UpdatedOnUtc, "The date and time when the album was last updated, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Contributors, "The list of references to the media contributors that performed on the album, each with the role they played.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Ratings, "The list of ratings for the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks, "The list of tracks of the album.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Id, "The Id of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].AlbumId, "The Id of the album the track belongs to.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].LibraryId, "The Id of the media library this track belongs to.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Path, "The file system path of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata, "The audio metadata of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Title, "The title of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.OriginalTitle, "The original title of the track, if different from the current title.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Description, "A brief description or summary of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo, "The release information of the track, including its release date and other relevant details.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release date of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release year of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReleaseCountry, "The country where the track was released.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Language, "The language of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Language!.LanguageCode, "The ISO code of the language of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Language!.LanguageName, "The name of the language of the track in English.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Language!.NativeName, "The native name of the language of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage, "The original language of the track, if it has been translated.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage!.LanguageCode, "The ISO code of the original language of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage!.LanguageName, "The name of the original language of the track in English.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Tags, "The list of tags of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Genres, "The list of genres of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.SampleRate, "The sample rate of the audio of the track in Hz.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Channels, "The number of audio channels of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.BitDepth, "The bit depth of the audio of the track, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.AudioCodec, "The audio codec used by the track, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Metadata!.Bitrate, "The bitrate of the audio of the track in kbps, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].TrackNumber, "The number of the track on its disc.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].DiscNumber, "The number of the disc the track belongs to, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Script, "The script used by the language of the track, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Key, "The musical key of the track, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Bpm, "The tempo of the track in beats per minute, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Work, "The title of the work the track is a recording of, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].MusicBrainzRecordingId, "The MusicBrainz identifier of the recording, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].MusicBrainzTrackId, "The MusicBrainz identifier of the track, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].CreatedOnUtc, "The date and time when the track was created.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Ratings, "The list of ratings for the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Moods, "The list of moods of the track.");
ResponseParam<ArtistResponse>(r => r.Albums![0].Tracks![0].Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
ResponseParam<ArtistResponse>(r => r.CreatedOnUtc, "The date and time when the artist was created.");
ResponseParam<ArtistResponse>(r => r.UpdatedOnUtc, "The date and time when the artist was last updated, if applicable.");
Guid artistId = Guid.NewGuid();
Guid libraryId = Guid.NewGuid();
Guid albumId = Guid.NewGuid();
Response(200, "The updated artist is returned.",
example: new ArtistResponse(
Id: artistId,
LibraryId: libraryId,
Name: "Queen",
Website: "https://www.queenonline.com",
MusicBrainzArtistId: Guid.NewGuid(),
Contributors:
[
new(ContributorId: Guid.NewGuid(), Role: MediaContributorRole.Vocals),
new(ContributorId: Guid.NewGuid(), Role: MediaContributorRole.Guitar)
],
Albums:
[
new AlbumResponse(
Id: albumId,
ArtistId: artistId,
LibraryId: libraryId,
Metadata: new AlbumMetadataDto(
Title: "A Night at the Opera",
OriginalTitle: "A Night at the Opera",
Description: "The fourth studio album by the British rock band Queen, released in 1975. It was the most expensive album ever recorded at the time of its release.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 11, 21),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Remastered"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres:
[
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
Tags:
[
new TagDto(Name: "classic"),
new TagDto(Name: "vinyl")
],
ReleaseType: MusicReleaseType.Album,
ReleaseStatus: MusicReleaseStatus.Official,
TotalDiscs: 1,
TotalTracks: 12
),
MediaFormat: MusicMediaFormat.CD,
Barcode: "0042282778329",
CatalogNumber: "EMC 4008",
MusicBrainzReleaseId: Guid.NewGuid(),
MusicBrainzReleaseGroupId: Guid.NewGuid(),
MusicBrainzReleaseArtistId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow,
Contributors:
[
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Producer
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Engineer
)
],
Ratings:
[
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Tracks:
[
new TrackResponse(
Id: Guid.NewGuid(),
AlbumId: albumId,
LibraryId: libraryId,
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
Metadata: new AudioMetadataDto(
Title: "Bohemian Rhapsody",
OriginalTitle: "Bohemian Rhapsody",
Description: "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags:
[
new TagDto(Name: "classic"),
new TagDto(Name: "epic")
],
Genres:
[
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
DurationInSeconds: 354,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 980
),
TrackNumber: 1,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 72,
Work: "Bohemian Rhapsody",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow,
Contributors:
[
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings:
[
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Moods:
[
new MoodDto(Name: "dramatic"),
new MoodDto(Name: "anxious")
],
Isrcs:
[
new IsrcDto(Value: "GBUM71029604")
]
),
new TrackResponse(
Id: Guid.NewGuid(),
AlbumId: albumId,
LibraryId: libraryId,
Path: "/music/queen/a-night-at-the-opera/07-youre-my-best-friend.flac",
Metadata: new AudioMetadataDto(
Title: "You're My Best Friend",
OriginalTitle: "You're My Best Friend",
Description: "A song by the British rock band Queen, written by bass guitarist John Deacon. It was originally released on the album A Night at the Opera in 1975 and as a single in 1976.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1976, 6, 18),
OriginalReleaseYear: 1976,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags:
[
new TagDto(Name: "classic"),
new TagDto(Name: "love")
],
Genres:
[
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Pop Rock")
],
DurationInSeconds: 181,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 912
),
TrackNumber: 7,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.BMajor,
Bpm: 118,
Work: "You're My Best Friend",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow,
Contributors:
[
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings:
[
new AudioRatingDto(
Value: 4.2M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 1234
),
new AudioRatingDto(
Value: 4.4M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 567
)
],
Moods:
[
new MoodDto(Name: "happy"),
new MoodDto(Name: "warm")
],
Isrcs:
[
new IsrcDto(Value: "GBUM71029609")
]
)
]
)
],
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow
)
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
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()}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token has expired",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}"
}
}
);
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()}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested artist, its media library, or one of the referenced media contributors does not exist.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ArtistNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "MediaContributorNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/artists/{Guid.NewGuid()}",
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()}",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"ArtistIdCannotBeEmpty",
"ArtistNameCannotBeEmpty",
"ArtistNameMustBeMaximum255CharactersLong",
"ArtistWebsiteMustBeMaximum2048CharactersLong",
"MusicBrainzIdInvalidFormat",
"ContributorsListCannotBeNull",
"MediaContributorIdCannotBeEmpty",
"UnknownMediaContributorRole",
"AlbumsListCannotBeNull",
"MetadataCannotBeNull",
"AlbumTitleCannotBeEmpty",
"AlbumTitleMustBeMaximum255CharactersLong",
"TitleCannotBeEmpty",
"TitleMustBeMaximum255CharactersLong",
"OriginalTitleMustBeMaximum255CharactersLong",
"DescriptionMustBeMaximum2000CharactersLong",
"UnknownMusicReleaseType",
"UnknownMusicReleaseStatus",
"TotalDiscsMustBeGreaterThanZero",
"TotalTracksMustBeGreaterThanZero",
"ReleaseInfoCannotBeNull",
"OriginalReleaseYearMustBeBetween1And9999",
"ReReleaseYearMustBeBetween1And9999",
"ReleaseVersionMustBeMaximum50CharactersLong",
"OriginalReleaseDateAndYearMustMatch",
"ReReleaseDateAndYearMustMatch",
"ReReleaseYearCannotBeEarlierThanOriginalReleaseYear",
"ReReleaseDateCannotBeEarlierThanOriginalReleaseDate",
"GenresListCannotBeNull",
"GenreNameCannotBeEmpty",
"GenreNameMustBeMaximum50CharactersLong",
"TagsListCannotBeNull",
"TagNameCannotBeEmpty",
"TagNameMustBeMaximum50CharactersLong",
"LanguageCodeCannotBeEmpty",
"LanguageCodeMustBe2CharactersLong",
"LanguageNameCannotBeEmpty",
"LanguageNameMustBeMaximum50CharactersLong",
"LanguageNativeNameMustBeMaximum50CharactersLong",
"UnknownMusicMediaFormat",
"CatalogNumberMustBeMaximum50CharactersLong",
"RatingsListCannotBeNull",
"RatingValueMustBePositive",
"RatingValueCannotBeGreaterThanMaxValue",
"RatingMaxValueMustBePositive",
"RatingVoteCountMustBePositive",
"TracksListCannotBeNull",
"TrackPathCannotBeEmpty",
"TrackPathMustBeMaximum2048CharactersLong",
"TrackNumberMustBeGreaterThanZero",
"DiscNumberMustBeGreaterThanZero",
"ScriptMustBeMaximum50CharactersLong",
"UnknownMusicKey",
"BpmMustBeGreaterThanZero",
"WorkMustBeMaximum255CharactersLong",
"MoodNameCannotBeEmpty",
"IsrcValueCannotBeEmpty",
"ArtistMustHaveAtLeastOneAlbum"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,58 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.AddTrack;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.AddTrack;
/// <summary>
/// API endpoint for the <c>/{libraryId}/artists/{artistId}/albums/{albumId}/tracks</c> route.
/// </summary>
public class AddTrackEndpoint : BaseEndpoint<AddTrackRequest, IResult>
{
private readonly ICommandHandler<AddTrackCommand, Result<TrackResponse>> _addTrackCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="AddTrackEndpoint"/> class.
/// </summary>
/// <param name="addTrackCommandHandler">Injected service for handling add track commands.</param>
public AddTrackEndpoint(ICommandHandler<AddTrackCommand, Result<TrackResponse>> addTrackCommandHandler)
{
_addTrackCommandHandler = addTrackCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.POST);
Routes(ApiRoutes.Albums.ADD_TRACK);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Adds a track stored in <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the track to be added.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(AddTrackRequest request, CancellationToken cancellationToken)
{
// Take 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<TrackResponse> result = await _addTrackCommandHandler.HandleAsync(request.ToCommand(libraryId, artistId, albumId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{result.Value.Id}", result.Value), Problem);
}
}
@@ -0,0 +1,457 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.AddTrack;
/// <summary>
/// Class used for providing a textual description for the <see cref="AddTrackEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddTrackEndpointSummary : Summary<AddTrackEndpoint, AddTrackRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="AddTrackEndpointSummary"/> class.
/// </summary>
public AddTrackEndpointSummary()
{
Summary = "Adds a new track to an album.";
Description = "Adds a new track to the album identified by the request, returning the full details of the newly created track. The track is added by an Admin, who can add tracks to the albums of all libraries, or by the owner of the library of the album the track is added to.";
ExampleRequest = new AddTrackRequest(
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
Metadata: new AudioMetadataDto(
Title: "Bohemian Rhapsody",
OriginalTitle: "Bohemian Rhapsody",
Description: "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
DurationInSeconds: 354,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 980,
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres:
[
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
Tags:
[
new TagDto(Name: "classic"),
new TagDto(Name: "epic")
]
),
TrackNumber: 1,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 72,
Work: "Bohemian Rhapsody",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
Contributors:
[
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings:
[
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Moods:
[
new MoodDto(Name: "dramatic"),
new MoodDto(Name: "anxious")
],
Isrcs:
[
new IsrcDto(Value: "GBUM71029604")
]
);
RequestParam(r => r.Path, "The file system path of the track. Required.");
RequestParam(r => r.Metadata, "The audio metadata of the track. Required.");
RequestParam(r => r.Metadata!.Title, "The title of the track. Required.");
RequestParam(r => r.Metadata!.OriginalTitle, "The original title of the track. Optional.");
RequestParam(r => r.Metadata!.Description, "The description of the track. Optional.");
RequestParam(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds. Required.");
RequestParam(r => r.Metadata!.SampleRate, "The sample rate of the audio of the track in Hz. Required.");
RequestParam(r => r.Metadata!.Channels, "The number of audio channels of the track. Required.");
RequestParam(r => r.Metadata!.BitDepth, "The bit depth of the audio of the track. Optional.");
RequestParam(r => r.Metadata!.AudioCodec, "The audio codec used by the track. Optional.");
RequestParam(r => r.Metadata!.Bitrate, "The bitrate of the audio of the track in kbps. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the track. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the track. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the track. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release or reissue year of the track. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the track. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the track. Optional.");
RequestParam(r => r.Metadata!.Language, "The language of the track. Optional.");
RequestParam(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the track. Optional.");
RequestParam(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the track in English. Optional.");
RequestParam(r => r.Metadata!.Language!.NativeName, "The native name of the language of the track. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage, "The original language of the track, if it has been translated. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the track. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the track in English. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track. Optional.");
RequestParam(r => r.Metadata!.Genres, "The list of genres associated with the track. Optional.");
RequestParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track. Optional.");
RequestParam(r => r.TrackNumber, "The number of the track on its disc. Required.");
RequestParam(r => r.DiscNumber, "The number of the disc the track belongs to. Optional.");
RequestParam(r => r.Script, "The script used by the language of the track. Optional.");
RequestParam(r => r.Key, "The musical key of the track. Optional.");
RequestParam(r => r.Bpm, "The tempo of the track in beats per minute. Optional.");
RequestParam(r => r.Work, "The title of the work the track is a recording of. Optional.");
RequestParam(r => r.MusicBrainzRecordingId, "The MusicBrainz identifier of the recording. Optional.");
RequestParam(r => r.MusicBrainzTrackId, "The MusicBrainz identifier of the track. Optional.");
RequestParam(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work. Optional.");
RequestParam(r => r.Contributors, "The list of media contributors that performed on the track. Optional.");
RequestParam(r => r.Ratings, "The list of ratings for this track. Required.");
RequestParam(r => r.Moods, "The list of moods of the track. Optional.");
RequestParam(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track. Optional.");
ResponseParam<TrackResponse>(r => r.Id, "The Id of the track.");
ResponseParam<TrackResponse>(r => r.AlbumId, "The Id of the album the track belongs to.");
ResponseParam<TrackResponse>(r => r.LibraryId, "The Id of the media library the track belongs to.");
ResponseParam<TrackResponse>(r => r.Path, "The file system path of the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.Title, "The title of the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalTitle, "The original title of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Description, "The description of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.TrackNumber, "The number of the track on its disc.");
ResponseParam<TrackResponse>(r => r.DiscNumber, "The number of the disc the track belongs to, if applicable.");
ResponseParam<TrackResponse>(r => r.Script, "The script used by the language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Key, "The musical key of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Bpm, "The tempo of the track in beats per minute, if applicable.");
ResponseParam<TrackResponse>(r => r.Work, "The title of the work the track is a recording of, if applicable.");
ResponseParam<TrackResponse>(r => r.MusicBrainzRecordingId, "The MusicBrainz identifier of the recording, if applicable.");
ResponseParam<TrackResponse>(r => r.MusicBrainzTrackId, "The MusicBrainz identifier of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
ResponseParam<TrackResponse>(r => r.CreatedOnUtc, "The date and time when the track was created.");
ResponseParam<TrackResponse>(r => r.UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
ResponseParam<TrackResponse>(r => r.Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
ResponseParam<TrackResponse>(r => r.Ratings, "The list of ratings for this track.");
ResponseParam<TrackResponse>(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
ResponseParam<TrackResponse>(r => r.Metadata!.SampleRate, "The sample rate of the audio of the track in Hz.");
ResponseParam<TrackResponse>(r => r.Metadata!.Channels, "The number of audio channels of the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.BitDepth, "The bit depth of the audio of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.AudioCodec, "The audio codec used by the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Bitrate, "The bitrate of the audio of the track in kbps, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release or reissue year of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the track in English, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Language!.NativeName, "The native name of the language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the track in English, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Genres, "The list of genres associated with the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track.");
ResponseParam<TrackResponse>(r => r.Moods, "The list of moods of the track.");
ResponseParam<TrackResponse>(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
Response(201, "The newly created track is returned.",
example: new TrackResponse(
Id: Guid.NewGuid(),
AlbumId: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
Metadata: new AudioMetadataDto(
Title: "Bohemian Rhapsody",
OriginalTitle: "Bohemian Rhapsody",
Description: "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new TagDto(Name: "classic"),
new TagDto(Name: "epic")
],
Genres: [
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
DurationInSeconds: 354,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 980
),
TrackNumber: 1,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 72,
Work: "Bohemian Rhapsody",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: default,
Contributors: [
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings: [
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Moods: [
new MoodDto(Name: "dramatic"),
new MoodDto(Name: "anxious")
],
Isrcs: [
new IsrcDto(Value: "GBUM71029604")
]
)
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks"
}
}
);
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/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested album, its media library, or one of the referenced media contributors does not exist.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "AlbumNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "MediaContributorNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
}
);
Response(409, "The request failed because a track with the same identity or file system path already exists in the library, or because a unique constraint was violated.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
title = "General.Conflict",
status = 409,
detail = "TrackAlreadyExists",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
title = "General.Conflict",
status = 409,
detail = "UniqueConstraintViolation",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
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/{libraryId}/artists/{artistId}/albums/{albumId}/tracks",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"ArtistIdCannotBeEmpty",
"AlbumIdCannotBeEmpty",
"TrackPathCannotBeEmpty",
"TrackPathMustBeMaximum2048CharactersLong",
"MetadataCannotBeNull",
"TitleCannotBeEmpty",
"TitleMustBeMaximum255CharactersLong",
"OriginalTitleMustBeMaximum255CharactersLong",
"DescriptionMustBeMaximum2000CharactersLong",
"ReleaseInfoCannotBeNull",
"OriginalReleaseYearMustBeBetween1And9999",
"ReReleaseYearMustBeBetween1And9999",
"ReleaseVersionMustBeMaximum50CharactersLong",
"OriginalReleaseDateAndYearMustMatch",
"ReReleaseDateAndYearMustMatch",
"ReReleaseYearCannotBeEarlierThanOriginalReleaseYear",
"ReReleaseDateCannotBeEarlierThanOriginalReleaseDate",
"GenresListCannotBeNull",
"GenreNameCannotBeEmpty",
"GenreNameMustBeMaximum50CharactersLong",
"TagsListCannotBeNull",
"TagNameCannotBeEmpty",
"TagNameMustBeMaximum50CharactersLong",
"LanguageCodeCannotBeEmpty",
"LanguageCodeMustBe2CharactersLong",
"LanguageNameCannotBeEmpty",
"LanguageNameMustBeMaximum50CharactersLong",
"LanguageNativeNameMustBeMaximum50CharactersLong",
"MusicBrainzIdInvalidFormat",
"TrackNumberMustBeGreaterThanZero",
"DiscNumberMustBeGreaterThanZero",
"ScriptMustBeMaximum50CharactersLong",
"UnknownMusicKey",
"BpmMustBeGreaterThanZero",
"WorkMustBeMaximum255CharactersLong",
"ContributorsListCannotBeNull",
"MediaContributorIdCannotBeEmpty",
"UnknownMediaContributorRole",
"RatingsListCannotBeNull",
"RatingValueMustBePositive",
"RatingValueCannotBeGreaterThanMaxValue",
"RatingMaxValueMustBePositive",
"RatingVoteCountMustBePositive",
"TrackPathMustBeWithinLibraryContentLocations"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.DeleteTrack;
using Lumina.Contracts.Requests.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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.DeleteTrack;
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums/{albumId}/tracks/{trackId}</c> route.
/// </summary>
public class DeleteTrackEndpoint : BaseEndpoint<DeleteTrackRequest, IResult>
{
private readonly ICommandHandler<DeleteTrackCommand, Result<Deleted>> _deleteTrackCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="DeleteTrackEndpoint"/> class.
/// </summary>
/// <param name="deleteTrackCommandHandler">Injected service for handling delete track commands.</param>
public DeleteTrackEndpoint(ICommandHandler<DeleteTrackCommand, Result<Deleted>> deleteTrackCommandHandler)
{
_deleteTrackCommandHandler = deleteTrackCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.DELETE);
Routes(ApiRoutes.Tracks.DELETE_TRACK);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Deletes a track by Id.
/// </summary>
/// <param name="request">The request containing the id of the track to be deleted.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(DeleteTrackRequest request, CancellationToken cancellationToken)
{
Result<Deleted> result = await _deleteTrackCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,112 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.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.DeleteTrack;
/// <summary>
/// Class used for providing a textual description for the <see cref="DeleteTrackEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteTrackEndpointSummary : Summary<DeleteTrackEndpoint, DeleteTrackRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="DeleteTrackEndpointSummary"/> class.
/// </summary>
public DeleteTrackEndpointSummary()
{
Summary = "Deletes an existing track.";
Description = "Deletes the track identified by the request. The track is deleted by an Admin, who can delete the tracks of all libraries, or by the owner of the library of the track.";
ExampleRequest = new DeleteTrackRequest(
ArtistId: Guid.NewGuid(),
AlbumId: Guid.NewGuid(),
TrackId: Guid.NewGuid()
);
RequestParam(r => r.ArtistId, "The unique identifier of the artist the album of the track belongs to, taken from the route.");
RequestParam(r => r.AlbumId, "The unique identifier of the album the track belongs to, taken from the route.");
RequestParam(r => r.TrackId, "The Id of the track to delete, taken from the route. Required.");
Response(200, "The track was successfully deleted.");
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}"
}
}
);
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/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested track does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "TrackNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}",
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/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"TrackIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Queries.GetTrack;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.GetTrack;
/// <summary>
/// API endpoint for the <c>/artists/{artistId}/albums/{albumId}/tracks/{trackId}</c> route.
/// </summary>
public class GetTrackEndpoint : BaseEndpoint<GetTrackRequest, IResult>
{
private readonly IQueryHandler<GetTrackQuery, Result<TrackResponse>> _getTrackQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetTrackEndpoint"/> class.
/// </summary>
/// <param name="getTrackQueryHandler">Injected service for handling get track queries.</param>
public GetTrackEndpoint(IQueryHandler<GetTrackQuery, Result<TrackResponse>> getTrackQueryHandler)
{
_getTrackQueryHandler = getTrackQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Routes(ApiRoutes.Tracks.GET_TRACK_BY_ID);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets a track by Id.
/// </summary>
/// <param name="request">The request containing the id of the track to be retrieved.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetTrackRequest request, CancellationToken cancellationToken)
{
Result<TrackResponse> result = await _getTrackQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,249 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.GetTrack;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetTrackEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetTrackEndpointSummary : Summary<GetTrackEndpoint, GetTrackRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetTrackEndpointSummary"/> class.
/// </summary>
public GetTrackEndpointSummary()
{
Summary = "Gets a track by its Id.";
Description = "Returns the full details of the track identified by the request. The track is returned to an Admin, who can see the tracks of all libraries, or to the owner of the library of the track.";
ExampleRequest = new GetTrackRequest(
ArtistId: Guid.NewGuid(),
AlbumId: Guid.NewGuid(),
TrackId: Guid.NewGuid()
);
RequestParam(r => r.ArtistId, "The unique identifier of the artist the album of the track belongs to, taken from the route.");
RequestParam(r => r.AlbumId, "The unique identifier of the album the track belongs to, taken from the route.");
RequestParam(r => r.TrackId, "The Id of the track to get. Required.");
ResponseParam<TrackResponse>(r => r.Id, "The Id of the track.");
ResponseParam<TrackResponse>(r => r.AlbumId, "The Id of the album the track belongs to.");
ResponseParam<TrackResponse>(r => r.LibraryId, "The Id of the media library the track belongs to.");
ResponseParam<TrackResponse>(r => r.Path, "The file system path of the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.Title, "The title of the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalTitle, "The original title of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Description, "The description of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.TrackNumber, "The number of the track on its disc.");
ResponseParam<TrackResponse>(r => r.DiscNumber, "The number of the disc the track belongs to, if applicable.");
ResponseParam<TrackResponse>(r => r.Script, "The script used by the language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Key, "The musical key of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Bpm, "The tempo of the track in beats per minute, if applicable.");
ResponseParam<TrackResponse>(r => r.Work, "The title of the work the track is a recording of, if applicable.");
ResponseParam<TrackResponse>(r => r.MusicBrainzRecordingId, "The MusicBrainz identifier of the recording, if applicable.");
ResponseParam<TrackResponse>(r => r.MusicBrainzTrackId, "The MusicBrainz identifier of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
ResponseParam<TrackResponse>(r => r.CreatedOnUtc, "The date and time when the track was created.");
ResponseParam<TrackResponse>(r => r.UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
ResponseParam<TrackResponse>(r => r.Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
ResponseParam<TrackResponse>(r => r.Ratings, "The list of ratings for this track.");
ResponseParam<TrackResponse>(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
ResponseParam<TrackResponse>(r => r.Metadata!.SampleRate, "The sample rate of the audio of the track in Hz.");
ResponseParam<TrackResponse>(r => r.Metadata!.Channels, "The number of audio channels of the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.BitDepth, "The bit depth of the audio of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.AudioCodec, "The audio codec used by the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Bitrate, "The bitrate of the audio of the track in kbps, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release or reissue year of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the track in English, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Language!.NativeName, "The native name of the language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the track in English, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Genres, "The list of genres associated with the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track.");
ResponseParam<TrackResponse>(r => r.Moods, "The list of moods of the track.");
ResponseParam<TrackResponse>(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
Response(200, "The requested track is returned.",
example: new TrackResponse(
Id: Guid.NewGuid(),
AlbumId: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
Metadata: new AudioMetadataDto(
Title: "Bohemian Rhapsody",
OriginalTitle: "Bohemian Rhapsody",
Description: "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new TagDto(Name: "classic"),
new TagDto(Name: "epic")
],
Genres: [
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
DurationInSeconds: 354,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 980
),
TrackNumber: 1,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 72,
Work: "Bohemian Rhapsody",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow,
Contributors: [
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings: [
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Moods: [
new MoodDto(Name: "dramatic"),
new MoodDto(Name: "anxious")
],
Isrcs: [
new IsrcDto(Value: "GBUM71029604")
]
)
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}"
}
}
);
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/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested track does not exist.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "TrackNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}",
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/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"TrackIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,59 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.Tracks.Commands.UpdateTrack;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
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.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.UpdateTrack;
/// <summary>
/// API endpoint for the <c>/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}</c> route.
/// </summary>
public class UpdateTrackEndpoint : BaseEndpoint<UpdateTrackRequest, IResult>
{
private readonly ICommandHandler<UpdateTrackCommand, Result<TrackResponse>> _updateTrackCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="UpdateTrackEndpoint"/> class.
/// </summary>
/// <param name="updateTrackCommandHandler">Injected service for handling update track commands.</param>
public UpdateTrackEndpoint(ICommandHandler<UpdateTrackCommand, Result<TrackResponse>> updateTrackCommandHandler)
{
_updateTrackCommandHandler = updateTrackCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.PUT);
Routes(ApiRoutes.Tracks.UPDATE_TRACK);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Updates a track stored in <paramref name="request"/>.
/// </summary>
/// <param name="request">The request containing the track to be updated.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(UpdateTrackRequest request, CancellationToken cancellationToken)
{
// Take 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<TrackResponse> result = await _updateTrackCommandHandler.HandleAsync(request.ToCommand(libraryId, artistId, albumId, trackId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,386 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.Common;
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.Tracks.UpdateTrack;
/// <summary>
/// Class used for providing a textual description for the <see cref="UpdateTrackEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdateTrackEndpointSummary : Summary<UpdateTrackEndpoint, UpdateTrackRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="UpdateTrackEndpointSummary"/> class.
/// </summary>
public UpdateTrackEndpointSummary()
{
Summary = "Updates an existing track.";
Description = "Updates the details of the track identified by the request, returning the full details of the updated track. The media contributors of the track are left untouched. The track is updated by an Admin, who can update the tracks of all libraries, or by the owner of the library of the track.";
ExampleRequest = new UpdateTrackRequest(
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
Metadata: new AudioMetadataDto(
Title: "Bohemian Rhapsody",
OriginalTitle: "Bohemian Rhapsody",
Description: "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
DurationInSeconds: 354,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 980,
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Genres:
[
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
Tags:
[
new TagDto(Name: "classic"),
new TagDto(Name: "epic")
]
),
TrackNumber: 1,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 72,
Work: "Bohemian Rhapsody",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
Contributors:
[
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings:
[
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Moods:
[
new MoodDto(Name: "dramatic"),
new MoodDto(Name: "anxious")
],
Isrcs:
[
new IsrcDto(Value: "GBUM71029604")
]
);
RequestParam(r => r.Path, "The file system path of the track. Required.");
RequestParam(r => r.Metadata, "The audio metadata of the track. Required.");
RequestParam(r => r.Metadata!.Title, "The title of the track. Required.");
RequestParam(r => r.Metadata!.OriginalTitle, "The original title of the track. Optional.");
RequestParam(r => r.Metadata!.Description, "The description of the track. Optional.");
RequestParam(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds. Required.");
RequestParam(r => r.Metadata!.SampleRate, "The sample rate of the audio of the track in Hz. Required.");
RequestParam(r => r.Metadata!.Channels, "The number of audio channels of the track. Required.");
RequestParam(r => r.Metadata!.BitDepth, "The bit depth of the audio of the track. Optional.");
RequestParam(r => r.Metadata!.AudioCodec, "The audio codec used by the track. Optional.");
RequestParam(r => r.Metadata!.Bitrate, "The bitrate of the audio of the track in kbps. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo, "The release information, including release date and other relevant details. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the track. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the track. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the track. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release or reissue year of the track. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the track. Optional.");
RequestParam(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the track. Optional.");
RequestParam(r => r.Metadata!.Language, "The language of the track. Optional.");
RequestParam(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the track. Optional.");
RequestParam(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the track in English. Optional.");
RequestParam(r => r.Metadata!.Language!.NativeName, "The native name of the language of the track. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage, "The original language of the track, if it has been translated. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the track. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the track in English. Optional.");
RequestParam(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track. Optional.");
RequestParam(r => r.Metadata!.Genres, "The list of genres associated with the track. Optional.");
RequestParam(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track. Optional.");
RequestParam(r => r.TrackNumber, "The number of the track on its disc. Required.");
RequestParam(r => r.DiscNumber, "The number of the disc the track belongs to. Optional.");
RequestParam(r => r.Script, "The script used by the language of the track. Optional.");
RequestParam(r => r.Key, "The musical key of the track. Optional.");
RequestParam(r => r.Bpm, "The tempo of the track in beats per minute. Optional.");
RequestParam(r => r.Work, "The title of the work the track is a recording of. Optional.");
RequestParam(r => r.MusicBrainzRecordingId, "The MusicBrainz identifier of the recording. Optional.");
RequestParam(r => r.MusicBrainzTrackId, "The MusicBrainz identifier of the track. Optional.");
RequestParam(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work. Optional.");
RequestParam(r => r.Contributors, "The list of media contributors that performed on the track. Optional.");
RequestParam(r => r.Ratings, "The list of ratings for this track. Required.");
RequestParam(r => r.Moods, "The list of moods of the track. Optional.");
RequestParam(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track. Optional.");
ResponseParam<TrackResponse>(r => r.Id, "The Id of the track.");
ResponseParam<TrackResponse>(r => r.AlbumId, "The Id of the album the track belongs to.");
ResponseParam<TrackResponse>(r => r.LibraryId, "The Id of the media library the track belongs to.");
ResponseParam<TrackResponse>(r => r.Path, "The file system path of the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.Title, "The title of the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalTitle, "The original title of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Description, "The description of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.TrackNumber, "The number of the track on its disc.");
ResponseParam<TrackResponse>(r => r.DiscNumber, "The number of the disc the track belongs to, if applicable.");
ResponseParam<TrackResponse>(r => r.Script, "The script used by the language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Key, "The musical key of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Bpm, "The tempo of the track in beats per minute, if applicable.");
ResponseParam<TrackResponse>(r => r.Work, "The title of the work the track is a recording of, if applicable.");
ResponseParam<TrackResponse>(r => r.MusicBrainzRecordingId, "The MusicBrainz identifier of the recording, if applicable.");
ResponseParam<TrackResponse>(r => r.MusicBrainzTrackId, "The MusicBrainz identifier of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.MusicBrainzWorkId, "The MusicBrainz identifier of the work, if applicable.");
ResponseParam<TrackResponse>(r => r.CreatedOnUtc, "The date and time when the track was created.");
ResponseParam<TrackResponse>(r => r.UpdatedOnUtc, "The date and time when the track was last updated, if applicable.");
ResponseParam<TrackResponse>(r => r.Contributors, "The list of references to the media contributors that performed on the track, each with the role they played.");
ResponseParam<TrackResponse>(r => r.Ratings, "The list of ratings for this track.");
ResponseParam<TrackResponse>(r => r.Metadata!.DurationInSeconds, "The duration of the audio of the track in seconds.");
ResponseParam<TrackResponse>(r => r.Metadata!.SampleRate, "The sample rate of the audio of the track in Hz.");
ResponseParam<TrackResponse>(r => r.Metadata!.Channels, "The number of audio channels of the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.BitDepth, "The bit depth of the audio of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.AudioCodec, "The audio codec used by the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Bitrate, "The bitrate of the audio of the track in kbps, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseDate, "The original release date of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.OriginalReleaseYear, "The original release year of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseDate, "The re-release or reissue date of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReReleaseYear, "The re-release or reissue year of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseCountry, "The country or region of the release of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.ReleaseInfo!.ReleaseVersion, "The version or edition of the release of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Language!.LanguageCode, "The ISO 639-1 two-letter language code of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Language!.LanguageName, "The full name of the language of the track in English, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Language!.NativeName, "The native name of the language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.LanguageCode, "The ISO 639-1 two-letter original language code of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.LanguageName, "The full name of the original language of the track in English, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.OriginalLanguage!.NativeName, "The native name of the original language of the track, if applicable.");
ResponseParam<TrackResponse>(r => r.Metadata!.Genres, "The list of genres associated with the track.");
ResponseParam<TrackResponse>(r => r.Metadata!.Tags, "The list of tags that further describe or categorize the track.");
ResponseParam<TrackResponse>(r => r.Moods, "The list of moods of the track.");
ResponseParam<TrackResponse>(r => r.Isrcs, "The list of ISRC (International Standard Recording Code) of the track.");
Response(200, "The updated track is returned.",
example: new TrackResponse(
Id: Guid.NewGuid(),
AlbumId: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Path: "/music/queen/a-night-at-the-opera/01-bohemian-rhapsody.flac",
Metadata: new AudioMetadataDto(
Title: "Bohemian Rhapsody",
OriginalTitle: "Bohemian Rhapsody",
Description: "A song by the British rock band Queen. It was written by Freddie Mercury and originally released on the album A Night at the Opera in 1975.",
ReleaseInfo: new ReleaseInfoDto(
OriginalReleaseDate: new DateOnly(1975, 10, 31),
OriginalReleaseYear: 1975,
ReReleaseDate: default,
ReReleaseYear: default,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "Original"
),
Language: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
OriginalLanguage: new LanguageInfoDto(
LanguageCode: "en",
LanguageName: "English",
NativeName: "English"
),
Tags: [
new TagDto(Name: "classic"),
new TagDto(Name: "epic")
],
Genres: [
new GenreDto(Name: "Rock"),
new GenreDto(Name: "Progressive Rock")
],
DurationInSeconds: 354,
SampleRate: 44100,
Channels: 2,
BitDepth: 16,
AudioCodec: "FLAC",
Bitrate: 980
),
TrackNumber: 1,
DiscNumber: 1,
Script: "Latn",
Key: MusicKey.CMajor,
Bpm: 72,
Work: "Bohemian Rhapsody",
MusicBrainzRecordingId: Guid.NewGuid(),
MusicBrainzTrackId: Guid.NewGuid(),
MusicBrainzWorkId: Guid.NewGuid(),
CreatedOnUtc: DateTime.UtcNow,
UpdatedOnUtc: DateTime.UtcNow,
Contributors: [
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Vocals
),
new MediaContributorReferenceDto(
ContributorId: Guid.NewGuid(),
Role: MediaContributorRole.Guitar
)
],
Ratings: [
new AudioRatingDto(
Value: 4.5M,
MaxValue: 5,
Source: AudioRatingSource.MusicBrainz,
VoteCount: 2345
),
new AudioRatingDto(
Value: 4.8M,
MaxValue: 5,
Source: AudioRatingSource.LastFm,
VoteCount: 1234
)
],
Moods: [
new MoodDto(Name: "dramatic"),
new MoodDto(Name: "anxious")
],
Isrcs: [
new IsrcDto(Value: "GBUM71029604")
]
)
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Invalid token: The token expired at '01/01/2024 01:00:00'",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}"
}
}
);
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/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the requested track or its media library does not exist.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "TrackNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = "/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}",
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/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"ArtistIdCannotBeEmpty",
"AlbumIdCannotBeEmpty",
"TrackIdCannotBeEmpty",
"TrackPathCannotBeEmpty",
"TrackNumberMustBeGreaterThanZero",
"MusicBrainzIdInvalidFormat"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -48,7 +48,7 @@ public class AddBookEndpoint : BaseEndpoint<AddBookRequest, IResult>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(AddBookRequest request, CancellationToken cancellationToken)
{
// take unique identifiers from the route
// Take unique identifiers from the route.
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
Result<BookResponse> result = await _addBookCommandHandler.HandleAsync(request.ToCommand(libraryId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Created($"{BaseURL}api/v1/libraries/{libraryId}/books/{result.Value.Id}", result.Value), Problem);
@@ -27,32 +27,35 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
public AddBookEndpointSummary()
{
Summary = "Adds a new book.";
Description = "Creates a new book and returns its details, including the location of the newly created resource.";
Description = "Creates a new book and returns its details, including the location of the newly created resource. The request is handled by an Admin, who can add books to all libraries, or by the owner of the library.";
Guid bookId = Guid.NewGuid();
Guid libraryId = Guid.NewGuid();
ExampleRequest = new AddBookRequest(
Path: "/media/libraries/books/the-fellowship-of-the-ring.epub",
Path: "/media/libraries/books/the-fellowship-of-the-ring.pdf",
Metadata: new(
Title: "The Fellowship of the Ring",
OriginalTitle: "The Fellowship of the Ring",
Description: "The first part of J.R.R. Tolkien's epic adventure The Lord of the Rings. In a sleepy village in the Shire, young Frodo Baggins finds himself faced with an immense task, as his elderly cousin Bilbo entrusts the Ring to his care. Frodo must leave his home and make a perilous journey across Middle-earth to the Cracks of Doom, there to destroy the Ring and foil the Dark Lord in his evil purpose.",
ReleaseInfo: new(
OriginalReleaseDate: DateOnly.ParseExact("1954-07-29", "yyyy-MM-dd", null),
OriginalReleaseDate: new DateOnly(1954, 7, 29),
OriginalReleaseYear: 1954,
ReReleaseDate: DateOnly.ParseExact("2001-09-06", "yyyy-MM-dd", null),
ReReleaseDate: new DateOnly(2001, 9, 6),
ReReleaseYear: 2001,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "50th Anniversary Edition"
),
Genres: new List<GenreDto>() {
{ new(Name: "fantasy") },
{ new(Name: "adventure") },
{ new(Name: "classic") }
},
Tags: new List<TagDto>() {
{ new(Name: "epic fantasy") },
{ new(Name: "quest") },
{ new(Name: "middle-earth") }
},
Genres: [
new(Name: "fantasy"),
new(Name: "adventure"),
new(Name: "classic")
],
Tags: [
new(Name: "epic fantasy"),
new(Name: "quest"),
new(Name: "middle-earth")
],
Language: new(
LanguageCode: "en",
LanguageName: "English",
@@ -70,7 +73,7 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
Format: BookFormat.Paperback,
Edition: "50th Anniversary Edition",
VolumeNumber: 1,
Series: new BookSeriesDto(
Series: new(
Title: "The Lord of the Rings"
),
ASIN: "B007978NPG",
@@ -212,17 +215,17 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
Response(201, "The new book is returned.", example:
new BookResponse(
Id: Guid.NewGuid(),
LibraryId: Guid.NewGuid(),
Path: "/media/libraries/books/the-fellowship-of-the-ring.epub",
Id: bookId,
LibraryId: libraryId,
Path: "/media/libraries/books/the-fellowship-of-the-ring.pdf",
Metadata: new(
Title: "The Fellowship of the Ring",
OriginalTitle: "The Fellowship of the Ring",
Description: "The first part of J.R.R. Tolkien's epic adventure The Lord of the Rings. In a sleepy village in the Shire, young Frodo Baggins finds himself faced with an immense task, as his elderly cousin Bilbo entrusts the Ring to his care. Frodo must leave his home and make a perilous journey across Middle-earth to the Cracks of Doom, there to destroy the Ring and foil the Dark Lord in his evil purpose.",
ReleaseInfo: new(
OriginalReleaseDate: DateOnly.ParseExact("1954-07-29", "yyyy-MM-dd", null),
OriginalReleaseDate: new DateOnly(1954, 7, 29),
OriginalReleaseYear: 1954,
ReReleaseDate: DateOnly.ParseExact("2001-09-06", "yyyy-MM-dd", null),
ReReleaseDate: new DateOnly(2001, 9, 6),
ReReleaseYear: 2001,
ReleaseCountry: ReleaseCountry.GB,
ReleaseVersion: "50th Anniversary Edition"
@@ -251,14 +254,11 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
),
Publisher: "Houghton Mifflin",
PageCount: 398
),
Format: BookFormat.Paperback,
Edition: "50th Anniversary Edition",
VolumeNumber: 1,
Series: new BookSeriesDto(
Title: "The Lord of the Rings"
),
Series: null,
ASIN: "B007978NPG",
GoodreadsId: "3",
LCCN: "54009621",
@@ -311,7 +311,6 @@ public class AddBookEndpointSummary : Summary<AddBookEndpoint, AddBookRequest>
)
);
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
@@ -1,9 +1,6 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingAvailability;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.WrittenContentLibrary.BookLibrary;
@@ -16,9 +13,9 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.Reading.GetReadingAvailability;
/// <summary>
/// API endpoint for the <c>/books/{bookId}/reading/availability</c> route.
/// API endpoint for the <c>/{libraryId}/books/{bookId}/reading/availability</c> route.
/// </summary>
public class GetReadingAvailabilityEndpoint : BaseEndpoint<GetReadingAvailabilityRequest, IResult>
public class GetReadingAvailabilityEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
{
private readonly IQueryHandler<GetReadingAvailabilityQuery, Result<ReadingAvailabilityResponse>> _getReadingAvailabilityQueryHandler;
@@ -36,20 +33,24 @@ public class GetReadingAvailabilityEndpoint : BaseEndpoint<GetReadingAvailabilit
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Verbs(FastEndpoints.Http.GET);
Routes(ApiRoutes.Books.GET_BOOK_READING_AVAILABILITY);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Checks the reading availability of the book identified by <paramref name="request"/>.
/// Checks the reading availability of the book identified by the route.
/// </summary>
/// <param name="request">The request containing the Id of the book whose reading availability is checked.</param>
/// <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(GetReadingAvailabilityRequest request, CancellationToken cancellationToken)
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
{
Result<ReadingAvailabilityResponse> result = await _getReadingAvailabilityQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
// Take unique identifiers from the route.
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
string? bookId = HttpContext.Request.RouteValues["bookId"]?.ToString();
GetReadingAvailabilityQuery query = new(libraryId, bookId);
Result<ReadingAvailabilityResponse> result = await _getReadingAvailabilityQueryHandler.HandleAsync(query, cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
using System;
using System.Collections.Generic;
@@ -13,7 +12,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.B
/// Class used for providing a textual description for the <see cref="GetReadingAvailabilityEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetReadingAvailabilityEndpointSummary : Summary<GetReadingAvailabilityEndpoint, GetReadingAvailabilityRequest>
public class GetReadingAvailabilityEndpointSummary : Summary<GetReadingAvailabilityEndpoint, EmptyRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetReadingAvailabilityEndpointSummary"/> class.
@@ -23,12 +22,6 @@ public class GetReadingAvailabilityEndpointSummary : Summary<GetReadingAvailabil
Summary = "Checks the reading availability of a book.";
Description = "Checks whether the book can be opened for reading, resolving the book reader configured for its media library and verifying that the reader is enabled, without extracting the book.";
ExampleRequest = new GetReadingAvailabilityRequest(
BookId: Guid.NewGuid()
);
RequestParam(r => r.BookId, "The Id of the book whose reading availability is checked. Required.");
ResponseParam<ReadingAvailabilityResponse>(r => r.BookId, "The Id of the book whose reading availability is reported.");
ResponseParam<ReadingAvailabilityResponse>(r => r.LibraryId, "The Id of the media library the book belongs to.");
ResponseParam<ReadingAvailabilityResponse>(r => r.IsAvailable, "Whether the book can be opened for reading.");
@@ -44,13 +37,32 @@ public class GetReadingAvailabilityEndpointSummary : Summary<GetReadingAvailabil
);
Response(401, "Authentication required.", "application/problem+json",
example: new
example: new[]
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/books/{bookId}/reading/availability"
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Authentication failed",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/availability"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token has expired",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/availability"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/availability"
}
}
);
@@ -58,23 +70,35 @@ public class GetReadingAvailabilityEndpointSummary : Summary<GetReadingAvailabil
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
title = "General.Unauthorized",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/books/{bookId}/reading/availability",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/availability",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the book does not exist.", "application/problem+json",
example: new
Response(404, "The request failed because the book or its media library does not exist.", "application/problem+json",
example: new[]
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "BookNotFound",
instance = "/api/v1/books/{bookId}/reading/availability",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "BookNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/availability",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/availability",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
}
);
@@ -85,12 +109,13 @@ public class GetReadingAvailabilityEndpointSummary : Summary<GetReadingAvailabil
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/books/{bookId}/reading/availability",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/availability",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"BookIdCannotBeEmpty"
}
}
@@ -1,9 +1,6 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingManifest;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.WrittenContentLibrary.BookLibrary;
@@ -16,9 +13,9 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.Reading.GetReadingManifest;
/// <summary>
/// API endpoint for the <c>/books/{bookId}/reading/manifest</c> route.
/// API endpoint for the <c>/{libraryId}/books/{bookId}/reading/manifest</c> route.
/// </summary>
public class GetReadingManifestEndpoint : BaseEndpoint<GetReadingManifestRequest, IResult>
public class GetReadingManifestEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
{
private readonly IQueryHandler<GetReadingManifestQuery, Result<ReadingManifestResponse>> _getReadingManifestQueryHandler;
@@ -36,20 +33,24 @@ public class GetReadingManifestEndpoint : BaseEndpoint<GetReadingManifestRequest
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Verbs(FastEndpoints.Http.GET);
Routes(ApiRoutes.Books.GET_BOOK_READING_MANIFEST);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the reading manifest of the book identified by <paramref name="request"/>.
/// Gets the reading manifest of the book identified by the route.
/// </summary>
/// <param name="request">The request containing the Id of the book whose reading manifest is retrieved.</param>
/// <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(GetReadingManifestRequest request, CancellationToken cancellationToken)
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
{
Result<ReadingManifestResponse> result = await _getReadingManifestQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
// Take unique identifiers from the route.
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
string? bookId = HttpContext.Request.RouteValues["bookId"]?.ToString();
GetReadingManifestQuery query = new(libraryId, bookId);
Result<ReadingManifestResponse> result = await _getReadingManifestQueryHandler.HandleAsync(query, cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
using System;
using System.Collections.Generic;
@@ -13,7 +12,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.B
/// Class used for providing a textual description for the <see cref="GetReadingManifestEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetReadingManifestEndpointSummary : Summary<GetReadingManifestEndpoint, GetReadingManifestRequest>
public class GetReadingManifestEndpointSummary : Summary<GetReadingManifestEndpoint, EmptyRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetReadingManifestEndpointSummary"/> class.
@@ -23,16 +22,16 @@ public class GetReadingManifestEndpointSummary : Summary<GetReadingManifestEndpo
Summary = "Retrieves the reading manifest of a book.";
Description = "Retrieves the reading manifest of a book, containing the metadata, the table of contents, the spine, and the resources needed to render the reader.";
ExampleRequest = new GetReadingManifestRequest(
BookId: Guid.NewGuid()
);
RequestParam(r => r.BookId, "The Id of the book whose reading manifest is retrieved. Required.");
ResponseParam<ReadingManifestResponse>(r => r.Title, "The title of the book.");
ResponseParam<ReadingManifestResponse>(r => r.Author, "The author of the book, if known.");
ResponseParam<ReadingManifestResponse>(r => r.CoverResourceKey, "The resource key of the cover image of the book, if applicable.");
ResponseParam<ReadingManifestResponse>(r => r.TableOfContents, "The hierarchical table of contents of the book.");
ResponseParam<ReadingManifestResponse>(r => r.TableOfContents[0].Label, "The label of the table of contents entry.");
ResponseParam<ReadingManifestResponse>(r => r.TableOfContents[0].LocationRef, "The opaque location reference of the reading section the entry points to.");
ResponseParam<ReadingManifestResponse>(r => r.TableOfContents[0].Children, "The child entries of the table of contents entry.");
ResponseParam<ReadingManifestResponse>(r => r.Spine, "The ordered spine of the reading sections of the book.");
ResponseParam<ReadingManifestResponse>(r => r.Spine[0].LocationRef, "The opaque location reference of the reading section.");
ResponseParam<ReadingManifestResponse>(r => r.Spine[0].Title, "The title of the reading section, if known.");
ResponseParam<ReadingManifestResponse>(r => r.ResourceKeys, "The resource keys of the resources of the book.");
ResponseParam<ReadingManifestResponse>(r => r.HasTextContent, "Whether the book has extractable text content. A scanned book, whose pages are only images, has no text content.");
@@ -62,13 +61,32 @@ public class GetReadingManifestEndpointSummary : Summary<GetReadingManifestEndpo
);
Response(401, "Authentication required.", "application/problem+json",
example: new
example: new[]
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/books/{bookId}/reading/manifest"
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Authentication failed",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/manifest"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token has expired",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/manifest"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/manifest"
}
}
);
@@ -76,23 +94,62 @@ public class GetReadingManifestEndpointSummary : Summary<GetReadingManifestEndpo
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
title = "General.Unauthorized",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/books/{bookId}/reading/manifest",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/manifest",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the book does not exist, no reader plugin supports its format, or the reader plugin is disabled.", "application/problem+json",
example: new
Response(404, "The request failed because the book or its media library does not exist, no reader plugin supports its format, the reader plugin is disabled, or the file of the book does not exist.", "application/problem+json",
example: new[]
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ReaderDisabled",
instance = "/api/v1/books/{bookId}/reading/manifest",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "BookNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/manifest",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/manifest",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "NoReaderAvailable",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/manifest",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ReaderDisabled",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/manifest",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "BookFileNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/manifest",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
}
);
@@ -103,12 +160,13 @@ public class GetReadingManifestEndpointSummary : Summary<GetReadingManifestEndpo
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/books/{bookId}/reading/manifest",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/manifest",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"BookIdCannotBeEmpty"
}
}
@@ -1,10 +1,7 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingResource;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.WrittenContentLibrary.BookLibrary;
using Lumina.Presentation.Api.Core.Endpoints.Common;
@@ -17,9 +14,9 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.Reading.GetReadingResource;
/// <summary>
/// API endpoint for the <c>/books/{bookId}/reading/resources/{resourceKey}</c> route.
/// API endpoint for the <c>/{libraryId}/books/{bookId}/reading/resources/{resourceKey}</c> route.
/// </summary>
public class GetReadingResourceEndpoint : BaseEndpoint<GetReadingResourceRequest, IResult>
public class GetReadingResourceEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
{
private readonly IQueryHandler<GetReadingResourceQuery, Result<ReadingResourceDataDto>> _getReadingResourceQueryHandler;
@@ -37,20 +34,25 @@ public class GetReadingResourceEndpoint : BaseEndpoint<GetReadingResourceRequest
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Verbs(FastEndpoints.Http.GET);
Routes(ApiRoutes.Books.GET_BOOK_READING_RESOURCE);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the resource of the book identified by <paramref name="request"/>.
/// Gets the resource of the book identified by the route.
/// </summary>
/// <param name="request">The request containing the Id of the book and the resource key of the resource.</param>
/// <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(GetReadingResourceRequest request, CancellationToken cancellationToken)
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
{
Result<ReadingResourceDataDto> result = await _getReadingResourceQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
// Take unique identifiers from the route.
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
string? bookId = HttpContext.Request.RouteValues["bookId"]?.ToString();
string? resourceKey = HttpContext.Request.RouteValues["resourceKey"]?.ToString();
GetReadingResourceQuery query = new(libraryId, bookId, resourceKey);
Result<ReadingResourceDataDto> result = await _getReadingResourceQueryHandler.HandleAsync(query, cancellationToken).ConfigureAwait(false);
if (result.IsFailure)
return Problem(result.Errors);
// The media type of a resource is declared by the book itself, so it is not trusted: a resource whose declared media type could be
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -12,7 +11,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.B
/// Class used for providing a textual description for the <see cref="GetReadingResourceEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetReadingResourceEndpointSummary : Summary<GetReadingResourceEndpoint, GetReadingResourceRequest>
public class GetReadingResourceEndpointSummary : Summary<GetReadingResourceEndpoint, EmptyRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetReadingResourceEndpointSummary"/> class.
@@ -22,24 +21,35 @@ public class GetReadingResourceEndpointSummary : Summary<GetReadingResourceEndpo
Summary = "Retrieves a resource of a book, for reading.";
Description = "Retrieves the binary content of a resource of a book, such as an image or a font referenced by a reading section.";
ExampleRequest = new GetReadingResourceRequest(
BookId: Guid.NewGuid(),
ResourceKey: "cover-image"
);
RequestParam(r => r.BookId, "The Id of the book whose resource is retrieved. Required.");
RequestParam(r => r.ResourceKey, "The opaque resource key of the resource. Required.");
Response(200, "The resource of the book is returned.");
Response(200, "The binary resource of the book is returned, with the media type of the resource, or application/octet-stream for media types that could be rendered as active documents.", "*/*");
Response(401, "Authentication required.", "application/problem+json",
example: new
example: new[]
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/books/{bookId}/reading/resources/{resourceKey}"
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Authentication failed",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/resources/cover-image"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token has expired",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/resources/cover-image"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/resources/cover-image"
}
}
);
@@ -47,23 +57,71 @@ public class GetReadingResourceEndpointSummary : Summary<GetReadingResourceEndpo
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
title = "General.Unauthorized",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/books/{bookId}/reading/resources/{resourceKey}",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/resources/cover-image",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the book does not exist, no reader plugin supports its format, the reader plugin is disabled, or the resource was not found.", "application/problem+json",
example: new
Response(404, "The request failed because the book or its media library does not exist, no reader plugin supports its format, the reader plugin is disabled, the file of the book does not exist, or the resource was not found.", "application/problem+json",
example: new[]
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ResourceNotFound",
instance = "/api/v1/books/{bookId}/reading/resources/{resourceKey}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "BookNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/resources/cover-image",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/resources/cover-image",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "NoReaderAvailable",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/resources/cover-image",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ReaderDisabled",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/resources/cover-image",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "BookFileNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/resources/cover-image",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ResourceNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/resources/cover-image",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
}
);
@@ -74,12 +132,13 @@ public class GetReadingResourceEndpointSummary : Summary<GetReadingResourceEndpo
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/books/{bookId}/reading/resources/{resourceKey}",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/resources/cover-image",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"BookIdCannotBeEmpty",
"ResourceKeyCannotBeEmpty"
}
@@ -1,10 +1,7 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingSection;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.WrittenContentLibrary.BookLibrary;
using Lumina.Presentation.Api.Core.Endpoints.Common;
@@ -16,9 +13,9 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.Reading.GetReadingSection;
/// <summary>
/// API endpoint for the <c>/books/{bookId}/reading/sections/{locationRef}</c> route.
/// API endpoint for the <c>/{libraryId}/books/{bookId}/reading/sections/{locationRef}</c> route.
/// </summary>
public class GetReadingSectionEndpoint : BaseEndpoint<GetReadingSectionRequest, IResult>
public class GetReadingSectionEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
{
private readonly IQueryHandler<GetReadingSectionQuery, Result<ReadingSectionDto>> _getReadingSectionQueryHandler;
@@ -36,20 +33,25 @@ public class GetReadingSectionEndpoint : BaseEndpoint<GetReadingSectionRequest,
/// </summary>
public override void Configure()
{
Verbs(Http.GET);
Verbs(FastEndpoints.Http.GET);
Routes(ApiRoutes.Books.GET_BOOK_READING_SECTION);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the content of the reading section of the book identified by <paramref name="request"/>.
/// Gets the content of the reading section of the book identified by the route.
/// </summary>
/// <param name="request">The request containing the Id of the book and the location reference of the reading section.</param>
/// <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(GetReadingSectionRequest request, CancellationToken cancellationToken)
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
{
Result<ReadingSectionDto> result = await _getReadingSectionQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
// Take unique identifiers from the route.
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
string? bookId = HttpContext.Request.RouteValues["bookId"]?.ToString();
string? locationRef = HttpContext.Request.RouteValues["locationRef"]?.ToString();
GetReadingSectionQuery query = new(libraryId, bookId, locationRef);
Result<ReadingSectionDto> result = await _getReadingSectionQueryHandler.HandleAsync(query, cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary.Reading;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -13,7 +12,7 @@ namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.B
/// Class used for providing a textual description for the <see cref="GetReadingSectionEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetReadingSectionEndpointSummary : Summary<GetReadingSectionEndpoint, GetReadingSectionRequest>
public class GetReadingSectionEndpointSummary : Summary<GetReadingSectionEndpoint, EmptyRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetReadingSectionEndpointSummary"/> class.
@@ -23,14 +22,6 @@ public class GetReadingSectionEndpointSummary : Summary<GetReadingSectionEndpoin
Summary = "Retrieves the content of a reading section of a book.";
Description = "Retrieves the sanitized HTML content of the reading section of a book, ready to be rendered by the client.";
ExampleRequest = new GetReadingSectionRequest(
BookId: Guid.NewGuid(),
LocationRef: "chapter-1"
);
RequestParam(r => r.BookId, "The Id of the book whose reading section is retrieved. Required.");
RequestParam(r => r.LocationRef, "The opaque location reference of the reading section. Required.");
ResponseParam<ReadingSectionDto>(r => r.LocationRef, "The opaque location reference of the reading section.");
ResponseParam<ReadingSectionDto>(r => r.Title, "The title of the reading section, if known.");
ResponseParam<ReadingSectionDto>(r => r.ContentHtml, "The sanitized HTML content of the reading section.");
@@ -44,13 +35,32 @@ public class GetReadingSectionEndpointSummary : Summary<GetReadingSectionEndpoin
);
Response(401, "Authentication required.", "application/problem+json",
example: new
example: new[]
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/books/{bookId}/reading/sections/{locationRef}"
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Authentication failed",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/sections/chapter-1"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token has expired",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/sections/chapter-1"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/sections/chapter-1"
}
}
);
@@ -58,23 +68,71 @@ public class GetReadingSectionEndpointSummary : Summary<GetReadingSectionEndpoin
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
title = "General.Failure",
title = "General.Unauthorized",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/books/{bookId}/reading/sections/{locationRef}",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/sections/chapter-1",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the book does not exist, no reader plugin supports its format, the reader plugin is disabled, or the reading section was not found.", "application/problem+json",
example: new
Response(404, "The request failed because the book or its media library does not exist, no reader plugin supports its format, the reader plugin is disabled, the file of the book does not exist, or the reading section was not found.", "application/problem+json",
example: new[]
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "SectionNotFound",
instance = "/api/v1/books/{bookId}/reading/sections/{locationRef}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "BookNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/sections/chapter-1",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/sections/chapter-1",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "NoReaderAvailable",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/sections/chapter-1",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "ReaderDisabled",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/sections/chapter-1",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "BookFileNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/sections/chapter-1",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "SectionNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/sections/chapter-1",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
}
);
@@ -85,12 +143,13 @@ public class GetReadingSectionEndpointSummary : Summary<GetReadingSectionEndpoin
title = "General.Validation",
status = 422,
detail = "OneOrMoreValidationErrorsOccurred",
instance = "/api/v1/books/{bookId}/reading/sections/{locationRef}",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/reading/sections/chapter-1",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"BookIdCannotBeEmpty",
"LocationRefCannotBeEmpty"
}
@@ -48,7 +48,7 @@ public class UpdateBookEndpoint : BaseEndpoint<UpdateBookRequest, IResult>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(UpdateBookRequest request, CancellationToken cancellationToken)
{
// take unique identifiers from the route
// Take unique identifiers from the route.
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
string? bookId = HttpContext.Request.RouteValues["bookId"]?.ToString();
Result<BookResponse> result = await _updateBookCommandHandler.HandleAsync(request.ToCommand(libraryId, bookId), cancellationToken).ConfigureAwait(false);
@@ -1,4 +1,4 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
@@ -27,8 +27,8 @@ public class UpdateBookEndpointSummary : Summary<UpdateBookEndpoint, UpdateBookR
/// </summary>
public UpdateBookEndpointSummary()
{
Summary = "Updates a book.";
Description = "Updates the details of the book identified by the request.";
Summary = "Updates an existing book.";
Description = "Updates the details of the book identified by the request. The request is handled by an Admin, who can update the books of all libraries, or by the owner of the library.";
RequestParam(r => r.Metadata, "The written content metadata of the book. Required.");
RequestParam(r => r.Metadata!.Title, "The title of the book. Required.");
@@ -258,9 +258,7 @@ public class UpdateBookEndpointSummary : Summary<UpdateBookEndpoint, UpdateBookR
Format: BookFormat.Paperback,
Edition: "50th Anniversary Edition",
VolumeNumber: 1,
Series: new BookSeriesDto(
Title: "The Lord of the Rings"
),
Series: null,
ASIN: "B007978NPG",
GoodreadsId: "3",
LCCN: "54009621",
@@ -371,6 +369,15 @@ public class UpdateBookEndpointSummary : Summary<UpdateBookEndpoint, UpdateBookR
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Commands.UpdateBookCover;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.WrittenContentLibrary.BookLibrary;
using Lumina.Presentation.Api.Core.Endpoints.Common;
@@ -14,17 +15,17 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.UpdateBookCover;
/// <summary>
/// API endpoint for the <c>/books/{id}/cover</c> route.
/// API endpoint for the <c>/books/{bookId}/cover</c> route.
/// </summary>
public class UpdateBookCoverEndpoint : BaseEndpoint<EmptyRequest, IResult>
public class UpdateBookCoverEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
{
private readonly Application.Common.CQRS.ICommandHandler<UpdateBookCoverCommand, Result<string>> _updateBookCoverCommandHandler;
private readonly ICommandHandler<UpdateBookCoverCommand, Result<UpdateBookCoverResponse>> _updateBookCoverCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="UpdateBookCoverEndpoint"/> class.
/// </summary>
/// <param name="updateBookCoverCommandHandler">Injected service for handling update book cover commands.</param>
public UpdateBookCoverEndpoint(Application.Common.CQRS.ICommandHandler<UpdateBookCoverCommand, Result<string>> updateBookCoverCommandHandler)
public UpdateBookCoverEndpoint(ICommandHandler<UpdateBookCoverCommand, Result<UpdateBookCoverResponse>> updateBookCoverCommandHandler)
{
_updateBookCoverCommandHandler = updateBookCoverCommandHandler;
}
@@ -34,7 +35,7 @@ public class UpdateBookCoverEndpoint : BaseEndpoint<EmptyRequest, IResult>
/// </summary>
public override void Configure()
{
Verbs(Http.PUT);
Verbs(FastEndpoints.Http.PUT);
Routes(ApiRoutes.Books.UPDATE_BOOK_COVER);
Version(1);
DontCatchExceptions();
@@ -45,11 +46,11 @@ public class UpdateBookCoverEndpoint : BaseEndpoint<EmptyRequest, IResult>
/// </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)
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
{
// The endpoint takes no typed request, because its body is a multipart file, so the book id is read from the {id} route
// value; an unparseable value becomes Guid.Empty, which the command validator reports as a missing book id.
Guid bookId = Guid.TryParse(HttpContext.Request.RouteValues["id"]?.ToString(), out Guid parsedBookId) ? parsedBookId : Guid.Empty;
// Take the identifiers from the route.
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
string? bookId = HttpContext.Request.RouteValues["bookId"]?.ToString();
IFormFile? cover = null;
if (HttpContext.Request.HasFormContentType)
@@ -67,10 +68,10 @@ public class UpdateBookCoverEndpoint : BaseEndpoint<EmptyRequest, IResult>
}
// The cover stream must stay open while the handler stores the image, and is disposed as soon as the handler returns.
UpdateBookCoverCommand command = new(bookId, cover?.OpenReadStream(), cover?.FileName);
UpdateBookCoverCommand command = new(libraryId, bookId, cover?.OpenReadStream(), cover?.FileName);
try
{
Result<string> result = await _updateBookCoverCommandHandler.HandleAsync(command, cancellationToken).ConfigureAwait(false);
Result<UpdateBookCoverResponse> result = await _updateBookCoverCommandHandler.HandleAsync(command, cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
finally
@@ -1,5 +1,7 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -21,17 +23,38 @@ public class UpdateBookCoverEndpointSummary : Summary<UpdateBookCoverEndpoint, E
Description = "Updates the cover image of the book identified by the request, with the image uploaded in the multipart form of the request.";
Response(200, "The relative path of the stored cover image is returned.",
example: "/media/books/books-3f2504e0-4f89-41d3-9a0c-0305e82c3301/The Lord of the Rings-2b0e5f5a-0b3f-4b7e-8f4a-8c9e3d2f5a6b/cover.jpg"
example: new UpdateBookCoverResponse(
CoverPath: "/media/books/books-3f2504e0-4f89-41d3-9a0c-0305e82c3301/The Lord of the Rings-2b0e5f5a-0b3f-4b7e-8f4a-8c9e3d2f5a6b/cover.jpg"
)
);
Response(401, "Authentication required.", "application/problem+json",
example: new
example: new[]
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "You are not authorized",
instance = "/api/v1/books/{id}/cover"
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Authentication failed",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/cover"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token has expired",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/cover"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token is invalid",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/cover"
}
}
);
@@ -42,38 +65,52 @@ public class UpdateBookCoverEndpointSummary : Summary<UpdateBookCoverEndpoint, E
title = "General.Unauthorized",
status = 403,
detail = "NotAuthorized",
instance = "/api/v1/books/{id}/cover",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/cover",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(404, "The request failed because the book or its media library does not exist.", "application/problem+json",
example: new
example: new[]
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "BookNotFound",
instance = "/api/v1/books/{id}/cover",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "BookNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/cover",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
},
new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
title = "General.NotFound",
status = 404,
detail = "LibraryNotFound",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/cover",
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
}
}
);
Response(422, "The request did not pass validation checks.", "application/problem+json",
Response(422, "The request did not pass validation checks, either on the request itself or while storing the uploaded cover image.", "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/books/{id}/cover",
instance = $"/api/v1/libraries/{Guid.NewGuid()}/books/{Guid.NewGuid()}/cover",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"BookIdCannotBeEmpty",
"BookCoverCannotBeNull",
"FileNameCannotBeEmpty",
"FileTooLarge",
"CoverFileMustBeAnImage"
}