mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11:10 +00:00
Removes the old music play history surface and drops its table
This commit is contained in:
1 parent
0b5b65391c
commit
bc619679e8
83 files changed
+3955
-4893
No files matched your search
-58
@@ -1,58 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.CompletePlay;
|
||||
using Lumina.Contracts.Requests.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.CompletePlay;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/music-play-history/plays/{playRecordId}/complete</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class CompletePlayEndpoint : BaseEndpoint<CompletePlayRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<CompletePlayCommand, Result<Updated>> _completePlayCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CompletePlayEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="completePlayCommandHandler">Injected service for handling complete play commands.</param>
|
||||
public CompletePlayEndpoint(ICommandHandler<CompletePlayCommand, Result<Updated>> completePlayCommandHandler)
|
||||
{
|
||||
_completePlayCommandHandler = completePlayCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.PUT);
|
||||
Routes(ApiRoutes.PlayHistory.COMPLETE_PLAY);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reports that a play of a track by the current user reached its end.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the last position and the listened duration.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(CompletePlayRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Take the unique identifier from the route.
|
||||
string? playRecordId = HttpContext.Request.RouteValues["playRecordId"]?.ToString();
|
||||
Result<Updated> result = await _completePlayCommandHandler.HandleAsync(request.ToCommand(playRecordId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
-129
@@ -1,129 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.CompletePlay;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="CompletePlayEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CompletePlayEndpointSummary : Summary<CompletePlayEndpoint, CompletePlayRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CompletePlayEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public CompletePlayEndpointSummary()
|
||||
{
|
||||
Summary = "Reports that a play of a track by the current user reached its end.";
|
||||
Description = "Reports that a play of a track by the current user reached its end, together with the last position and the listened duration. Only an in-progress play of the current user can be completed, and the listened duration can never decrease. The reports are stored so that the play history, statistics and recommendations can be built from them.";
|
||||
|
||||
ExampleRequest = new CompletePlayRequest(
|
||||
PositionInSeconds: 354,
|
||||
ListenedDurationInSeconds: 354
|
||||
);
|
||||
|
||||
RequestParam(request => request.PositionInSeconds, "The last position reported by the player, in seconds. Required.");
|
||||
RequestParam(request => request.ListenedDurationInSeconds, "The duration the user listened to, in seconds. Required.");
|
||||
|
||||
Response(200, "The completion of the play was reported.", example: new { });
|
||||
|
||||
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/plays/{Guid.NewGuid()}/complete"
|
||||
},
|
||||
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/plays/{Guid.NewGuid()}/complete"
|
||||
},
|
||||
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/plays/{Guid.NewGuid()}/complete"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the play record 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 = "MusicPlayRecordNotFound",
|
||||
instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/complete",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because the play is not in progress anymore, or because another report changed it after this request read it.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "PlayIsNotInProgress",
|
||||
instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/complete",
|
||||
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/music-play-history/plays/{Guid.NewGuid()}/complete",
|
||||
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/music-play-history/plays/{Guid.NewGuid()}/complete",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlayRecordIdCannotBeEmpty",
|
||||
"PlaybackPositionCannotBeNull",
|
||||
"PlaybackPositionMustBeNonNegative",
|
||||
"PlaybackPositionIsOutOfRange",
|
||||
"ListenedDurationCannotBeNull",
|
||||
"ListenedDurationMustBeNonNegative",
|
||||
"ListenedDurationIsOutOfRange",
|
||||
"ListenedDurationCannotDecrease"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
#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
@@ -1,116 +0,0 @@
|
||||
#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
@@ -1,60 +0,0 @@
|
||||
#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
@@ -1,80 +0,0 @@
|
||||
#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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
-62
@@ -1,62 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Queries.GetPlayRecord;
|
||||
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.GetPlayRecord;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/music-play-history/plays/{playRecordId}</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class GetPlayRecordEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IQueryHandler<GetPlayRecordQuery, Result<PlayRecordResponse>> _getPlayRecordQueryHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPlayRecordEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="getPlayRecordQueryHandler">Injected service for handling get play record queries.</param>
|
||||
public GetPlayRecordEndpoint(IQueryHandler<GetPlayRecordQuery, Result<PlayRecordResponse>> getPlayRecordQueryHandler)
|
||||
{
|
||||
_getPlayRecordQueryHandler = getPlayRecordQueryHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(Http.GET);
|
||||
Routes(ApiRoutes.PlayHistory.GET_PLAY);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a recorded play of a track by 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 play record 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? playRecordId = HttpContext.Request.RouteValues["playRecordId"]?.ToString();
|
||||
Result<PlayRecordResponse> result = await _getPlayRecordQueryHandler.HandleAsync(new GetPlayRecordQuery(playRecordId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.GetPlayRecord;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetPlayRecordEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPlayRecordEndpointSummary : Summary<GetPlayRecordEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetPlayRecordEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetPlayRecordEndpointSummary()
|
||||
{
|
||||
Summary = "Retrieves a recorded play of a track by the current user.";
|
||||
Description = "Retrieves the play record identified by the route, when it belongs to the current user. The record carries the last reported position, the listened duration and whether the play is in progress, completed or stopped. It never carries a queue, a current index, a repeat or shuffle state, or a playback session.";
|
||||
|
||||
ResponseParam<PlayRecordResponse>(r => r.Id, "The Id of the play record.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.TrackId, "The Id of the track that was played.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.LibraryId, "The Id of the media library that contains the track.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.AlbumId, "The Id of the album that contains the track.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.ArtistId, "The Id of the artist that produced the track.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.Status, "The state of the recorded play.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.LastPositionInSeconds, "The last position reported by the player, in seconds.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.ListenedDurationInSeconds, "The duration the user has listened to, in seconds.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.StartedOnUtc, "The date and time when the play started.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.EndedOnUtc, "The date and time when the play completed or stopped, if it has ended.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.UpdatedOnUtc, "The date and time when the play record was last updated, if applicable.");
|
||||
|
||||
Response(200, "The play record is returned.",
|
||||
example: new PlayRecordResponse(
|
||||
Id: Guid.Parse("2c1b0a9f-8e7d-4c6b-5a4f-3e2d1c0b9a8f"),
|
||||
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"),
|
||||
Status: PlaybackRecordStatus.Stopped,
|
||||
LastPositionInSeconds: 92.5,
|
||||
ListenedDurationInSeconds: 92.5,
|
||||
StartedOnUtc: new DateTime(2026, 10, 19, 12, 0, 0, DateTimeKind.Utc),
|
||||
EndedOnUtc: new DateTime(2026, 10, 19, 12, 1, 32, 500, DateTimeKind.Utc),
|
||||
UpdatedOnUtc: new DateTime(2026, 10, 19, 12, 1, 32, 500, 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/music-play-history/plays/{Guid.NewGuid()}"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token has expired",
|
||||
instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the play record 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 = "MusicPlayRecordNotFound",
|
||||
instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlayRecordIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
#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
@@ -1,116 +0,0 @@
|
||||
#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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.ReportPlayProgress;
|
||||
using Lumina.Contracts.Requests.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.ReportPlayProgress;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/music-play-history/plays/{playRecordId}/progress</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class ReportPlayProgressEndpoint : BaseEndpoint<ReportPlayProgressRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<ReportPlayProgressCommand, Result<Updated>> _reportPlayProgressCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ReportPlayProgressEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="reportPlayProgressCommandHandler">Injected service for handling report play progress commands.</param>
|
||||
public ReportPlayProgressEndpoint(ICommandHandler<ReportPlayProgressCommand, Result<Updated>> reportPlayProgressCommandHandler)
|
||||
{
|
||||
_reportPlayProgressCommandHandler = reportPlayProgressCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.PUT);
|
||||
Routes(ApiRoutes.PlayHistory.REPORT_PLAY_PROGRESS);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reports the progress of a play of a track by the current user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the last position and the listened duration.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(ReportPlayProgressRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Take the unique identifier from the route.
|
||||
string? playRecordId = HttpContext.Request.RouteValues["playRecordId"]?.ToString();
|
||||
Result<Updated> result = await _reportPlayProgressCommandHandler.HandleAsync(request.ToCommand(playRecordId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
-129
@@ -1,129 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.ReportPlayProgress;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="ReportPlayProgressEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ReportPlayProgressEndpointSummary : Summary<ReportPlayProgressEndpoint, ReportPlayProgressRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ReportPlayProgressEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public ReportPlayProgressEndpointSummary()
|
||||
{
|
||||
Summary = "Reports the progress of a play of a track by the current user.";
|
||||
Description = "Reports the last position and the listened duration of a play of a track by the current user. Only an in-progress play of the current user can be progressed, and the listened duration can never decrease. The reports are stored so that the play history, statistics and recommendations can be built from them.";
|
||||
|
||||
ExampleRequest = new ReportPlayProgressRequest(
|
||||
PositionInSeconds: 92.5,
|
||||
ListenedDurationInSeconds: 92.5
|
||||
);
|
||||
|
||||
RequestParam(request => request.PositionInSeconds, "The last position reported by the player, in seconds. Required.");
|
||||
RequestParam(request => request.ListenedDurationInSeconds, "The duration the user has listened to, in seconds. Required.");
|
||||
|
||||
Response(200, "The progress of the play was reported.", example: new { });
|
||||
|
||||
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/plays/{Guid.NewGuid()}/progress"
|
||||
},
|
||||
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/plays/{Guid.NewGuid()}/progress"
|
||||
},
|
||||
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/plays/{Guid.NewGuid()}/progress"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the play record 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 = "MusicPlayRecordNotFound",
|
||||
instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/progress",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because the play is not in progress anymore, or because another report changed it after this request read it.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "PlayIsNotInProgress",
|
||||
instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/progress",
|
||||
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/music-play-history/plays/{Guid.NewGuid()}/progress",
|
||||
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/music-play-history/plays/{Guid.NewGuid()}/progress",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlayRecordIdCannotBeEmpty",
|
||||
"PlaybackPositionCannotBeNull",
|
||||
"PlaybackPositionMustBeNonNegative",
|
||||
"PlaybackPositionIsOutOfRange",
|
||||
"ListenedDurationCannotBeNull",
|
||||
"ListenedDurationMustBeNonNegative",
|
||||
"ListenedDurationIsOutOfRange",
|
||||
"ListenedDurationCannotDecrease"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.StartPlay;
|
||||
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.StartPlay;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}/plays</c> route.
|
||||
/// </summary>
|
||||
public class StartPlayEndpoint : BaseEndpoint<FastEndpoints.EmptyRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<StartPlayCommand, Result<PlayRecordResponse>> _startPlayCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StartPlayEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="startPlayCommandHandler">Injected service for handling start play commands.</param>
|
||||
public StartPlayEndpoint(ICommandHandler<StartPlayCommand, Result<PlayRecordResponse>> startPlayCommandHandler)
|
||||
{
|
||||
_startPlayCommandHandler = startPlayCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.POST);
|
||||
Routes(ApiRoutes.PlayHistory.START_PLAY);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Records the start of a play of a track by 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, so that they cannot be replaced by values posted in a body.
|
||||
string? libraryId = HttpContext.Request.RouteValues["libraryId"]?.ToString();
|
||||
string? artistId = HttpContext.Request.RouteValues["artistId"]?.ToString();
|
||||
string? albumId = HttpContext.Request.RouteValues["albumId"]?.ToString();
|
||||
string? trackId = HttpContext.Request.RouteValues["trackId"]?.ToString();
|
||||
Result<PlayRecordResponse> result = await _startPlayCommandHandler
|
||||
.HandleAsync(new StartPlayCommand(libraryId, artistId, albumId, trackId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
-144
@@ -1,144 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Playback;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.StartPlay;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="StartPlayEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class StartPlayEndpointSummary : Summary<StartPlayEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StartPlayEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public StartPlayEndpointSummary()
|
||||
{
|
||||
Summary = "Records the start of a play of a track by the current user.";
|
||||
Description = "Records the start of a play of a track by the current user, so that the play history, statistics and recommendations can be built from it. The track must belong to the named library, album and artist. The play record is returned with its identifier, which the player uses to report its progress, completion or stop. The play record belongs to the current user, and it never stores a queue, a current index, a repeat or shuffle state, or a playback session.";
|
||||
|
||||
ResponseParam<PlayRecordResponse>(r => r.Id, "The Id of the play record.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.TrackId, "The Id of the track that was played.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.LibraryId, "The Id of the media library that contains the track.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.AlbumId, "The Id of the album that contains the track.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.ArtistId, "The Id of the artist that produced the track.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.Status, "The state of the recorded play.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.LastPositionInSeconds, "The last position reported by the player, in seconds.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.ListenedDurationInSeconds, "The duration the user has listened to, in seconds.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.StartedOnUtc, "The date and time when the play started.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.EndedOnUtc, "The date and time when the play completed or stopped, if it has ended.");
|
||||
ResponseParam<PlayRecordResponse>(r => r.UpdatedOnUtc, "The date and time when the play record was last updated, if applicable.");
|
||||
|
||||
Response(200, "The play was recorded and its play record is returned.",
|
||||
example: new PlayRecordResponse(
|
||||
Id: Guid.Parse("2c1b0a9f-8e7d-4c6b-5a4f-3e2d1c0b9a8f"),
|
||||
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"),
|
||||
Status: PlaybackRecordStatus.InProgress,
|
||||
LastPositionInSeconds: 0,
|
||||
ListenedDurationInSeconds: 0,
|
||||
StartedOnUtc: new DateTime(2026, 10, 19, 12, 0, 0, DateTimeKind.Utc),
|
||||
EndedOnUtc: null,
|
||||
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/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token has expired",
|
||||
instance = "/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays"
|
||||
},
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
|
||||
status = 401,
|
||||
title = "Unauthorized",
|
||||
detail = "The token is invalid",
|
||||
instance = "/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(403, "The request failed because the user making the request is not an Admin, or the owner of the media library.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.4",
|
||||
title = "General.Unauthorized",
|
||||
status = 403,
|
||||
detail = "NotAuthorized",
|
||||
instance = "/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays",
|
||||
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the album or the track does not exist, or they do not belong to the library, artist and album named by the request.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.5",
|
||||
title = "General.NotFound",
|
||||
status = 404,
|
||||
detail = "AlbumNotFound",
|
||||
instance = "/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays",
|
||||
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/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(422, "The request did not pass validation checks.", "application/problem+json",
|
||||
example: new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
title = "General.Validation",
|
||||
status = 422,
|
||||
detail = "OneOrMoreValidationErrorsOccurred",
|
||||
instance = "/api/v1/libraries/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a/artists/d7c41e6a-9f2b-4b1c-9a3e-7f6e5d4c3b2a/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/tracks/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/plays",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"LibraryIdCannotBeEmpty",
|
||||
"ArtistIdCannotBeEmpty",
|
||||
"AlbumIdCannotBeEmpty",
|
||||
"TrackIdCannotBeEmpty"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Application.Core.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory.Commands.StopPlay;
|
||||
using Lumina.Contracts.Requests.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.StopPlay;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/users/me/music-play-history/plays/{playRecordId}/stop</c> route.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Uses "me" because it is always for the currently authenticated user.
|
||||
/// </remarks>
|
||||
public class StopPlayEndpoint : BaseEndpoint<StopPlayRequest, IResult>
|
||||
{
|
||||
private readonly ICommandHandler<StopPlayCommand, Result<Updated>> _stopPlayCommandHandler;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StopPlayEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="stopPlayCommandHandler">Injected service for handling stop play commands.</param>
|
||||
public StopPlayEndpoint(ICommandHandler<StopPlayCommand, Result<Updated>> stopPlayCommandHandler)
|
||||
{
|
||||
_stopPlayCommandHandler = stopPlayCommandHandler;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
Verbs(FastEndpoints.Http.PUT);
|
||||
Routes(ApiRoutes.PlayHistory.STOP_PLAY);
|
||||
Version(1);
|
||||
DontCatchExceptions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reports that a play of a track by the current user stopped before the track completed.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the last position and the listened duration.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(StopPlayRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// Take the unique identifier from the route.
|
||||
string? playRecordId = HttpContext.Request.RouteValues["playRecordId"]?.ToString();
|
||||
Result<Updated> result = await _stopPlayCommandHandler.HandleAsync(request.ToCommand(playRecordId), cancellationToken).ConfigureAwait(false);
|
||||
return result.Match(success => TypedResults.Ok(success), Problem);
|
||||
}
|
||||
}
|
||||
-129
@@ -1,129 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.PlayHistory.StopPlay;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="StopPlayEndpoint"/> API endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class StopPlayEndpointSummary : Summary<StopPlayEndpoint, StopPlayRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StopPlayEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public StopPlayEndpointSummary()
|
||||
{
|
||||
Summary = "Reports that a play of a track by the current user stopped before the track completed.";
|
||||
Description = "Reports that a play of a track by the current user stopped before the track completed, together with the last position and the listened duration. Only an in-progress play of the current user can be stopped, and the listened duration can never decrease. The reports are stored so that the play history, statistics and recommendations can be built from them.";
|
||||
|
||||
ExampleRequest = new StopPlayRequest(
|
||||
PositionInSeconds: 92.5,
|
||||
ListenedDurationInSeconds: 92.5
|
||||
);
|
||||
|
||||
RequestParam(request => request.PositionInSeconds, "The last position reported by the player, in seconds. Required.");
|
||||
RequestParam(request => request.ListenedDurationInSeconds, "The duration the user listened to, in seconds. Required.");
|
||||
|
||||
Response(200, "The stop of the play was reported.", example: new { });
|
||||
|
||||
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/plays/{Guid.NewGuid()}/stop"
|
||||
},
|
||||
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/plays/{Guid.NewGuid()}/stop"
|
||||
},
|
||||
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/plays/{Guid.NewGuid()}/stop"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Response(404, "The request failed because the play record 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 = "MusicPlayRecordNotFound",
|
||||
instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/stop",
|
||||
traceId = "00-57d15dadd702dbd4aeb5dc9b7cee68ee-9330237dbb2ce0e5-00"
|
||||
}
|
||||
);
|
||||
|
||||
Response(409, "The request failed because the play is not in progress anymore, or because another report changed it after this request read it.", "application/problem+json",
|
||||
example: new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
|
||||
title = "General.Conflict",
|
||||
status = 409,
|
||||
detail = "PlayIsNotInProgress",
|
||||
instance = $"/api/v1/users/me/music-play-history/plays/{Guid.NewGuid()}/stop",
|
||||
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/music-play-history/plays/{Guid.NewGuid()}/stop",
|
||||
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/music-play-history/plays/{Guid.NewGuid()}/stop",
|
||||
errors = new Dictionary<string, string[]>
|
||||
{
|
||||
{
|
||||
"General.Validation", new[]
|
||||
{
|
||||
"PlayRecordIdCannotBeEmpty",
|
||||
"PlaybackPositionCannotBeNull",
|
||||
"PlaybackPositionMustBeNonNegative",
|
||||
"PlaybackPositionIsOutOfRange",
|
||||
"ListenedDurationCannotBeNull",
|
||||
"ListenedDurationMustBeNonNegative",
|
||||
"ListenedDurationIsOutOfRange",
|
||||
"ListenedDurationCannotDecrease"
|
||||
}
|
||||
}
|
||||
},
|
||||
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user