mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11:10 +00:00
Adds the music play statistics endpoints and moves the Web statistics page under the library
This commit is contained in:
1 parent
dfd979ec1e
commit
a61fbf407c
69 files changed
+3407
-7
No files matched your search
+17
@@ -0,0 +1,17 @@
|
||||
namespace Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Class for the collection of the music play statistics routes of the API.
|
||||
/// </summary>
|
||||
public static partial class ApiRoutes
|
||||
{
|
||||
/// <summary>
|
||||
/// Routes for the music play statistics of the current user.
|
||||
/// </summary>
|
||||
public static class PlayStatistics
|
||||
{
|
||||
public const string GET_RECENTLY_PLAYED = "/users/me/music-play-history/recently-played";
|
||||
public const string GET_MOST_PLAYED = "/users/me/music-play-history/most-played";
|
||||
public const string GET_MUSIC_PLAY_STATISTICS = "/users/me/music-play-history/statistics";
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetMostPlayed;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetMostPlayed;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/music-play-history/most-played</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class GetMostPlayedEndpoint : BaseEndpoint<GetMostPlayedRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetMostPlayedQuery, Result<PaginatedResponse<PlayedTrackResponse>>> _getMostPlayedQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMostPlayedEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getMostPlayedQueryHandler">Injected service for handling get most played queries.</param>
|
||||
public GetMostPlayedEndpoint(IQueryHandler<GetMostPlayedQuery, Result<PaginatedResponse<PlayedTrackResponse>>> getMostPlayedQueryHandler)
|
||||
{
|
||||
_getMostPlayedQueryHandler = getMostPlayedQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.PlayStatistics.GET_MOST_PLAYED);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the most played tracks of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the optional page bounds.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetMostPlayedRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The statistics 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<PlayedTrackResponse>> result = await _getMostPlayedQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetMostPlayed;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetMostPlayedEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetMostPlayedEndpointSummary : Summary<GetMostPlayedEndpoint, GetMostPlayedRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMostPlayedEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetMostPlayedEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the most played tracks of the current user.";
|
||||
Description = "Gets the tracks the current user played the most, from the most played. Only the plays that count as plays are included: a play counts when it completed or when the listened duration reached 30 seconds. Each track is returned once, with its counted plays, its completed plays, the duration the user listened to it and its last activity time. A track deleted from its library keeps its row, without display data. The response is private to the authenticated user.";
|
||||
|
||||
ExampleRequest = new GetMostPlayedRequest(CurrentPage: 1, PerPage: 50);
|
||||
RequestParam(request => request.CurrentPage, "The one based page of tracks to return. Optional. Defaults to 1.");
|
||||
RequestParam(request => request.PerPage, "The number of tracks per page. Optional. Defaults to 50. When both pagination parameters are omitted, every matching track is returned.");
|
||||
|
||||
ResponseParam<PaginatedResponse<PlayedTrackResponse>>(response => response.Data, "The most played tracks of the requested page, ordered by counted plays, listened duration, last activity, and track Id.");
|
||||
ResponseParam<PaginatedResponse<PlayedTrackResponse>>(response => response.CurrentPage, "The current page number.");
|
||||
ResponseParam<PaginatedResponse<PlayedTrackResponse>>(response => response.PerPage, "The number of tracks retrieved per page.");
|
||||
ResponseParam<PaginatedResponse<PlayedTrackResponse>>(response => response.Count, "The total number of tracks that match the filters.");
|
||||
ResponseParam<PaginatedResponse<PlayedTrackResponse>>(response => response.NumberOfPages, "The total number of pages.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.TrackId, "The Id of the track.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.LibraryId, "The Id of the media library that contains the track.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.AlbumId, "The Id of the album that contains the track.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.ArtistId, "The Id of the artist that produced the track.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.Title, "The title of the track, if it still exists and the user can access its library.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.AlbumTitle, "The title of the album that contains the track, if available.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.ArtistName, "The name of the artist that produced the track, if available.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.CoverPath, "The path of the cover art of the album, if available.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.LastPlayedOnUtc, "The date and time of the last recorded activity of the track's most recent play.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.PlayCount, "The number of plays of the track that count as plays.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.CompletedPlayCount, "The number of plays of the track that completed.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.ListenedDurationInSeconds, "The duration the user listened to the track, over all of its counted plays, in seconds.");
|
||||
|
||||
Response(200, "The requested page of most played tracks is returned.",
|
||||
example: new PaginatedResponse<PlayedTrackResponse>
|
||||
{
|
||||
Data =
|
||||
[
|
||||
new PlayedTrackResponse(
|
||||
TrackId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"),
|
||||
LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"),
|
||||
AlbumId: Guid.Parse("e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f"),
|
||||
ArtistId: Guid.Parse("d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a"),
|
||||
Title: "Time",
|
||||
AlbumTitle: "The Dark Side of the Moon",
|
||||
ArtistName: "Pink Floyd",
|
||||
CoverPath: "covers/dark-side-of-the-moon.jpg",
|
||||
LastPlayedOnUtc: new DateTime(2026, 10, 20, 18, 30, 0, DateTimeKind.Utc),
|
||||
PlayCount: 12,
|
||||
CompletedPlayCount: 9,
|
||||
ListenedDurationInSeconds: 4230.5)
|
||||
],
|
||||
CurrentPage = 1,
|
||||
PerPage = 50,
|
||||
Count = 1,
|
||||
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/music-play-history/most-played"
|
||||
},
|
||||
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/music-play-history/most-played"
|
||||
},
|
||||
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/music-play-history/most-played"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
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/music-play-history/most-played",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetMusicPlayStatistics;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetMusicPlayStatistics;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/music-play-history/statistics</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class GetMusicPlayStatisticsEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetMusicPlayStatisticsQuery, Result<MusicPlayStatisticsResponse>> _getMusicPlayStatisticsQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMusicPlayStatisticsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getMusicPlayStatisticsQueryHandler">Injected service for handling get music play statistics queries.</param>
|
||||
public GetMusicPlayStatisticsEndpoint(IQueryHandler<GetMusicPlayStatisticsQuery, Result<MusicPlayStatisticsResponse>> getMusicPlayStatisticsQueryHandler)
|
||||
{
|
||||
_getMusicPlayStatisticsQueryHandler = getMusicPlayStatisticsQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.PlayStatistics.GET_MUSIC_PLAY_STATISTICS);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the listening statistics 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(EmptyRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The statistics 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<MusicPlayStatisticsResponse> result = await _getMusicPlayStatisticsQueryHandler.HandleAsync(new GetMusicPlayStatisticsQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetMusicPlayStatistics;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetMusicPlayStatisticsEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetMusicPlayStatisticsEndpointSummary : Summary<GetMusicPlayStatisticsEndpoint>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMusicPlayStatisticsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetMusicPlayStatisticsEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the listening statistics of the current user.";
|
||||
Description = "Gets the total listening time, the number of plays that count as plays, the number of completed plays, the number of stopped plays that count and the completion rate of the current user. A play counts when it completed or when the listened duration reached 30 seconds, and the total listening time includes the listened duration of every recorded play. A play that is still in progress counts once it reaches the threshold, so the counted total can exceed the completed and stopped plays together. The statistics are aggregated over the plays of the authenticated user, so the response is private to that user.";
|
||||
|
||||
ResponseParam<MusicPlayStatisticsResponse>(response => response.TotalListeningDurationInSeconds, "The total duration the user listened to, over every recorded play, in seconds.");
|
||||
ResponseParam<MusicPlayStatisticsResponse>(response => response.TotalPlayCount, "The number of recorded plays that count as plays. It includes an in-progress play that has already reached the threshold, so it need not equal the completed and stopped plays together.");
|
||||
ResponseParam<MusicPlayStatisticsResponse>(response => response.CompletedPlayCount, "The number of recorded plays that completed.");
|
||||
ResponseParam<MusicPlayStatisticsResponse>(response => response.StoppedPlayCount, "The number of recorded plays that stopped before the track completed and count as plays.");
|
||||
ResponseParam<MusicPlayStatisticsResponse>(response => response.CompletionRate, "The fraction of the counted plays that completed, between 0 and 1, or 0 when there is no counted play.");
|
||||
|
||||
Response(200, "The listening statistics of the current user are returned.",
|
||||
example: new MusicPlayStatisticsResponse(
|
||||
TotalListeningDurationInSeconds: 93840.5,
|
||||
TotalPlayCount: 512,
|
||||
CompletedPlayCount: 388,
|
||||
StoppedPlayCount: 124,
|
||||
CompletionRate: 0.7578125)
|
||||
);
|
||||
|
||||
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/music-play-history/statistics"
|
||||
},
|
||||
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/music-play-history/statistics"
|
||||
},
|
||||
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/music-play-history/statistics"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
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/music-play-history/statistics",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetRecentlyPlayed;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Common.Routes.Library.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetRecentlyPlayed;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/music-play-history/recently-played</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class GetRecentlyPlayedEndpoint : BaseEndpoint<GetRecentlyPlayedRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetRecentlyPlayedQuery, Result<PaginatedResponse<PlayedTrackResponse>>> _getRecentlyPlayedQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRecentlyPlayedEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getRecentlyPlayedQueryHandler">Injected service for handling get recently played queries.</param>
|
||||
public GetRecentlyPlayedEndpoint(IQueryHandler<GetRecentlyPlayedQuery, Result<PaginatedResponse<PlayedTrackResponse>>> getRecentlyPlayedQueryHandler)
|
||||
{
|
||||
_getRecentlyPlayedQueryHandler = getRecentlyPlayedQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.PlayStatistics.GET_RECENTLY_PLAYED);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the recently played tracks of the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the optional page bounds.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetRecentlyPlayedRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The statistics 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<PlayedTrackResponse>> result = await _getRecentlyPlayedQueryHandler.HandleAsync(request.ToQuery(), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetRecentlyPlayed;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetRecentlyPlayedEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetRecentlyPlayedEndpointSummary : Summary<GetRecentlyPlayedEndpoint, GetRecentlyPlayedRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRecentlyPlayedEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetRecentlyPlayedEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the recently played tracks of the current user.";
|
||||
Description = "Gets the tracks the current user played recently, from the most recently played. Only the plays that count as plays are included: a play counts when it completed or when the listened duration reached 30 seconds. Each track is returned once, with its last activity time, its counted plays, its completed plays and the duration the user listened to it. A track deleted from its library keeps its row, without display data. The response is private to the authenticated user.";
|
||||
|
||||
ExampleRequest = new GetRecentlyPlayedRequest(CurrentPage: 1, PerPage: 50);
|
||||
RequestParam(request => request.CurrentPage, "The one based page of tracks to return. Optional. Defaults to 1.");
|
||||
RequestParam(request => request.PerPage, "The number of tracks per page. Optional. Defaults to 50. When both pagination parameters are omitted, every matching track is returned.");
|
||||
|
||||
ResponseParam<PaginatedResponse<PlayedTrackResponse>>(response => response.Data, "The recently played tracks of the requested page, from the most recently played.");
|
||||
ResponseParam<PaginatedResponse<PlayedTrackResponse>>(response => response.CurrentPage, "The current page number.");
|
||||
ResponseParam<PaginatedResponse<PlayedTrackResponse>>(response => response.PerPage, "The number of tracks retrieved per page.");
|
||||
ResponseParam<PaginatedResponse<PlayedTrackResponse>>(response => response.Count, "The total number of tracks that match the filters.");
|
||||
ResponseParam<PaginatedResponse<PlayedTrackResponse>>(response => response.NumberOfPages, "The total number of pages.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.TrackId, "The Id of the track.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.LibraryId, "The Id of the media library that contains the track.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.AlbumId, "The Id of the album that contains the track.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.ArtistId, "The Id of the artist that produced the track.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.Title, "The title of the track, if it still exists and the user can access its library.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.AlbumTitle, "The title of the album that contains the track, if available.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.ArtistName, "The name of the artist that produced the track, if available.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.CoverPath, "The path of the cover art of the album, if available.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.LastPlayedOnUtc, "The date and time of the last recorded activity of the track's most recent play.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.PlayCount, "The number of plays of the track that count as plays.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.CompletedPlayCount, "The number of plays of the track that completed.");
|
||||
ResponseParam<PlayedTrackResponse>(response => response.ListenedDurationInSeconds, "The duration the user listened to the track, over all of its counted plays, in seconds.");
|
||||
|
||||
Response(200, "The requested page of recently played tracks is returned.",
|
||||
example: new PaginatedResponse<PlayedTrackResponse>
|
||||
{
|
||||
Data =
|
||||
[
|
||||
new PlayedTrackResponse(
|
||||
TrackId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"),
|
||||
LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"),
|
||||
AlbumId: Guid.Parse("e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f"),
|
||||
ArtistId: Guid.Parse("d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a"),
|
||||
Title: "Time",
|
||||
AlbumTitle: "The Dark Side of the Moon",
|
||||
ArtistName: "Pink Floyd",
|
||||
CoverPath: "covers/dark-side-of-the-moon.jpg",
|
||||
LastPlayedOnUtc: new DateTime(2026, 10, 20, 18, 30, 0, DateTimeKind.Utc),
|
||||
PlayCount: 12,
|
||||
CompletedPlayCount: 9,
|
||||
ListenedDurationInSeconds: 4230.5)
|
||||
],
|
||||
CurrentPage = 1,
|
||||
PerPage = 50,
|
||||
Count = 1,
|
||||
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/music-play-history/recently-played"
|
||||
},
|
||||
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/music-play-history/recently-played"
|
||||
},
|
||||
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/music-play-history/recently-played"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
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/music-play-history/recently-played",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+13
@@ -44,6 +44,19 @@ public class GetAllUsersConsumptionStatisticsEndpointSummary : Summary<GetAllUse
|
||||
ResponseParam<ConsumptionTotalsResponse>(response => response.StoppedSessionCount, "The number of recorded sessions of every user that stopped before they completed and count towards statistics.");
|
||||
ResponseParam<ConsumptionTotalsResponse>(response => response.CompletionRate, "The fraction of the counted sessions of every user that completed, between 0 and 1, or 0 when there is no counted session.");
|
||||
ResponseParam<ConsumptionTotalsResponse>(response => response.MediaKindSummaries, "The combined consumption statistics broken down by media kind.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.UserId, "The Id of the user the summary belongs to.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.TotalConsumedDurationInSeconds, "The total duration consumed over every recorded session of the user, in seconds.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.CountedSessionCount, "The number of recorded sessions of the user that count towards statistics.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.CompletedSessionCount, "The number of recorded sessions of the user that completed.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.StoppedSessionCount, "The number of recorded sessions of the user that stopped before they completed and count towards statistics.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.CompletionRate, "The fraction of the counted sessions of the user that completed, between 0 and 1.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.MediaKindSummaries, "The consumption statistics of the user broken down by media kind.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.MediaKind, "The kind of media the breakdown entry belongs to.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.TotalConsumedDurationInSeconds, "The total duration consumed over every recorded session of the media kind, in seconds.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.CountedSessionCount, "The number of recorded sessions of the media kind that count towards statistics.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.CompletedSessionCount, "The number of recorded sessions of the media kind that completed.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.StoppedSessionCount, "The number of recorded sessions of the media kind that stopped before they completed and count towards statistics.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.CompletionRate, "The fraction of the counted sessions of the media kind that completed, between 0 and 1.");
|
||||
|
||||
Response<AllUsersConsumptionStatisticsResponse>(statusCode: 200, description: "The consumption statistics of every user are returned.", contentType: "application/json",
|
||||
example: new AllUsersConsumptionStatisticsResponse(
|
||||
|
||||
+7
-1
@@ -42,7 +42,13 @@ public class GetConsumptionStatisticsEndpointSummary : Summary<GetConsumptionSta
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.CompletedSessionCount, "The number of recorded sessions that completed.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.StoppedSessionCount, "The number of recorded sessions that stopped before they completed and count towards statistics.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.CompletionRate, "The fraction of the counted sessions that completed, between 0 and 1, or 0 when there is no counted session.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.MediaKindSummaries, "The consumption statistics broken down by media kind. Each entry carries the media kind, the consumed duration, the counted, completed and stopped session counts, and the completion rate of that kind.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.MediaKindSummaries, "The consumption statistics broken down by media kind.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.MediaKind, "The kind of media the breakdown entry belongs to.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.TotalConsumedDurationInSeconds, "The total duration consumed over every recorded session of the media kind, in seconds.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.CountedSessionCount, "The number of recorded sessions of the media kind that count towards statistics.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.CompletedSessionCount, "The number of recorded sessions of the media kind that completed.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.StoppedSessionCount, "The number of recorded sessions of the media kind that stopped before they completed and count towards statistics.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.CompletionRate, "The fraction of the counted sessions of the media kind that completed, between 0 and 1.");
|
||||
|
||||
Response<ConsumptionSummaryResponse>(statusCode: 200, description: "The consumption statistics of the current user are returned.", contentType: "application/json",
|
||||
example: new ConsumptionSummaryResponse(
|
||||
|
||||
+7
-1
@@ -43,7 +43,13 @@ public class GetUserConsumptionStatisticsEndpointSummary : Summary<GetUserConsum
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.CompletedSessionCount, "The number of recorded sessions that completed.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.StoppedSessionCount, "The number of recorded sessions that stopped before they completed and count towards statistics.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.CompletionRate, "The fraction of the counted sessions that completed, between 0 and 1, or 0 when there is no counted session.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.MediaKindSummaries, "The consumption statistics broken down by media kind. Each entry carries the media kind, the consumed duration, the counted, completed and stopped session counts, and the completion rate of that kind.");
|
||||
ResponseParam<ConsumptionSummaryResponse>(response => response.MediaKindSummaries, "The consumption statistics broken down by media kind.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.MediaKind, "The kind of media the breakdown entry belongs to.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.TotalConsumedDurationInSeconds, "The total duration consumed over every recorded session of the media kind, in seconds.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.CountedSessionCount, "The number of recorded sessions of the media kind that count towards statistics.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.CompletedSessionCount, "The number of recorded sessions of the media kind that completed.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.StoppedSessionCount, "The number of recorded sessions of the media kind that stopped before they completed and count towards statistics.");
|
||||
ResponseParam<MediaKindConsumptionSummaryResponse>(response => response.CompletionRate, "The fraction of the counted sessions of the media kind that completed, between 0 and 1.");
|
||||
|
||||
Response<ConsumptionSummaryResponse>(statusCode: 200, description: "The consumption statistics of the user are returned.", contentType: "application/json",
|
||||
example: new ConsumptionSummaryResponse(
|
||||
|
||||
Reference in new issue
Block a user