mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11:10 +00:00
Adds playlist management and playback
This commit is contained in:
1 parent
009a0c8156
commit
9889c86c76
296 files changed
+18830
-367
No files matched your search
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Playlists;
|
||||
using Lumina.Application.Core.Playlists.Commands.AddPlaylistEntries;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Playlists;
|
||||
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.Playlists.AddPlaylistEntries;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/playlists/{playlistId}/entries-batch</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class AddPlaylistEntriesEndpoint : BaseEndpoint<AddPlaylistEntriesRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<AddPlaylistEntriesCommand, Result<PlaylistEntriesAddedResponse>> _addPlaylistEntriesCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddPlaylistEntriesEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="addPlaylistEntriesCommandHandler">Injected service for handling add playlist entries commands.</param>
|
||||
public AddPlaylistEntriesEndpoint(ICommandHandler<AddPlaylistEntriesCommand, Result<PlaylistEntriesAddedResponse>> addPlaylistEntriesCommandHandler)
|
||||
{
|
||||
_addPlaylistEntriesCommandHandler = addPlaylistEntriesCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.Playlists.ADD_PLAYLIST_ENTRIES);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds several tracks to the end of the ordered entries of a playlist of the current user, in order.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the tracks to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(AddPlaylistEntriesRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The playlist is identified by the route value, not by any id posted in the body.
|
||||
string? playlistId = HttpContext.Request.RouteValues["playlistId"]?.ToString();
|
||||
Result<PlaylistEntriesAddedResponse> result = await _addPlaylistEntriesCommandHandler.HandleAsync(request.ToCommand(playlistId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Playlists.AddPlaylistEntries;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="AddPlaylistEntriesEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddPlaylistEntriesEndpointSummary : Summary<AddPlaylistEntriesEndpoint, AddPlaylistEntriesRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddPlaylistEntriesEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public AddPlaylistEntriesEndpointSummary()
|
||||
{
|
||||
Summary = "Adds several tracks to a playlist of the current user.";
|
||||
Description = "Adds several tracks to the end of the ordered entries of the playlist identified by its Id, when the playlist belongs to the currently authenticated user, in the order the request lists them. Every track must exist, and the media library of every track must be reachable by the current user; a missing track and an unreachable library are both reported as not found, so the response never reveals whether a track exists in another user's library. The playlist must accept music tracks, which is the only media kind exposed until video libraries are catalogued. The same track may appear more than once. The request is applied as a whole: when any track is missing or not reachable, no entry is added. The tracks are inserted in bounded batches, so a long queue is accepted.";
|
||||
|
||||
ExampleRequest = new AddPlaylistEntriesRequest(
|
||||
TrackIds:
|
||||
[
|
||||
Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"),
|
||||
Guid.Parse("8e1f2a3b-4c5d-4e6f-8a9b-0c1d2e3f4a5b")
|
||||
]
|
||||
);
|
||||
RequestParam(request => request.TrackIds, "The Ids of the tracks to add, in the order they must take. Required.");
|
||||
|
||||
ResponseParam<PlaylistEntriesAddedResponse>(response => response.PlaylistId, "The Id of the playlist the entries were added to.");
|
||||
ResponseParam<PlaylistEntriesAddedResponse>(response => response.AddedCount, "The number of entries that were appended, including repeated tracks.");
|
||||
ResponseParam<PlaylistEntriesAddedResponse>(response => response.UpdatedOnUtc, "The date and time when the playlist was last updated, if applicable.");
|
||||
|
||||
Response(200, "The number of added entries is returned with the playlist activity time.",
|
||||
example: new PlaylistEntriesAddedResponse(
|
||||
PlaylistId: Guid.Parse("1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"),
|
||||
AddedCount: 12,
|
||||
UpdatedOnUtc: new DateTime(2026, 10, 20, 12, 0, 0, DateTimeKind.Utc)
|
||||
)
|
||||
);
|
||||
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-batch"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token has expired",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-batch"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-batch"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the playlist does not accept music tracks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Forbidden",
|
||||
status = 403,
|
||||
detail = "PlaylistDoesNotAcceptMediaItems",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-batch",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the playlist does not exist, does not belong to the current user, or a track does not exist or is not reachable.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "PlaylistNotFound",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-batch",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "TrackNotFound",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-batch",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because the entries could not be stored, because of a conflicting row or because the database is busy.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "UniqueConstraintViolation",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-batch",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "ConcurrencyConflict",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-batch",
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-batch",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlaylistIdCannotBeEmpty",
|
||||
"TrackIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Playlists;
|
||||
using Lumina.Application.Core.Playlists.Commands.AddPlaylistEntry;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Playlists;
|
||||
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.Playlists.AddPlaylistEntry;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/playlists/{playlistId}/entries</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class AddPlaylistEntryEndpoint : BaseEndpoint<AddPlaylistEntryRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<AddPlaylistEntryCommand, Result<PlaylistEntryAddedResponse>> _addPlaylistEntryCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddPlaylistEntryEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="addPlaylistEntryCommandHandler">Injected service for handling add playlist entry commands.</param>
|
||||
public AddPlaylistEntryEndpoint(ICommandHandler<AddPlaylistEntryCommand, Result<PlaylistEntryAddedResponse>> addPlaylistEntryCommandHandler)
|
||||
{
|
||||
_addPlaylistEntryCommandHandler = addPlaylistEntryCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.Playlists.ADD_PLAYLIST_ENTRY);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a track to the end of the ordered entries of a playlist of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the track to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(AddPlaylistEntryRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The playlist is identified by the route value, not by any id posted in the body.
|
||||
string? playlistId = HttpContext.Request.RouteValues["playlistId"]?.ToString();
|
||||
Result<PlaylistEntryAddedResponse> result = await _addPlaylistEntryCommandHandler.HandleAsync(request.ToCommand(playlistId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Playlists.AddPlaylistEntry;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="AddPlaylistEntryEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddPlaylistEntryEndpointSummary : Summary<AddPlaylistEntryEndpoint, AddPlaylistEntryRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddPlaylistEntryEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public AddPlaylistEntryEndpointSummary()
|
||||
{
|
||||
Summary = "Adds a track to a playlist of the current user.";
|
||||
Description = "Adds a track to the end of the ordered entries of the playlist identified by its Id, when the playlist belongs to the currently authenticated user. The track must exist, and its media library must be reachable by the current user; a missing track and an unreachable library are both reported as not found, so the response never reveals whether a track exists in another user's library. The playlist must accept music tracks, which is the only media kind exposed until video libraries are catalogued. The same track may appear in a playlist more than once.";
|
||||
|
||||
ExampleRequest = new AddPlaylistEntryRequest(
|
||||
TrackId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f")
|
||||
);
|
||||
RequestParam(request => request.TrackId, "The Id of the track to add. Required.");
|
||||
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.PlaylistId, "The Id of the playlist the entry was added to.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry, "The added entry.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry.Id, "The Id of the added entry.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry.MediaItemId, "The Id of the media item the entry references.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry.MediaItemType, "The kind of media item the entry references.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry.Position, "The zero based position of the entry in the playlist.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry.LibraryId, "The Id of the media library that contains the media item.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry.CollectionId, "The Id of the collection that contains the media item.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry.CreatorId, "The Id of the creator of the media item.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry.MediaItemTitle, "The title of the media item.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry.CollectionTitle, "The title of the collection that contains the media item.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry.CreatorName, "The name of the creator of the media item.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry.DurationInSeconds, "The duration of the media item in seconds.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.Entry.CoverPath, "The path of the cover art of the collection, if available.");
|
||||
ResponseParam<PlaylistEntryAddedResponse>(response => response.UpdatedOnUtc, "The date and time when the playlist was last updated.");
|
||||
|
||||
Response(200, "The added entry is returned with the playlist activity time.",
|
||||
example: new PlaylistEntryAddedResponse(
|
||||
PlaylistId: Guid.Parse("1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"),
|
||||
Entry: new PlaylistEntryResponse(
|
||||
Id: Guid.Parse("2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d"),
|
||||
MediaItemId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"),
|
||||
MediaItemType: PlaylistMediaItemType.MusicTrack,
|
||||
Position: 11,
|
||||
LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"),
|
||||
CollectionId: Guid.Parse("e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f"),
|
||||
CreatorId: Guid.Parse("d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a"),
|
||||
MediaItemTitle: "The Show Must Go On",
|
||||
CollectionTitle: "Innuendo",
|
||||
CreatorName: "Queen",
|
||||
DurationInSeconds: 262,
|
||||
CoverPath: "/artwork/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
),
|
||||
UpdatedOnUtc: new DateTime(2026, 10, 20, 12, 0, 0, DateTimeKind.Utc)
|
||||
)
|
||||
);
|
||||
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token has expired",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the playlist does not accept music tracks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Forbidden",
|
||||
status = 403,
|
||||
detail = "PlaylistDoesNotAcceptMediaItems",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the playlist does not exist, does not belong to the current user, or the track does not exist or is not reachable.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "PlaylistNotFound",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "TrackNotFound",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because the entry could not be stored, because of a conflicting row or because the database is busy.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "UniqueConstraintViolation",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "ConcurrencyConflict",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries",
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlaylistIdCannotBeEmpty",
|
||||
"TrackIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Playlists;
|
||||
using Lumina.Application.Core.Playlists.Commands.AddPlaylistScopeEntries;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Playlists;
|
||||
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.Playlists.AddPlaylistScopeEntries;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/playlists/{playlistId}/entries-scope</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class AddPlaylistScopeEntriesEndpoint : BaseEndpoint<AddPlaylistScopeEntriesRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<AddPlaylistScopeEntriesCommand, Result<PlaylistEntriesAddedResponse>> _addPlaylistScopeEntriesCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddPlaylistScopeEntriesEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="addPlaylistScopeEntriesCommandHandler">Injected service for handling add playlist scope entries commands.</param>
|
||||
public AddPlaylistScopeEntriesEndpoint(ICommandHandler<AddPlaylistScopeEntriesCommand, Result<PlaylistEntriesAddedResponse>> addPlaylistScopeEntriesCommandHandler)
|
||||
{
|
||||
_addPlaylistScopeEntriesCommandHandler = addPlaylistScopeEntriesCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.Playlists.ADD_PLAYLIST_SCOPE_ENTRIES);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds every track of a music library, an artist or an album to a playlist of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the scope whose tracks are appended.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(AddPlaylistScopeEntriesRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The playlist is identified by the route value, not by any id posted in the body.
|
||||
string? playlistId = HttpContext.Request.RouteValues["playlistId"]?.ToString();
|
||||
Result<PlaylistEntriesAddedResponse> result = await _addPlaylistScopeEntriesCommandHandler.HandleAsync(request.ToCommand(playlistId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Playlists.AddPlaylistScopeEntries;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="AddPlaylistScopeEntriesEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddPlaylistScopeEntriesEndpointSummary : Summary<AddPlaylistScopeEntriesEndpoint, AddPlaylistScopeEntriesRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddPlaylistScopeEntriesEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public AddPlaylistScopeEntriesEndpointSummary()
|
||||
{
|
||||
Summary = "Adds every track of a library, artist or album to a playlist of the current user.";
|
||||
Description = "Appends every track of the music library identified by libraryId, optionally limited to an artist or an album, to the end of the ordered entries of the playlist identified by its Id. The server resolves the scope in catalogue order with one set-based statement, so a whole library is appended without materializing its track Ids, sorting them in memory or sending them to the data access layer. The playlist must belong to the currently authenticated user, and the library must be reachable by the current user. An empty scope appends nothing and reports a zero count without an activity time. The same track may appear in a playlist more than once.";
|
||||
|
||||
ExampleRequest = new AddPlaylistScopeEntriesRequest(
|
||||
LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"),
|
||||
ArtistId: Guid.Parse("d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a"),
|
||||
AlbumId: Guid.Parse("e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f")
|
||||
);
|
||||
RequestParam(request => request.LibraryId, "The Id of the music library the scope belongs to. Required.");
|
||||
RequestParam(request => request.ArtistId, "The Id of the artist the scope is limited to. Optional.");
|
||||
RequestParam(request => request.AlbumId, "The Id of the album the scope is limited to. Optional.");
|
||||
|
||||
ResponseParam<PlaylistEntriesAddedResponse>(response => response.PlaylistId, "The Id of the playlist the entries were added to.");
|
||||
ResponseParam<PlaylistEntriesAddedResponse>(response => response.AddedCount, "The number of entries that were appended, including repeated tracks.");
|
||||
ResponseParam<PlaylistEntriesAddedResponse>(response => response.UpdatedOnUtc, "The date and time when the playlist was last updated, if applicable.");
|
||||
|
||||
Response(200, "The scope was appended to the playlist.",
|
||||
example: new PlaylistEntriesAddedResponse(
|
||||
PlaylistId: Guid.Parse("1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"),
|
||||
AddedCount: 120,
|
||||
UpdatedOnUtc: new DateTime(2026, 10, 20, 12, 0, 0, DateTimeKind.Utc)
|
||||
)
|
||||
);
|
||||
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-scope"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token has expired",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-scope"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-scope"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the library is not accessible to the current user.", "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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-scope",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the playlist does not exist, or it does not belong to the current user.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "PlaylistNotFound",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-scope",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because the entries could not be stored, because of a conflicting row or because the database is busy.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "UniqueConstraintViolation",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-scope",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "ConcurrencyConflict",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-scope",
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries-scope",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlaylistIdCannotBeEmpty",
|
||||
"LibraryIdCannotBeEmpty",
|
||||
"ArtistIdCannotBeEmpty",
|
||||
"AlbumIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Playlists;
|
||||
using Lumina.Application.Core.Playlists.Commands.CreatePlaylist;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Playlists;
|
||||
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.Playlists.CreatePlaylist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/playlists</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class CreatePlaylistEndpoint : BaseEndpoint<CreatePlaylistRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<CreatePlaylistCommand, Result<PlaylistResponse>> _createPlaylistCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CreatePlaylistEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="createPlaylistCommandHandler">Injected service for handling create playlist commands.</param>
|
||||
public CreatePlaylistEndpoint(ICommandHandler<CreatePlaylistCommand, Result<PlaylistResponse>> createPlaylistCommandHandler)
|
||||
{
|
||||
_createPlaylistCommandHandler = createPlaylistCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.Playlists.CREATE_PLAYLIST);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a playlist of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the details of the playlist to create.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(CreatePlaylistRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
Result<PlaylistResponse> result = await _createPlaylistCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Playlists.CreatePlaylist;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="CreatePlaylistEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CreatePlaylistEndpointSummary : Summary<CreatePlaylistEndpoint, CreatePlaylistRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CreatePlaylistEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public CreatePlaylistEndpointSummary()
|
||||
{
|
||||
Summary = "Creates a playlist of the current user.";
|
||||
Description = "Creates a playlist that belongs to the currently authenticated user. The name is required, while the description is optional. The type decides which media items the playlist accepts. Only the music type is exposed, because video libraries are not catalogued yet; the entry model and the storage already carry a generic media item kind, so exposing video playlists later does not require a schema change. The new playlist starts empty.";
|
||||
|
||||
ExampleRequest = new CreatePlaylistRequest(
|
||||
Name: "Evening listening",
|
||||
Description: "Quiet tracks for the end of the day.",
|
||||
Type: PlaylistType.Music
|
||||
);
|
||||
RequestParam(request => request.Name, "The name of the playlist. Required, maximum 255 characters.");
|
||||
RequestParam(request => request.Description, "The description of the playlist. Optional, maximum 2000 characters.");
|
||||
RequestParam(request => request.Type, "The kind of media the playlist holds. Required. Only Music is currently supported.");
|
||||
|
||||
ResponseParam<PlaylistResponse>(response => response.Id, "The Id of the playlist.");
|
||||
ResponseParam<PlaylistResponse>(response => response.Name, "The name of the playlist.");
|
||||
ResponseParam<PlaylistResponse>(response => response.Description, "The description of the playlist, if applicable.");
|
||||
ResponseParam<PlaylistResponse>(response => response.Type, "The kind of media the playlist holds.");
|
||||
ResponseParam<PlaylistResponse>(response => response.Entries, "The ordered entries of the playlist.");
|
||||
ResponseParam<PlaylistResponse>(response => response.EntryCount, "The total number of entries the playlist holds, even when only a window of them is returned.");
|
||||
ResponseParam<PlaylistResponse>(response => response.CreatedOnUtc, "The date and time when the playlist was created.");
|
||||
ResponseParam<PlaylistResponse>(response => response.UpdatedOnUtc, "The date and time when the playlist was last updated, if applicable.");
|
||||
|
||||
Response(200, "The playlist was created and is returned.",
|
||||
example: new PlaylistResponse(
|
||||
Id: Guid.Parse("1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"),
|
||||
Name: "Evening listening",
|
||||
Description: "Quiet tracks for the end of the day.",
|
||||
Type: PlaylistType.Music,
|
||||
Entries: [],
|
||||
EntryCount: 0,
|
||||
CreatedOnUtc: new DateTime(2026, 10, 21, 12, 0, 0, DateTimeKind.Utc),
|
||||
UpdatedOnUtc: null
|
||||
)
|
||||
);
|
||||
|
||||
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/users/me/playlists"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token has expired",
|
||||
instance = "/api/v1/users/me/playlists"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/users/me/playlists"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because the playlist could not be stored, because of a conflicting row or because the database is busy.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "UniqueConstraintViolation",
|
||||
instance = "/api/v1/users/me/playlists",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "ConcurrencyConflict",
|
||||
instance = "/api/v1/users/me/playlists",
|
||||
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/users/me/playlists",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlaylistNameCannotBeEmpty",
|
||||
"PlaylistNameMustBeMaximum255CharactersLong",
|
||||
"PlaylistDescriptionMustBeMaximum2000CharactersLong",
|
||||
"PlaylistTypeIsInvalid"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Playlists.Commands.DeletePlaylist;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Playlists;
|
||||
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.Playlists.DeletePlaylist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/playlists/{playlistId}</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class DeletePlaylistEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<DeletePlaylistCommand, Result<Deleted>> _deletePlaylistCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeletePlaylistEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="deletePlaylistCommandHandler">Injected service for handling delete playlist commands.</param>
|
||||
public DeletePlaylistEndpoint(ICommandHandler<DeletePlaylistCommand, Result<Deleted>> deletePlaylistCommandHandler)
|
||||
{
|
||||
_deletePlaylistCommandHandler = deletePlaylistCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.DELETE);
|
||||
Routes(ApiRoutes.Playlists.DELETE_PLAYLIST);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a playlist of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Take the unique identifier from the route.
|
||||
string? playlistId = HttpContext.Request.RouteValues["playlistId"]?.ToString();
|
||||
Result<Deleted> result = await _deletePlaylistCommandHandler.HandleAsync(new DeletePlaylistCommand(playlistId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Playlists.DeletePlaylist;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="DeletePlaylistEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeletePlaylistEndpointSummary : Summary<DeletePlaylistEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeletePlaylistEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public DeletePlaylistEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes a playlist of the current user.";
|
||||
Description = "Deletes the playlist identified by its Id when it belongs to the currently authenticated user, together with its ordered entries. The tracks it referenced are not deleted, because a playlist only references them by Id.";
|
||||
|
||||
Response(200, "The playlist 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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token has expired",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the playlist does not exist, or it does not belong to the current user.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "PlaylistNotFound",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because another request changed the playlist after it was read.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "ConcurrencyConflict",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b",
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{ "General.Validation", new[] { "PlaylistIdCannotBeEmpty" } }
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Playlists.Queries.GetPlaylist;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Playlists;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Playlists.GetPlaylist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/playlists/{playlistId}</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class GetPlaylistEndpoint : BaseEndpoint<GetPlaylistRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetPlaylistQuery, Result<PlaylistResponse>> _getPlaylistQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPlaylistEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getPlaylistQueryHandler">Injected service for handling get playlist queries.</param>
|
||||
public GetPlaylistEndpoint(IQueryHandler<GetPlaylistQuery, Result<PlaylistResponse>> getPlaylistQueryHandler)
|
||||
{
|
||||
_getPlaylistQueryHandler = getPlaylistQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.GET);
|
||||
Routes(ApiRoutes.Playlists.GET_PLAYLIST);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a window of the entries of a playlist of the current user.
|
||||
/// </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(GetPlaylistRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The playlist belongs to the authenticated user, so no intermediary may store any response of this route, including its problem
|
||||
// responses, and every response varies by the bearer token that authorized it.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Authorization";
|
||||
// Take the unique identifier from the route.
|
||||
string? playlistId = HttpContext.Request.RouteValues["playlistId"]?.ToString();
|
||||
int offset = request.Offset ?? 0;
|
||||
// The limit bounds one response window, not the size of the playlist. Clamping it keeps a crafted limit from turning the
|
||||
// windowed read into one unbounded response, while the handler still validates the value independently.
|
||||
int limit = Math.Clamp(request.Limit ?? PlaylistWindow.DEFAULT_ENTRY_WINDOW_SIZE, 1, PlaylistWindow.MAXIMUM_ENTRY_WINDOW_SIZE);
|
||||
Result<PlaylistResponse> result = await _getPlaylistQueryHandler
|
||||
.HandleAsync(new GetPlaylistQuery(playlistId, offset, limit), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Playlists.GetPlaylist;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetPlaylistEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPlaylistEndpointSummary : Summary<GetPlaylistEndpoint, GetPlaylistRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPlaylistEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetPlaylistEndpointSummary()
|
||||
{
|
||||
Summary = "Gets a playlist of the current user.";
|
||||
Description = "Gets the playlist identified by its Id when it belongs to the currently authenticated user, together with a window of its ordered entries. The offset and limit query parameters select the window, and entryCount reports the total number of entries. The limit is a response-window bound of at most 1000 entries and does not cap the size of the playlist. Each entry carries the media item Id and the media item kind it references, and a music track also carries the display details needed to play it: the library, album and artist Ids, the title, the album title, the artist name, the duration and the cover art. An entry whose media item was deleted is still returned, with empty display details.";
|
||||
|
||||
ExampleRequest = new GetPlaylistRequest(
|
||||
Offset: 0,
|
||||
Limit: 200
|
||||
);
|
||||
RequestParam(request => request.Offset, "The zero based position of the first entry to return. Optional; defaults to 0.");
|
||||
RequestParam(request => request.Limit, "The maximum number of entries to return, from 1 to 1000. Optional; defaults to 200.");
|
||||
|
||||
ResponseParam<PlaylistResponse>(response => response.Id, "The Id of the playlist.");
|
||||
ResponseParam<PlaylistResponse>(response => response.Name, "The name of the playlist.");
|
||||
ResponseParam<PlaylistResponse>(response => response.Description, "The description of the playlist, if applicable.");
|
||||
ResponseParam<PlaylistResponse>(response => response.Type, "The kind of media the playlist holds.");
|
||||
ResponseParam<PlaylistResponse>(response => response.Entries, "The ordered entries of the playlist.");
|
||||
ResponseParam<PlaylistResponse>(response => response.EntryCount, "The total number of entries the playlist holds, even when only a window of them is returned.");
|
||||
ResponseParam<PlaylistResponse>(response => response.CreatedOnUtc, "The date and time when the playlist was created.");
|
||||
ResponseParam<PlaylistResponse>(response => response.UpdatedOnUtc, "The date and time when the playlist was last updated, if applicable.");
|
||||
|
||||
Response(200, "The playlist and its ordered entries are returned.",
|
||||
example: new PlaylistResponse(
|
||||
Id: Guid.Parse("1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"),
|
||||
Name: "Evening listening",
|
||||
Description: "Quiet tracks for the end of the day.",
|
||||
Type: PlaylistType.Music,
|
||||
Entries:
|
||||
[
|
||||
new PlaylistEntryResponse(
|
||||
Id: Guid.Parse("2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d"),
|
||||
MediaItemId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"),
|
||||
MediaItemType: PlaylistMediaItemType.MusicTrack,
|
||||
Position: 0,
|
||||
LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"),
|
||||
CollectionId: Guid.Parse("e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f"),
|
||||
CreatorId: Guid.Parse("d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a"),
|
||||
MediaItemTitle: "The Show Must Go On",
|
||||
CollectionTitle: "Innuendo",
|
||||
CreatorName: "Queen",
|
||||
DurationInSeconds: 262,
|
||||
CoverPath: "/artwork/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
)
|
||||
],
|
||||
EntryCount: 1,
|
||||
CreatedOnUtc: new DateTime(2026, 10, 19, 18, 0, 0, DateTimeKind.Utc),
|
||||
UpdatedOnUtc: new DateTime(2026, 10, 19, 19, 30, 0, DateTimeKind.Utc)
|
||||
)
|
||||
);
|
||||
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token has expired",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the playlist does not exist, or it does not belong to the current user.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "PlaylistNotFound",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b",
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlaylistIdCannotBeEmpty",
|
||||
"PlaylistEntryWindowOffsetIsInvalid"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Playlists.Queries.GetPlaylists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Playlists;
|
||||
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.Playlists.GetPlaylists;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/playlists</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class GetPlaylistsEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetPlaylistsQuery, Result<PlaylistSummaryResponse[]>> _getPlaylistsQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPlaylistsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getPlaylistsQueryHandler">Injected service for handling get playlists queries.</param>
|
||||
public GetPlaylistsEndpoint(IQueryHandler<GetPlaylistsQuery, Result<PlaylistSummaryResponse[]>> getPlaylistsQueryHandler)
|
||||
{
|
||||
_getPlaylistsQueryHandler = getPlaylistsQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.GET);
|
||||
Routes(ApiRoutes.Playlists.GET_PLAYLISTS);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the playlists of the current user.
|
||||
/// </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)
|
||||
{
|
||||
// The playlists belong to the authenticated user, so no intermediary may store any response of this route, including its problem
|
||||
// responses, and every response varies by the bearer token that authorized it.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Authorization";
|
||||
Result<PlaylistSummaryResponse[]> result = await _getPlaylistsQueryHandler.HandleAsync(new GetPlaylistsQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Playlists.GetPlaylists;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetPlaylistsEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPlaylistsEndpointSummary : Summary<GetPlaylistsEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPlaylistsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetPlaylistsEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the playlists of the current user.";
|
||||
Description = "Gets the playlists that belong to the currently authenticated user, ordered by their most recent activity. Each playlist is returned without its entries, together with the number of entries it holds. A playlist of another user is never returned.";
|
||||
|
||||
ResponseParam<PlaylistSummaryResponse>(response => response.Id, "The Id of the playlist.");
|
||||
ResponseParam<PlaylistSummaryResponse>(response => response.Name, "The name of the playlist.");
|
||||
ResponseParam<PlaylistSummaryResponse>(response => response.Description, "The description of the playlist, if applicable.");
|
||||
ResponseParam<PlaylistSummaryResponse>(response => response.Type, "The kind of media the playlist holds.");
|
||||
ResponseParam<PlaylistSummaryResponse>(response => response.EntryCount, "The number of entries of the playlist.");
|
||||
ResponseParam<PlaylistSummaryResponse>(response => response.CreatedOnUtc, "The date and time when the playlist was created.");
|
||||
ResponseParam<PlaylistSummaryResponse>(response => response.UpdatedOnUtc, "The date and time when the playlist was last updated, if applicable.");
|
||||
|
||||
Response(200, "The playlists of the current user are returned.",
|
||||
example: new[]
|
||||
{
|
||||
new PlaylistSummaryResponse(
|
||||
Id: Guid.Parse("1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"),
|
||||
Name: "Evening listening",
|
||||
Description: "Quiet tracks for the end of the day.",
|
||||
Type: PlaylistType.Music,
|
||||
EntryCount: 12,
|
||||
CreatedOnUtc: new DateTime(2026, 10, 19, 18, 0, 0, DateTimeKind.Utc),
|
||||
UpdatedOnUtc: new DateTime(2026, 10, 19, 19, 30, 0, DateTimeKind.Utc)
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
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/users/me/playlists"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token has expired",
|
||||
instance = "/api/v1/users/me/playlists"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/users/me/playlists"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Playlists;
|
||||
using Lumina.Application.Core.Playlists.Commands.MovePlaylistEntry;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Playlists;
|
||||
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.Playlists.MovePlaylistEntry;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/playlists/{playlistId}/entries/{playlistEntryId}/move</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class MovePlaylistEntryEndpoint : BaseEndpoint<MovePlaylistEntryRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<MovePlaylistEntryCommand, Result<PlaylistEntryMovedResponse>> _movePlaylistEntryCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MovePlaylistEntryEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="movePlaylistEntryCommandHandler">Injected service for handling move playlist entry commands.</param>
|
||||
public MovePlaylistEntryEndpoint(ICommandHandler<MovePlaylistEntryCommand, Result<PlaylistEntryMovedResponse>> movePlaylistEntryCommandHandler)
|
||||
{
|
||||
_movePlaylistEntryCommandHandler = movePlaylistEntryCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.PUT);
|
||||
Routes(ApiRoutes.Playlists.MOVE_PLAYLIST_ENTRY);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves one entry of a playlist of the current user to a new position.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the new position of the entry.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(MovePlaylistEntryRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The playlist and the entry are identified by the route values, not by any id posted in the body.
|
||||
string? playlistId = HttpContext.Request.RouteValues["playlistId"]?.ToString();
|
||||
string? playlistEntryId = HttpContext.Request.RouteValues["playlistEntryId"]?.ToString();
|
||||
Result<PlaylistEntryMovedResponse> result = await _movePlaylistEntryCommandHandler.HandleAsync(request.ToCommand(playlistId, playlistEntryId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Playlists.MovePlaylistEntry;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="MovePlaylistEntryEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MovePlaylistEntryEndpointSummary : Summary<MovePlaylistEntryEndpoint, MovePlaylistEntryRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MovePlaylistEntryEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public MovePlaylistEntryEndpointSummary()
|
||||
{
|
||||
Summary = "Moves one entry of a playlist of the current user.";
|
||||
Description = "Moves the entry identified by its Id to the target zero based position in the ordered entries of the playlist identified by its Id, when the playlist belongs to the currently authenticated user. The request carries only the target position, so the move changes one sparse order key instead of rewriting the following entries. The moved entry and its new position are returned.";
|
||||
|
||||
ExampleRequest = new MovePlaylistEntryRequest(
|
||||
TargetPosition: 3
|
||||
);
|
||||
RequestParam(request => request.TargetPosition, "The new zero based position of the entry. Required, zero or greater.");
|
||||
|
||||
ResponseParam<PlaylistEntryMovedResponse>(response => response.PlaylistId, "The Id of the playlist whose entry was moved.");
|
||||
ResponseParam<PlaylistEntryMovedResponse>(response => response.EntryId, "The Id of the moved entry.");
|
||||
ResponseParam<PlaylistEntryMovedResponse>(response => response.Position, "The new zero based position of the entry.");
|
||||
ResponseParam<PlaylistEntryMovedResponse>(response => response.UpdatedOnUtc, "The date and time when the playlist was last updated.");
|
||||
|
||||
Response(200, "The moved entry and its new position are returned.",
|
||||
example: new PlaylistEntryMovedResponse(
|
||||
PlaylistId: Guid.Parse("1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"),
|
||||
EntryId: Guid.Parse("2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d"),
|
||||
Position: 3,
|
||||
UpdatedOnUtc: new DateTime(2026, 10, 20, 12, 0, 0, DateTimeKind.Utc)
|
||||
)
|
||||
);
|
||||
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d/move"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token has expired",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d/move"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d/move"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the playlist or the entry does not exist, or the playlist does not belong to the current user.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "PlaylistNotFound",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d/move",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "PlaylistEntryNotFound",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d/move",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because another request changed the playlist after it was read, or because the new position could not be stored.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "ConcurrencyConflict",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d/move",
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d/move",
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d/move",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlaylistIdCannotBeEmpty",
|
||||
"PlaylistEntryIdCannotBeEmpty",
|
||||
"PlaylistMoveTargetPositionIsInvalid"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Playlists.Commands.RemovePlaylistEntry;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Playlists;
|
||||
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.Playlists.RemovePlaylistEntry;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/playlists/{playlistId}/entries/{playlistEntryId}</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class RemovePlaylistEntryEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<RemovePlaylistEntryCommand, Result<PlaylistEntryRemovedResponse>> _removePlaylistEntryCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RemovePlaylistEntryEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="removePlaylistEntryCommandHandler">Injected service for handling remove playlist entry commands.</param>
|
||||
public RemovePlaylistEntryEndpoint(ICommandHandler<RemovePlaylistEntryCommand, Result<PlaylistEntryRemovedResponse>> removePlaylistEntryCommandHandler)
|
||||
{
|
||||
_removePlaylistEntryCommandHandler = removePlaylistEntryCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.DELETE);
|
||||
Routes(ApiRoutes.Playlists.REMOVE_PLAYLIST_ENTRY);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an entry from a playlist of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request object.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(FastEndpoints.EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Take the unique identifiers from the route.
|
||||
string? playlistId = HttpContext.Request.RouteValues["playlistId"]?.ToString();
|
||||
string? playlistEntryId = HttpContext.Request.RouteValues["playlistEntryId"]?.ToString();
|
||||
Result<PlaylistEntryRemovedResponse> result = await _removePlaylistEntryCommandHandler.HandleAsync(new RemovePlaylistEntryCommand(playlistId, playlistEntryId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Playlists.RemovePlaylistEntry;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="RemovePlaylistEntryEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RemovePlaylistEntryEndpointSummary : Summary<RemovePlaylistEntryEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RemovePlaylistEntryEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public RemovePlaylistEntryEndpointSummary()
|
||||
{
|
||||
Summary = "Removes an entry from a playlist of the current user.";
|
||||
Description = "Removes the entry identified by its Id from the playlist identified by its Id, when the playlist belongs to the currently authenticated user. The entries use sparse order keys, so only the removed row is written and no remaining entry needs to be repositioned. The referenced track is not deleted.";
|
||||
|
||||
ResponseParam<PlaylistEntryRemovedResponse>(response => response.PlaylistId, "The Id of the playlist the entry was removed from.");
|
||||
ResponseParam<PlaylistEntryRemovedResponse>(response => response.RemovedEntryId, "The Id of the removed entry.");
|
||||
ResponseParam<PlaylistEntryRemovedResponse>(response => response.RepositionedCount, "Always zero, because sparse order keys need no remaining entries to be repositioned.");
|
||||
ResponseParam<PlaylistEntryRemovedResponse>(response => response.UpdatedOnUtc, "The date and time when the playlist was last updated.");
|
||||
|
||||
Response(200, "The removed entry and the number of repositioned entries are returned.",
|
||||
example: new PlaylistEntryRemovedResponse(
|
||||
PlaylistId: Guid.Parse("1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"),
|
||||
RemovedEntryId: Guid.Parse("2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d"),
|
||||
RepositionedCount: 0,
|
||||
UpdatedOnUtc: new DateTime(2026, 10, 20, 12, 0, 0, DateTimeKind.Utc)
|
||||
)
|
||||
);
|
||||
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token has expired",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the playlist or the entry does not exist, or the playlist does not belong to the current user.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "PlaylistNotFound",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "PlaylistEntryNotFound",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because another request changed the playlist after it was read.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "ConcurrencyConflict",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d",
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b/entries/2a3b4c5d-6e7f-4a8b-9c0d-1e2f3a4b5c6d",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlaylistIdCannotBeEmpty",
|
||||
"PlaylistEntryIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Playlists;
|
||||
using Lumina.Application.Core.Playlists.Commands.UpdatePlaylist;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Playlists;
|
||||
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.Playlists.UpdatePlaylist;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/playlists/{playlistId}</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class UpdatePlaylistEndpoint : BaseEndpoint<UpdatePlaylistRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<UpdatePlaylistCommand, Result<PlaylistDetailsResponse>> _updatePlaylistCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdatePlaylistEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="updatePlaylistCommandHandler">Injected service for handling update playlist commands.</param>
|
||||
public UpdatePlaylistEndpoint(ICommandHandler<UpdatePlaylistCommand, Result<PlaylistDetailsResponse>> updatePlaylistCommandHandler)
|
||||
{
|
||||
_updatePlaylistCommandHandler = updatePlaylistCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.PUT);
|
||||
Routes(ApiRoutes.Playlists.UPDATE_PLAYLIST);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the details of a playlist of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the new details of the playlist.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(UpdatePlaylistRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The playlist is identified by the route value, not by any id posted in the body, so that a mismatched id can never redirect the
|
||||
// update to another playlist.
|
||||
string? playlistId = HttpContext.Request.RouteValues["playlistId"]?.ToString();
|
||||
Result<PlaylistDetailsResponse> result = await _updatePlaylistCommandHandler.HandleAsync(request.ToCommand(playlistId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Playlists.UpdatePlaylist;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="UpdatePlaylistEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdatePlaylistEndpointSummary : Summary<UpdatePlaylistEndpoint, UpdatePlaylistRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdatePlaylistEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public UpdatePlaylistEndpointSummary()
|
||||
{
|
||||
Summary = "Updates the details of a playlist of the current user.";
|
||||
Description = "Updates the name and the description of the playlist identified by its Id when it belongs to the currently authenticated user, leaving its ordered entries untouched. The playlist is identified by the route value, not by any id posted in the body.";
|
||||
|
||||
ExampleRequest = new UpdatePlaylistRequest(
|
||||
Name: "Evening listening",
|
||||
Description: "Quiet tracks for the end of the day."
|
||||
);
|
||||
RequestParam(request => request.Name, "The name of the playlist. Required, maximum 255 characters.");
|
||||
RequestParam(request => request.Description, "The description of the playlist. Optional, maximum 2000 characters.");
|
||||
|
||||
ResponseParam<PlaylistDetailsResponse>(response => response.Id, "The Id of the playlist.");
|
||||
ResponseParam<PlaylistDetailsResponse>(response => response.Name, "The name of the playlist.");
|
||||
ResponseParam<PlaylistDetailsResponse>(response => response.Description, "The description of the playlist, if applicable.");
|
||||
ResponseParam<PlaylistDetailsResponse>(response => response.Type, "The kind of media the playlist holds.");
|
||||
ResponseParam<PlaylistDetailsResponse>(response => response.UpdatedOnUtc, "The date and time when the playlist was last updated, if applicable.");
|
||||
|
||||
Response(200, "The updated playlist scalars are returned.",
|
||||
example: new PlaylistDetailsResponse(
|
||||
Id: Guid.Parse("1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"),
|
||||
Name: "Evening listening",
|
||||
Description: "Quiet tracks for the end of the day.",
|
||||
Type: PlaylistType.Music,
|
||||
UpdatedOnUtc: new DateTime(2026, 10, 20, 12, 0, 0, DateTimeKind.Utc)
|
||||
)
|
||||
);
|
||||
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token has expired",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the playlist does not exist, or it does not belong to the current user.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "PlaylistNotFound",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because another request changed the playlist after it was read.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "ConcurrencyConflict",
|
||||
instance = "/api/v1/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b",
|
||||
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/users/me/playlists/1f2e3d4c-5b6a-4978-8a9b-0c1d2e3f4a5b",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlaylistIdCannotBeEmpty",
|
||||
"PlaylistNameCannotBeEmpty",
|
||||
"PlaylistNameMustBeMaximum255CharactersLong",
|
||||
"PlaylistDescriptionMustBeMaximum2000CharactersLong"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user