mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 19:21:10 +00:00
Adds favorites and aligns playlist and favorite pagination
This commit is contained in:
1 parent
2e9f7d8496
commit
525ac1348d
193 files changed
+10944
-643
No files matched your search
@@ -0,0 +1,18 @@
|
||||
namespace Lumina.Presentation.Api.Common.Routes.Favorites;
|
||||
|
||||
/// <summary>
|
||||
/// Class for the collection of the favorite routes of the API.
|
||||
/// </summary>
|
||||
public static partial class ApiRoutes
|
||||
{
|
||||
/// <summary>
|
||||
/// Routes for the favorites of the current user.
|
||||
/// </summary>
|
||||
public static class Favorites
|
||||
{
|
||||
public const string GET_FAVORITES = "/users/me/favorites";
|
||||
public const string ADD_FAVORITE = "/users/me/favorites";
|
||||
public const string REMOVE_FAVORITE = "/users/me/favorites/{mediaKind}/{mediaItemId}";
|
||||
public const string GET_FAVORITE_STATUS = "/users/me/favorites/status";
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Favorites;
|
||||
using Lumina.Application.Core.Favorites.Commands.AddFavorite;
|
||||
using Lumina.Contracts.Requests.Favorites;
|
||||
using Lumina.Contracts.Responses.Favorites;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Favorites;
|
||||
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.Favorites.AddFavorite;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/favorites</c> route, for adding a favorite.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class AddFavoriteEndpoint : BaseEndpoint<AddFavoriteRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<AddFavoriteCommand, Result<FavoriteResponse>> _addFavoriteCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddFavoriteEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="addFavoriteCommandHandler">Injected service for handling add favorite commands.</param>
|
||||
public AddFavoriteEndpoint(ICommandHandler<AddFavoriteCommand, Result<FavoriteResponse>> addFavoriteCommandHandler)
|
||||
{
|
||||
_addFavoriteCommandHandler = addFavoriteCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.Favorites.ADD_FAVORITE);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Marks a media item as a favorite of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the kind and the Id of the media item to favorite.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(AddFavoriteRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The favorites 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<FavoriteResponse> result = await _addFavoriteCommandHandler.HandleAsync(request.ToCommand(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Favorites;
|
||||
using Lumina.Contracts.Responses.Favorites;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Favorites.AddFavorite;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="AddFavoriteEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddFavoriteEndpointSummary : Summary<AddFavoriteEndpoint, AddFavoriteRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddFavoriteEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public AddFavoriteEndpointSummary()
|
||||
{
|
||||
Summary = "Marks a media item as a favorite of the current user.";
|
||||
Description = "Marks the media item identified by its kind and its Id as a favorite of the currently authenticated user. The supported kinds are MusicArtist, MusicAlbum, MusicTrack and Book. The kinds Video and Photo exist but are planned: they are rejected with a validation error until video and photo libraries are catalogued. The media item must exist and belong to a media library the current user can access; an item that does not exist and an item of a library the user cannot access are reported with the same not found error, so the response cannot be used to find out what another user holds. The operation is idempotent: adding an item that is already a favorite returns the existing favorite and changes nothing.";
|
||||
|
||||
ExampleRequest = new AddFavoriteRequest(
|
||||
MediaKind: FavoriteMediaKind.MusicTrack,
|
||||
MediaItemId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f")
|
||||
);
|
||||
RequestParam(request => request.MediaKind, "The kind of the media item to favorite. Required. One of MusicArtist, MusicAlbum, MusicTrack or Book.");
|
||||
RequestParam(request => request.MediaItemId, "The Id of the media item to favorite. Required.");
|
||||
|
||||
ResponseParam<FavoriteResponse>(response => response.Id, "The Id of the favorite.");
|
||||
ResponseParam<FavoriteResponse>(response => response.MediaKind, "The kind of the favorited media item.");
|
||||
ResponseParam<FavoriteResponse>(response => response.MediaItemId, "The Id of the favorited media item.");
|
||||
ResponseParam<FavoriteResponse>(response => response.FavoritedOnUtc, "The date and time when the media item was favorited.");
|
||||
|
||||
Response(200, "The media item is a favorite of the current user, and the favorite is returned.",
|
||||
example: new FavoriteResponse(
|
||||
Id: Guid.Parse("4d5e6f70-8192-4a3b-9c4d-5e6f708192a3"),
|
||||
MediaKind: FavoriteMediaKind.MusicTrack,
|
||||
MediaItemId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"),
|
||||
FavoritedOnUtc: new DateTime(2026, 10, 21, 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/favorites"
|
||||
},
|
||||
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/favorites"
|
||||
},
|
||||
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/favorites"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the authenticated request does not carry the identity of a 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/favorites",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the media item does not exist, or it belongs to a media library the current user cannot access. The error names the kind of the media item.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "ArtistNotFound",
|
||||
instance = "/api/v1/users/me/favorites",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "AlbumNotFound",
|
||||
instance = "/api/v1/users/me/favorites",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-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/favorites",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "BookNotFound",
|
||||
instance = "/api/v1/users/me/favorites",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because the favorite could not be stored, because the database is busy or locked. Repeating the request is safe.", "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/favorites",
|
||||
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/favorites",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"FavoriteMediaKindIsInvalid",
|
||||
"FavoriteMediaItemIdCannotBeEmpty",
|
||||
"FavoriteMediaKindIsNotSupported"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Favorites;
|
||||
using Lumina.Application.Core.Favorites.Queries.GetFavoriteStatus;
|
||||
using Lumina.Contracts.Requests.Favorites;
|
||||
using Lumina.Contracts.Responses.Favorites;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Favorites;
|
||||
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.Favorites.GetFavoriteStatus;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/favorites/status</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class GetFavoriteStatusEndpoint : BaseEndpoint<GetFavoriteStatusRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetFavoriteStatusQuery, Result<FavoriteStatusResponse>> _getFavoriteStatusQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetFavoriteStatusEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getFavoriteStatusQueryHandler">Injected service for handling get favorite status queries.</param>
|
||||
public GetFavoriteStatusEndpoint(IQueryHandler<GetFavoriteStatusQuery, Result<FavoriteStatusResponse>> getFavoriteStatusQueryHandler)
|
||||
{
|
||||
_getFavoriteStatusQueryHandler = getFavoriteStatusQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.GET);
|
||||
Routes(ApiRoutes.Favorites.GET_FAVORITE_STATUS);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds out which media items of one kind are favorites of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the media kind and the Ids of the media items to check.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetFavoriteStatusRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The favorites 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<FavoriteStatusResponse> result = await _getFavoriteStatusQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Favorites;
|
||||
using Lumina.Contracts.Responses.Favorites;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Favorites.GetFavoriteStatus;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetFavoriteStatusEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetFavoriteStatusEndpointSummary : Summary<GetFavoriteStatusEndpoint, GetFavoriteStatusRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetFavoriteStatusEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetFavoriteStatusEndpointSummary()
|
||||
{
|
||||
Summary = "Finds out which media items are favorites of the current user.";
|
||||
Description = "Checks up to 100 media items of one kind and returns the Ids, among the checked ones, that are favorites of the currently authenticated user. The media item Ids are sent by repeating the mediaItemIds query parameter once per Id, and the limit of 100 keeps the request line within the size limit of the server. Only the favorites of the current user are consulted, so the answer reveals nothing about the media items of other users. An Id that does not exist, or that is not a favorite, is simply absent from the answer.";
|
||||
|
||||
ExampleRequest = new GetFavoriteStatusRequest(
|
||||
MediaKind: FavoriteMediaKind.MusicTrack,
|
||||
MediaItemIds:
|
||||
[
|
||||
Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"),
|
||||
Guid.Parse("a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d")
|
||||
]
|
||||
);
|
||||
RequestParam(request => request.MediaKind, "The kind of the media items to check. Required. One of MusicArtist, MusicAlbum, MusicTrack or Book.");
|
||||
RequestParam(request => request.MediaItemIds, "The Ids of the media items to check, from 1 to 100, sent as a repeated query parameter. Required.");
|
||||
|
||||
ResponseParam<FavoriteStatusResponse>(response => response.FavoritedMediaItemIds, "The Ids, among the checked ones, of the media items that are favorites of the current user.");
|
||||
|
||||
Response(200, "The favorite status of the checked media items is returned.",
|
||||
example: new FavoriteStatusResponse(
|
||||
FavoritedMediaItemIds: [Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f")]
|
||||
)
|
||||
);
|
||||
|
||||
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/favorites/status"
|
||||
},
|
||||
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/favorites/status"
|
||||
},
|
||||
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/favorites/status"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the authenticated request does not carry the identity of a 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/favorites/status",
|
||||
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/favorites/status",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"FavoriteMediaKindIsInvalid",
|
||||
"FavoriteMediaItemIdsCannotBeEmpty",
|
||||
"FavoriteMediaItemIdsExceedMaximumCount",
|
||||
"FavoriteMediaItemIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Favorites;
|
||||
using Lumina.Application.Core.Favorites.Queries.GetFavorites;
|
||||
using Lumina.Contracts.Requests.Favorites;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.Favorites;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Favorites;
|
||||
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.Favorites.GetFavorites;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/favorites</c> route, for getting the favorites.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class GetFavoritesEndpoint : BaseEndpoint<GetFavoritesRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetFavoritesQuery, Result<PaginatedResponse<FavoriteItemResponse>>> _getFavoritesQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetFavoritesEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getFavoritesQueryHandler">Injected service for handling get favorites queries.</param>
|
||||
public GetFavoritesEndpoint(IQueryHandler<GetFavoritesQuery, Result<PaginatedResponse<FavoriteItemResponse>>> getFavoritesQueryHandler)
|
||||
{
|
||||
_getFavoritesQueryHandler = getFavoritesQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.GET);
|
||||
Routes(ApiRoutes.Favorites.GET_FAVORITES);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a page of the favorites of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the optional media kind filter and the page bounds.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetFavoritesRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The favorites 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<PaginatedResponse<FavoriteItemResponse>> result = await _getFavoritesQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Favorites;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.Favorites;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Favorites;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Favorites.GetFavorites;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetFavoritesEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetFavoritesEndpointSummary : Summary<GetFavoritesEndpoint, GetFavoritesRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetFavoritesEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetFavoritesEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the favorites of the current user.";
|
||||
Description = "Gets the favorites of the currently authenticated user, from the most recently favorited, across every kind of media item or restricted to one kind. The currentPage and perPage query parameters select the page, and count reports the number of favorites that match the filter. When neither parameter is provided, every matching favorite is returned in a single page. Each favorite carries the display details of the media item it references: the title, the collection, the creator and the cover art. A favorite whose media item was deleted, or whose media library the user can no longer access, is still returned, with isAvailable set to false and empty display details, so the user can see it and remove it. A favorite of another user is never returned.";
|
||||
|
||||
ExampleRequest = new GetFavoritesRequest(
|
||||
MediaKind: FavoriteMediaKind.MusicTrack,
|
||||
CurrentPage: 1,
|
||||
PerPage: 200
|
||||
);
|
||||
RequestParam(request => request.MediaKind, "The kind of media item to restrict the favorites to. Optional; every kind is returned when omitted.");
|
||||
RequestParam(request => request.CurrentPage, "The one based page of favorites to return. Optional; defaults to 1 when a page size is provided.");
|
||||
RequestParam(request => request.PerPage, "The number of favorites per page. Optional; defaults to 200 when a page is provided. When both pagination parameters are omitted, every matching favorite is returned.");
|
||||
|
||||
ResponseParam<PaginatedResponse<FavoriteItemResponse>>(response => response.Data, "The favorites of the requested page, from the most recently favorited.");
|
||||
ResponseParam<PaginatedResponse<FavoriteItemResponse>>(response => response.CurrentPage, "The current page number.");
|
||||
ResponseParam<PaginatedResponse<FavoriteItemResponse>>(response => response.PerPage, "The number of favorites retrieved per page.");
|
||||
ResponseParam<PaginatedResponse<FavoriteItemResponse>>(response => response.Count, "The total number of favorites that match the filter.");
|
||||
ResponseParam<PaginatedResponse<FavoriteItemResponse>>(response => response.NumberOfPages, "The total number of pages.");
|
||||
|
||||
ResponseParam<FavoriteItemResponse>(response => response.MediaKind, "The kind of the favorited media item.");
|
||||
ResponseParam<FavoriteItemResponse>(response => response.MediaItemId, "The Id of the favorited media item.");
|
||||
ResponseParam<FavoriteItemResponse>(response => response.IsAvailable, "Whether the media item still exists and its library is accessible to the current user.");
|
||||
ResponseParam<FavoriteItemResponse>(response => response.LibraryId, "The Id of the media library that contains the media item.");
|
||||
ResponseParam<FavoriteItemResponse>(response => response.Title, "The title of the media item.");
|
||||
ResponseParam<FavoriteItemResponse>(response => response.CollectionId, "The Id of the collection that contains the media item, or the empty Guid when there is none.");
|
||||
ResponseParam<FavoriteItemResponse>(response => response.CollectionTitle, "The title of the collection that contains the media item, or an empty string when there is none.");
|
||||
ResponseParam<FavoriteItemResponse>(response => response.CreatorId, "The Id of the creator of the media item, or the empty Guid when there is none.");
|
||||
ResponseParam<FavoriteItemResponse>(response => response.CreatorName, "The name of the creator of the media item, or an empty string when there is none.");
|
||||
ResponseParam<FavoriteItemResponse>(response => response.CoverPath, "The path of the cover art of the media item, if available.");
|
||||
|
||||
Response(200, "The favorites of the current user are returned.",
|
||||
example: new PaginatedResponse<FavoriteItemResponse>
|
||||
{
|
||||
Data =
|
||||
[
|
||||
new FavoriteItemResponse(
|
||||
MediaKind: FavoriteMediaKind.MusicTrack,
|
||||
MediaItemId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"),
|
||||
IsAvailable: true,
|
||||
LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"),
|
||||
Title: "The Show Must Go On",
|
||||
CollectionId: Guid.Parse("e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f"),
|
||||
CollectionTitle: "Innuendo",
|
||||
CreatorId: Guid.Parse("d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a"),
|
||||
CreatorName: "Queen",
|
||||
CoverPath: "/artwork/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg"
|
||||
),
|
||||
new FavoriteItemResponse(
|
||||
MediaKind: FavoriteMediaKind.Book,
|
||||
MediaItemId: Guid.Parse("0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d"),
|
||||
IsAvailable: true,
|
||||
LibraryId: Guid.Parse("6c7d8e9f-0a1b-4c2d-9e3f-4a5b6c7d8e9f"),
|
||||
Title: "The Fellowship of the Ring",
|
||||
CollectionId: Guid.Empty,
|
||||
CollectionTitle: string.Empty,
|
||||
CreatorId: Guid.Parse("8e9f0a1b-2c3d-4e4f-9a5b-6c7d8e9f0a1b"),
|
||||
CreatorName: "J. R. R. Tolkien",
|
||||
CoverPath: "/artwork/books/0a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d/cover.jpg"
|
||||
),
|
||||
new FavoriteItemResponse(
|
||||
MediaKind: FavoriteMediaKind.MusicAlbum,
|
||||
MediaItemId: Guid.Parse("9f0a1b2c-3d4e-4f5a-8b6c-7d8e9f0a1b2c"),
|
||||
IsAvailable: false,
|
||||
LibraryId: Guid.Empty,
|
||||
Title: string.Empty,
|
||||
CollectionId: Guid.Empty,
|
||||
CollectionTitle: string.Empty,
|
||||
CreatorId: Guid.Empty,
|
||||
CreatorName: string.Empty,
|
||||
CoverPath: null
|
||||
)
|
||||
],
|
||||
CurrentPage = 1,
|
||||
PerPage = 200,
|
||||
Count = 3,
|
||||
NumberOfPages = 1
|
||||
}
|
||||
);
|
||||
|
||||
Response(401, "Authentication required.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "Authentication failed",
|
||||
instance = "/api/v1/users/me/favorites"
|
||||
},
|
||||
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/favorites"
|
||||
},
|
||||
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/favorites"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the authenticated request does not carry the identity of a 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/favorites",
|
||||
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/favorites",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"FavoriteMediaKindIsInvalid"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Favorites.Commands.RemoveFavorite;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Favorites;
|
||||
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.Favorites.RemoveFavorite;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/favorites/{mediaKind}/{mediaItemId}</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class RemoveFavoriteEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<RemoveFavoriteCommand, Result<Deleted>> _removeFavoriteCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RemoveFavoriteEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="removeFavoriteCommandHandler">Injected service for handling remove favorite commands.</param>
|
||||
public RemoveFavoriteEndpoint(ICommandHandler<RemoveFavoriteCommand, Result<Deleted>> removeFavoriteCommandHandler)
|
||||
{
|
||||
_removeFavoriteCommandHandler = removeFavoriteCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.DELETE);
|
||||
Routes(ApiRoutes.Favorites.REMOVE_FAVORITE);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a media item from the favorites 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 favorites 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";
|
||||
// Take the kind and the unique identifier of the media item from the route, as raw strings so the validator reports a clean error for an unparseable value.
|
||||
string? mediaKind = HttpContext.Request.RouteValues["mediaKind"]?.ToString();
|
||||
string? mediaItemId = HttpContext.Request.RouteValues["mediaItemId"]?.ToString();
|
||||
Result<Deleted> result = await _removeFavoriteCommandHandler.HandleAsync(new RemoveFavoriteCommand(mediaKind, mediaItemId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Favorites.RemoveFavorite;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="RemoveFavoriteEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RemoveFavoriteEndpointSummary : Summary<RemoveFavoriteEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RemoveFavoriteEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public RemoveFavoriteEndpointSummary()
|
||||
{
|
||||
Summary = "Removes a media item from the favorites of the current user.";
|
||||
Description = "Removes the media item identified by its kind and its Id from the favorites of the currently authenticated user. The kind is the name of a kind of media item, such as MusicTrack, and is matched without regard to case. The media item itself is never deleted. The favorite is always the one of the authenticated user, so this route can never remove another user's favorite. The media library of the item is deliberately not checked, so a user can always remove their own favorite whose item was deleted or is no longer accessible. Removing is idempotent: an item that is not a favorite of the user already has the desired state, so the request succeeds without changing anything and without raising an event.";
|
||||
|
||||
Params["mediaKind"] = "The name of the kind of media item, matched case insensitively: MusicArtist, MusicAlbum, MusicTrack or Book.";
|
||||
Params["mediaItemId"] = "The Id of the media item to remove from the favorites.";
|
||||
|
||||
Response(200, "The media item was successfully removed from the favorites.");
|
||||
|
||||
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/favorites/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"
|
||||
},
|
||||
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/favorites/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"
|
||||
},
|
||||
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/favorites/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the authenticated request does not carry the identity of a 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/favorites/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because the database is busy or locked, or the favorite was changed by another request in a way that could not be reconciled. Removing a favorite that another request removed first succeeds.", "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/favorites/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f",
|
||||
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/favorites/Unknown/not-a-guid",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"FavoriteMediaKindIsInvalid",
|
||||
"FavoriteMediaItemIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+10
-4
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
|
||||
using System;
|
||||
@@ -37,8 +38,7 @@ public class CreatePlaylistEndpointSummary : Summary<CreatePlaylistEndpoint, Cre
|
||||
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.Entries, "The page of ordered entries of the playlist, with its pagination metadata.");
|
||||
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.");
|
||||
|
||||
@@ -48,8 +48,14 @@ public class CreatePlaylistEndpointSummary : Summary<CreatePlaylistEndpoint, Cre
|
||||
Name: "Evening listening",
|
||||
Description: "Quiet tracks for the end of the day.",
|
||||
Type: PlaylistType.Music,
|
||||
Entries: [],
|
||||
EntryCount: 0,
|
||||
Entries: new PaginatedResponse<PlaylistEntryResponse>
|
||||
{
|
||||
Data = [],
|
||||
CurrentPage = 1,
|
||||
PerPage = 200,
|
||||
Count = 0,
|
||||
NumberOfPages = 0
|
||||
},
|
||||
CreatedOnUtc: new DateTime(2026, 10, 21, 12, 0, 0, DateTimeKind.Utc),
|
||||
UpdatedOnUtc: null
|
||||
)
|
||||
|
||||
+3
-8
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.Playlists;
|
||||
using Lumina.Application.Core.Playlists.Queries.GetPlaylist;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
@@ -7,7 +8,6 @@ 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
|
||||
@@ -45,7 +45,7 @@ public class GetPlaylistEndpoint : BaseEndpoint<GetPlaylistRequest, IResult>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a window of the entries of a playlist of the current user.
|
||||
/// Gets a page 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>
|
||||
@@ -57,12 +57,7 @@ public class GetPlaylistEndpoint : BaseEndpoint<GetPlaylistRequest, IResult>
|
||||
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);
|
||||
Result<PlaylistResponse> result = await _getPlaylistQueryHandler.HandleAsync(request.ToQuery(playlistId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+32
-27
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.Playlists;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.Playlists;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playlists;
|
||||
using System;
|
||||
@@ -22,21 +23,20 @@ public class GetPlaylistEndpointSummary : Summary<GetPlaylistEndpoint, GetPlayli
|
||||
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.";
|
||||
Description = "Gets the playlist identified by its Id when it belongs to the currently authenticated user, together with a page of its ordered entries. The currentPage and perPage query parameters select the page, and entries.count reports the total number of entries. When neither parameter is provided, every entry is returned in a single page. 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
|
||||
CurrentPage: 1,
|
||||
PerPage: 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.");
|
||||
RequestParam(request => request.CurrentPage, "The one based page of entries to return. Optional; defaults to 1 when a page size is provided.");
|
||||
RequestParam(request => request.PerPage, "The number of entries per page. Optional; defaults to 200 when a page is provided. When both pagination parameters are omitted, every entry is returned.");
|
||||
|
||||
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.Entries, "The page of ordered entries of the playlist, with its pagination metadata.");
|
||||
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.");
|
||||
|
||||
@@ -46,24 +46,30 @@ public class GetPlaylistEndpointSummary : Summary<GetPlaylistEndpoint, GetPlayli
|
||||
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,
|
||||
Entries: new PaginatedResponse<PlaylistEntryResponse>
|
||||
{
|
||||
Data =
|
||||
[
|
||||
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"
|
||||
)
|
||||
],
|
||||
CurrentPage = 1,
|
||||
PerPage = 200,
|
||||
Count = 1,
|
||||
NumberOfPages = 1
|
||||
},
|
||||
CreatedOnUtc: new DateTime(2026, 10, 19, 18, 0, 0, DateTimeKind.Utc),
|
||||
UpdatedOnUtc: new DateTime(2026, 10, 19, 19, 30, 0, DateTimeKind.Utc)
|
||||
)
|
||||
@@ -124,8 +130,7 @@ public class GetPlaylistEndpointSummary : Summary<GetPlaylistEndpoint, GetPlayli
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlaylistIdCannotBeEmpty",
|
||||
"PlaylistEntryWindowOffsetIsInvalid"
|
||||
"PlaylistIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user