Adds the media-neutral library statistics page and separates tags from genres

This commit is contained in:
BinaryAlley committed 2026-10-25 15:51:27 +02:00
1 parent a61fbf407c
commit 00d7eff777
118 files changed
+6132 -1154

No files matched your search

@@ -14,13 +14,17 @@ public static partial class ApiRoutes
public const string GET_MOST_CONSUMED = "/users/me/consumption-history/most-consumed";
public const string GET_CONSUMPTION_STATISTICS = "/users/me/consumption-statistics";
public const string GET_TAG_CONSUMPTION = "/users/me/consumption-statistics/tags";
public const string GET_GENRE_CONSUMPTION = "/users/me/consumption-statistics/genres";
public const string GET_USER_RECENTLY_CONSUMED = "/users/{userId}/consumption-history/recently-consumed";
public const string GET_USER_MOST_CONSUMED = "/users/{userId}/consumption-history/most-consumed";
public const string GET_USER_CONSUMPTION_STATISTICS = "/users/{userId}/consumption-statistics";
public const string GET_USER_TAG_CONSUMPTION = "/users/{userId}/consumption-statistics/tags";
public const string GET_USER_GENRE_CONSUMPTION = "/users/{userId}/consumption-statistics/genres";
public const string GET_ALL_USERS_CONSUMPTION_STATISTICS = "/users/consumption-statistics";
public const string DELETE_CONSUMPTION_RECORD = "/users/me/consumption-history/{recordId}";
public const string DELETE_USER_CONSUMPTION_RECORD = "/users/{userId}/consumption-history/{recordId}";
public const string DELETE_CONSUMPTION_ITEM_HISTORY = "/users/me/consumption-history/media-items/{mediaKind}/{mediaItemId}/{libraryId}";
public const string DELETE_USER_CONSUMPTION_ITEM_HISTORY = "/users/{userId}/consumption-history/media-items/{mediaKind}/{mediaItemId}/{libraryId}";
public const string CLEAR_CONSUMPTION_HISTORY = "/users/me/consumption-history";
public const string CLEAR_USER_CONSUMPTION_HISTORY = "/users/{userId}/consumption-history";
public const string CLEAR_RESUME_POINTS = "/users/me/media-resume-points";
@@ -0,0 +1,60 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.MediaConsumption.Commands.DeleteConsumptionItemHistory;
using Lumina.Contracts.Requests.MediaConsumption;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.Statistics;
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.Statistics.DeleteConsumptionItemHistory;
/// <summary>
/// API endpoint for the <c>/users/me/consumption-history/media-items/{mediaKind}/{mediaItemId}/{libraryId}</c> route.
/// </summary>
/// <remarks>
/// Uses "me" because it is always for the currently authenticated user.
/// </remarks>
public class DeleteConsumptionItemHistoryEndpoint : BaseEndpoint<DeleteConsumptionItemHistoryRequest, IResult>
{
private readonly ICommandHandler<DeleteConsumptionItemHistoryCommand, Result<Deleted>> _deleteConsumptionItemHistoryCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="DeleteConsumptionItemHistoryEndpoint"/> class.
/// </summary>
/// <param name="deleteConsumptionItemHistoryCommandHandler">Injected service for handling delete consumption item history commands.</param>
public DeleteConsumptionItemHistoryEndpoint(ICommandHandler<DeleteConsumptionItemHistoryCommand, Result<Deleted>> deleteConsumptionItemHistoryCommandHandler)
{
_deleteConsumptionItemHistoryCommandHandler = deleteConsumptionItemHistoryCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.DELETE);
Routes(ApiRoutes.LibraryStatistics.DELETE_CONSUMPTION_ITEM_HISTORY);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Deletes every consumption record of a media item of the current user.
/// </summary>
/// <param name="request">The request containing the media item and its library.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(DeleteConsumptionItemHistoryRequest request, CancellationToken cancellationToken)
{
// The consumption records 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.Append("Vary", "Authorization");
Result<Deleted> result = await _deleteConsumptionItemHistoryCommandHandler
.HandleAsync(new DeleteConsumptionItemHistoryCommand(TargetUserId: null, request.MediaKind, request.MediaItemId, request.LibraryId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,99 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaConsumption;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.Statistics.DeleteConsumptionItemHistory;
/// <summary>
/// Class used for providing a textual description for the <see cref="DeleteConsumptionItemHistoryEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteConsumptionItemHistoryEndpointSummary : Summary<DeleteConsumptionItemHistoryEndpoint, DeleteConsumptionItemHistoryRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="DeleteConsumptionItemHistoryEndpointSummary"/> class.
/// </summary>
public DeleteConsumptionItemHistoryEndpointSummary()
{
Summary = "Deletes every consumption record of a media item of the current user.";
Description = "Deletes every recorded consumption session of one media item of the current user, in the library named by the route. The deletion covers every session of the item, independent of any date range, so the item disappears from the history consistently with clearing the whole history. Deleting an item that has no recorded session changes nothing and is not an error, so a retried deletion is safe; a concurrent write can still be rejected with a conflict. The resume point of the media item is not deleted: removing an item from the history and removing it from continue watching are separate user actions. The records of another user are never deleted by this route.";
Params["mediaKind"] = "The kind of the consumed media item.";
Params["mediaItemId"] = "The Id of the consumed media item.";
Params["libraryId"] = "The Id of the media library that contains the media item.";
Response(200, "The consumption records of the media item were successfully deleted.");
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Authentication failed",
instance = "/api/v1/users/me/consumption-history/media-items/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"
},
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/consumption-history/media-items/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"
}
}
);
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/consumption-history/media-items/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(409, "The request failed because the deletion could not be stored, because the database is busy or locked, or because another request changed the same data after this request read it. Repeating the request is safe.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
title = "General.Conflict",
status = 409,
detail = "ConcurrencyConflict",
instance = "/api/v1/users/me/consumption-history/media-items/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
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/consumption-history/media-items/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"UnsupportedMediaKind",
"MediaItemIdCannotBeEmpty",
"LibraryIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,58 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.MediaConsumption.Commands.DeleteConsumptionItemHistory;
using Lumina.Contracts.Requests.MediaConsumption;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.Statistics;
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.Statistics.DeleteConsumptionItemHistory;
/// <summary>
/// API endpoint for the <c>/users/{userId}/consumption-history/media-items/{mediaKind}/{mediaItemId}/{libraryId}</c> route.
/// </summary>
public class DeleteUserConsumptionItemHistoryEndpoint : BaseEndpoint<DeleteConsumptionItemHistoryRequest, IResult>
{
private readonly ICommandHandler<DeleteConsumptionItemHistoryCommand, Result<Deleted>> _deleteConsumptionItemHistoryCommandHandler;
/// <summary>
/// Initializes a new instance of the <see cref="DeleteUserConsumptionItemHistoryEndpoint"/> class.
/// </summary>
/// <param name="deleteConsumptionItemHistoryCommandHandler">Injected service for handling delete consumption item history commands.</param>
public DeleteUserConsumptionItemHistoryEndpoint(ICommandHandler<DeleteConsumptionItemHistoryCommand, Result<Deleted>> deleteConsumptionItemHistoryCommandHandler)
{
_deleteConsumptionItemHistoryCommandHandler = deleteConsumptionItemHistoryCommandHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.DELETE);
Routes(ApiRoutes.LibraryStatistics.DELETE_USER_CONSUMPTION_ITEM_HISTORY);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Deletes every consumption record of a media item of a user.
/// </summary>
/// <param name="request">The request containing the media item and its library.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(DeleteConsumptionItemHistoryRequest request, CancellationToken cancellationToken)
{
// The consumption records belong to the target user, and only that user or an Admin may delete them, 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.Append("Vary", "Authorization");
string? targetUserId = HttpContext.Request.RouteValues["userId"]?.ToString();
Result<Deleted> result = await _deleteConsumptionItemHistoryCommandHandler
.HandleAsync(new DeleteConsumptionItemHistoryCommand(targetUserId, request.MediaKind, request.MediaItemId, request.LibraryId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,101 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaConsumption;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.Statistics.DeleteConsumptionItemHistory;
/// <summary>
/// Class used for providing a textual description for the <see cref="DeleteUserConsumptionItemHistoryEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteUserConsumptionItemHistoryEndpointSummary : Summary<DeleteUserConsumptionItemHistoryEndpoint, DeleteConsumptionItemHistoryRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="DeleteUserConsumptionItemHistoryEndpointSummary"/> class.
/// </summary>
public DeleteUserConsumptionItemHistoryEndpointSummary()
{
Summary = "Deletes every consumption record of a media item of a user.";
Description = "Deletes every recorded consumption session of one media item of a user, in the library named by the route. The deletion covers every session of the item, independent of any date range, so the item disappears from the history consistently with clearing the whole history. A user can delete only their own history, while an Admin can select any user with the userId route parameter; a regular user targeting another user receives the same not authorized result as a route that names no accessible user. Deleting an item that has no recorded session changes nothing and is not an error, so a retried deletion is safe; a concurrent write can still be rejected with a conflict. The resume point of the media item is not deleted: removing an item from the history and removing it from continue watching are separate user actions.";
Params["userId"] = "The Id of the user whose history is deleted. An Admin can name any user; a regular user can only name themselves.";
Params["mediaKind"] = "The kind of the consumed media item.";
Params["mediaItemId"] = "The Id of the consumed media item.";
Params["libraryId"] = "The Id of the media library that contains the media item.";
Response(200, "The consumption records of the media item were successfully deleted.");
Response(401, "Authentication required.", "application/problem+json",
example: new[]
{
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "Authentication failed",
instance = "/api/v1/users/1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d/consumption-history/media-items/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token has expired",
instance = "/api/v1/users/1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d/consumption-history/media-items/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"
}
}
);
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/1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d/consumption-history/media-items/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
traceId = "00-a712bbf99ca8ab485f86a762ae5ae74d-b3a2eb78813b0a5d-00"
}
);
Response(409, "The request failed because the deletion could not be stored, because the database is busy or locked, or because another request changed the same data after this request read it. Repeating the request is safe.", "application/problem+json",
example: new
{
type = "https://tools.ietf.org/html/rfc9110#section-15.5.10",
title = "General.Conflict",
status = 409,
detail = "ConcurrencyConflict",
instance = "/api/v1/users/1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d/consumption-history/media-items/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
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/1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d/consumption-history/media-items/MusicTrack/9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f/3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"TargetUserIdIsInvalid",
"UnsupportedMediaKind",
"MediaItemIdCannotBeEmpty",
"LibraryIdCannotBeEmpty"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,62 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaConsumption;
using Lumina.Application.Core.MediaConsumption.Queries.GetGenreConsumption;
using Lumina.Contracts.Requests.MediaConsumption;
using Lumina.Contracts.Responses.MediaConsumption;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.Statistics;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.Statistics.GetGenreConsumption;
/// <summary>
/// API endpoint for the <c>/users/me/consumption-statistics/genres</c> route.
/// </summary>
/// <remarks>
/// Uses "me" because it is always for the currently authenticated user.
/// </remarks>
public class GetGenreConsumptionEndpoint : BaseEndpoint<GetGenreConsumptionRequest, IResult>
{
private readonly IQueryHandler<GetGenreConsumptionQuery, Result<IReadOnlyList<GenreConsumptionResponse>>> _getGenreConsumptionQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetGenreConsumptionEndpoint"/> class.
/// </summary>
/// <param name="getGenreConsumptionQueryHandler">Injected service for handling get genre consumption queries.</param>
public GetGenreConsumptionEndpoint(IQueryHandler<GetGenreConsumptionQuery, Result<IReadOnlyList<GenreConsumptionResponse>>> getGenreConsumptionQueryHandler)
{
_getGenreConsumptionQueryHandler = getGenreConsumptionQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.GET);
Routes(ApiRoutes.LibraryStatistics.GET_GENRE_CONSUMPTION);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the consumption statistics of the genres of the current user.
/// </summary>
/// <param name="request">The request containing the optional filters and the date range.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetGenreConsumptionRequest request, CancellationToken cancellationToken)
{
// The consumption 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.Append("Vary", "Authorization");
Result<IReadOnlyList<GenreConsumptionResponse>> result = await _getGenreConsumptionQueryHandler.HandleAsync(request.ToQuery(targetUserId: null), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,120 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaConsumption;
using Lumina.Contracts.Responses.MediaConsumption;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.Statistics.GetGenreConsumption;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetGenreConsumptionEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetGenreConsumptionEndpointSummary : Summary<GetGenreConsumptionEndpoint, GetGenreConsumptionRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetGenreConsumptionEndpointSummary"/> class.
/// </summary>
public GetGenreConsumptionEndpointSummary()
{
Summary = "Gets the consumption statistics of the genres of the current user.";
Description = "Gets the genres carried by the media items the current user consumed, grouped by lowercase name across every media kind, or restricted to one kind, one library, and a date range. Only an item with at least one session that counts towards statistics contributes, and each item contributes its genres once regardless of how many sessions it had, so a multi-genre item adds one to each of its genres, not one per session. The names are always lowercase and culture invariant, so a genre that is shared by a book and a track appears in one bucket. Genres of an item whose media item was deleted, or whose media library the user can no longer access, are not included, because their genres cannot be resolved, while their sessions still count in the summary. The statistics of another user are never returned by this route.";
ExampleRequest = new GetGenreConsumptionRequest(
LibraryId: null,
MediaKind: null,
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
);
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the statistics to. Optional.");
RequestParam(request => request.MediaKind, "The kind of media to restrict the statistics to. Optional.");
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
ResponseParam<GenreConsumptionResponse>(response => response.Name, "The lowercase name of the genre.");
ResponseParam<GenreConsumptionResponse>(response => response.ConsumedItemCount, "The number of distinct media items that carry the genre and were consumed.");
ResponseParam<GenreConsumptionResponse>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media items that carry the genre, in seconds.");
Response<IReadOnlyList<GenreConsumptionResponse>>(statusCode: 200, description: "The consumption statistics of the genres of the current user are returned.", contentType: "application/json",
example:
[
new GenreConsumptionResponse(
Name: "horror",
ConsumedItemCount: 3,
ConsumedDurationInSeconds: 5400
),
new GenreConsumptionResponse(
Name: "fantasy",
ConsumedItemCount: 2,
ConsumedDurationInSeconds: 7320
),
new GenreConsumptionResponse(
Name: "science fiction",
ConsumedItemCount: 1,
ConsumedDurationInSeconds: 1424.5
)
]
);
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/consumption-statistics/genres"
},
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/consumption-statistics/genres"
}
}
);
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/consumption-statistics/genres",
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/consumption-statistics/genres",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"UnsupportedMediaKind",
"ConsumptionDateRangeIsInvalid"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -0,0 +1,62 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.CQRS;
using Lumina.Application.Common.Mapping.MediaConsumption;
using Lumina.Application.Core.MediaConsumption.Queries.GetGenreConsumption;
using Lumina.Contracts.Requests.MediaConsumption;
using Lumina.Contracts.Responses.MediaConsumption;
using Lumina.Domain.Common.Primitives;
using Lumina.Presentation.Api.Common.Routes.Library.Statistics;
using Lumina.Presentation.Api.Core.Endpoints.Common;
using Microsoft.AspNetCore.Http;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.Statistics.GetGenreConsumption;
/// <summary>
/// API endpoint for the <c>/users/{userId}/consumption-statistics/genres</c> route.
/// </summary>
public class GetUserGenreConsumptionEndpoint : BaseEndpoint<GetGenreConsumptionRequest, IResult>
{
private readonly IQueryHandler<GetGenreConsumptionQuery, Result<IReadOnlyList<GenreConsumptionResponse>>> _getGenreConsumptionQueryHandler;
/// <summary>
/// Initializes a new instance of the <see cref="GetUserGenreConsumptionEndpoint"/> class.
/// </summary>
/// <param name="getGenreConsumptionQueryHandler">Injected service for handling get genre consumption queries.</param>
public GetUserGenreConsumptionEndpoint(IQueryHandler<GetGenreConsumptionQuery, Result<IReadOnlyList<GenreConsumptionResponse>>> getGenreConsumptionQueryHandler)
{
_getGenreConsumptionQueryHandler = getGenreConsumptionQueryHandler;
}
/// <summary>
/// Configures the API endpoint.
/// </summary>
public override void Configure()
{
Verbs(FastEndpoints.Http.GET);
Routes(ApiRoutes.LibraryStatistics.GET_USER_GENRE_CONSUMPTION);
Version(1);
DontCatchExceptions();
}
/// <summary>
/// Gets the consumption statistics of the genres of a user.
/// </summary>
/// <param name="request">The request containing the optional filters and the date range.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
public override async Task<IResult> ExecuteAsync(GetGenreConsumptionRequest request, CancellationToken cancellationToken)
{
// The consumption statistics belong to the target user, and only that user or an Admin may read them, 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.Append("Vary", "Authorization");
// Take the target user from the route. The access policy in the query decides whether the caller is the target user or an admin, and a
// regular user targeting another user receives the same not authorized result as a route that names no accessible user.
string? targetUserId = HttpContext.Request.RouteValues["userId"]?.ToString();
Result<IReadOnlyList<GenreConsumptionResponse>> result = await _getGenreConsumptionQueryHandler.HandleAsync(request.ToQuery(targetUserId), cancellationToken).ConfigureAwait(false);
return result.Match(success => TypedResults.Ok(success), Problem);
}
}
@@ -0,0 +1,122 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.MediaConsumption;
using Lumina.Contracts.Responses.MediaConsumption;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.Core.Endpoints.Library.Statistics.GetGenreConsumption;
/// <summary>
/// Class used for providing a textual description for the <see cref="GetUserGenreConsumptionEndpoint"/> API endpoint, for OpenAPI.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetUserGenreConsumptionEndpointSummary : Summary<GetUserGenreConsumptionEndpoint, GetGenreConsumptionRequest>
{
/// <summary>
/// Initializes a new instance of the <see cref="GetUserGenreConsumptionEndpointSummary"/> class.
/// </summary>
public GetUserGenreConsumptionEndpointSummary()
{
Summary = "Gets the consumption statistics of the genres of a user.";
Description = "Gets the genres carried by the media items a user consumed, grouped by lowercase name across every media kind, or restricted to one kind, one library, and a date range. A user can read only their own statistics, while an Admin can select any user with the userId route parameter; a regular user targeting another user receives the same not authorized result as a route that names no accessible user. Only an item with at least one session that counts towards statistics contributes, and each item contributes its genres once regardless of how many sessions it had, so a multi-genre item adds one to each of its genres, not one per session. The names are always lowercase and culture invariant, so a genre that is shared by a book and a track appears in one bucket. Genres of an item whose media item was deleted, or whose media library the user can no longer access, are not included, because their genres cannot be resolved, while their sessions still count in the summary.";
ExampleRequest = new GetGenreConsumptionRequest(
LibraryId: null,
MediaKind: null,
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
);
Params["userId"] = "The Id of the user whose statistics are retrieved. An Admin can name any user; a regular user can only name themselves.";
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the statistics to. Optional.");
RequestParam(request => request.MediaKind, "The kind of media to restrict the statistics to. Optional.");
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
ResponseParam<GenreConsumptionResponse>(response => response.Name, "The lowercase name of the genre.");
ResponseParam<GenreConsumptionResponse>(response => response.ConsumedItemCount, "The number of distinct media items that carry the genre and were consumed.");
ResponseParam<GenreConsumptionResponse>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media items that carry the genre, in seconds.");
Response<IReadOnlyList<GenreConsumptionResponse>>(statusCode: 200, description: "The consumption statistics of the genres of the user are returned.", contentType: "application/json",
example:
[
new GenreConsumptionResponse(
Name: "horror",
ConsumedItemCount: 3,
ConsumedDurationInSeconds: 5400
),
new GenreConsumptionResponse(
Name: "fantasy",
ConsumedItemCount: 2,
ConsumedDurationInSeconds: 7320
),
new GenreConsumptionResponse(
Name: "science fiction",
ConsumedItemCount: 1,
ConsumedDurationInSeconds: 1424.5
)
]
);
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/{userId}/consumption-statistics/genres"
},
new
{
type = "https://tools.ietf.org/html/rfc7235#section-3.1",
status = 401,
title = "Unauthorized",
detail = "The token has expired",
instance = "/api/v1/users/{userId}/consumption-statistics/genres"
}
}
);
Response(403, "The request failed because the authenticated request does not carry the identity of a user, or because the current user is neither the target user nor an Admin.", "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/{userId}/consumption-statistics/genres",
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/{userId}/consumption-statistics/genres",
errors = new Dictionary<string, string[]>
{
{
"General.Validation", new[]
{
"TargetUserIdIsInvalid",
"LibraryIdCannotBeEmpty",
"UnsupportedMediaKind",
"ConsumptionDateRangeIsInvalid"
}
}
},
traceId = "00-2470be4248a2a5a0c6f70579975a6954-b9c3ba9544a03500-00"
}
);
}
}
@@ -23,19 +23,23 @@ public class GetMostConsumedEndpointSummary : Summary<GetMostConsumedEndpoint, G
public GetMostConsumedEndpointSummary()
{
Summary = "Gets the most consumed media items of the current user.";
Description = "Gets one page of the media items the current user consumed the most, across every kind of media or restricted to one kind and one library. The items are ordered by the number of sessions that count towards statistics, then by the consumed duration, then by the last consumption date, and finally by the media item Id so the order is stable. Music and book sessions appear in the same list, and an item consumed many times appears once. An item whose sessions all fall below the counting threshold of its kind still appears in this list with a countedSessionCount of zero, but it is ordered after every item that has at least one counted session, so it normally appears on a later page. Each item carries the display details of the media item it references: the title, the collection, the creator and the cover art. An item whose media item was deleted, or whose media library the user can no longer access, is still returned, with isAvailable set to false and empty display details, so the user can see it and delete the session. The history of another user is never returned by this route.";
Description = "Gets one page of the media items the current user consumed the most, across every kind of media or restricted to one kind, one library, and a date range. The items are ordered by the number of sessions that count towards statistics, then by the consumed duration, then by the last consumption date, and finally by the media item Id so the order is stable. Music and book sessions appear in the same list, and an item consumed many times appears once. An item whose sessions all fall below the counting threshold of its kind still appears in this list with a countedSessionCount of zero, but it is ordered after every item that has at least one counted session, so it normally appears on a later page. Each item carries the display details of the media item it references: the title, the collection, the creator and the cover art. An item whose media item was deleted, or whose media library the user can no longer access, is still returned, with isAvailable set to false and empty display details, so the user can see it and delete it from the history. The history of another user is never returned by this route.";
ExampleRequest = new GetMostConsumedRequest(
LibraryId: null,
MediaKind: MediaKind.MusicTrack,
CurrentPage: 1,
PerPage: 50
PerPage: 50,
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
);
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the history to. Optional.");
RequestParam(request => request.MediaKind, "The kind of media to restrict the history to. Optional.");
RequestParam(request => request.CurrentPage, "The one based page of media items to return. Optional.");
RequestParam(request => request.PerPage, "The number of media items per page. Optional.");
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
ResponseParam<PaginatedResponse<ConsumedItemResponse>>(response => response.Data, "The most consumed media items of the requested page, ordered by counted sessions, consumed duration, and last consumption date.");
ResponseParam<PaginatedResponse<ConsumedItemResponse>>(response => response.CurrentPage, "The current page number.");
@@ -55,7 +59,7 @@ public class GetMostConsumedEndpointSummary : Summary<GetMostConsumedEndpoint, G
ResponseParam<ConsumedItemResponse>(response => response.CompletedSessionCount, "The number of consumption sessions of the media item that completed.");
ResponseParam<ConsumedItemResponse>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media item, over all of its sessions, in seconds.");
Response(statusCode: 200, description: "The most consumed media items of the current user are returned.", contentType: "application/json",
Response(200, "The most consumed media items of the current user are returned.", "application/json",
example: new PaginatedResponse<ConsumedItemResponse>
{
Data =
@@ -144,7 +148,8 @@ public class GetMostConsumedEndpointSummary : Summary<GetMostConsumedEndpoint, G
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"UnsupportedMediaKind"
"UnsupportedMediaKind",
"ConsumptionDateRangeIsInvalid"
}
}
},
@@ -23,13 +23,15 @@ public class GetUserMostConsumedEndpointSummary : Summary<GetUserMostConsumedEnd
public GetUserMostConsumedEndpointSummary()
{
Summary = "Gets the most consumed media items of a user.";
Description = "Gets one page of the media items a user consumed the most, across every kind of media or restricted to one kind and one library. A user can read only their own history, while an Admin can select any user with the userId route parameter; a regular user targeting another user receives the same not authorized result as a route that names no accessible user. The items are ordered by the number of sessions that count towards statistics, then by the consumed duration, then by the last consumption date, and finally by the media item Id so the order is stable. Music and book sessions appear in the same list, and an item consumed many times appears once. An item whose sessions all fall below the counting threshold of its kind still appears in this list with a countedSessionCount of zero, but it is ordered after every item that has at least one counted session, so it normally appears on a later page. Each item carries the display details of the media item it references: the title, the collection, the creator and the cover art. An item whose media item was deleted, or whose media library the user can no longer access, is still returned, with isAvailable set to false and empty display details, so the user can see it and delete the session.";
Description = "Gets one page of the media items a user consumed the most, across every kind of media or restricted to one kind, one library, and a date range. A user can read only their own history, while an Admin can select any user with the userId route parameter; a regular user targeting another user receives the same not authorized result as a route that names no accessible user. The items are ordered by the number of sessions that count towards statistics, then by the consumed duration, then by the last consumption date, and finally by the media item Id so the order is stable. Music and book sessions appear in the same list, and an item consumed many times appears once. An item whose sessions all fall below the counting threshold of its kind still appears in this list with a countedSessionCount of zero, but it is ordered after every item that has at least one counted session, so it normally appears on a later page. Each item carries the display details of the media item it references: the title, the collection, the creator and the cover art. An item whose media item was deleted, or whose media library the user can no longer access, is still returned, with isAvailable set to false and empty display details, so the user can see it and delete it from the history.";
ExampleRequest = new GetMostConsumedRequest(
LibraryId: null,
MediaKind: MediaKind.MusicTrack,
CurrentPage: 1,
PerPage: 50
PerPage: 50,
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
);
Params["userId"] = "The Id of the user whose history is retrieved. An Admin can name any user; a regular user can only name themselves.";
@@ -37,6 +39,8 @@ public class GetUserMostConsumedEndpointSummary : Summary<GetUserMostConsumedEnd
RequestParam(request => request.MediaKind, "The kind of media to restrict the history to. Optional.");
RequestParam(request => request.CurrentPage, "The one based page of media items to return. Optional.");
RequestParam(request => request.PerPage, "The number of media items per page. Optional.");
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
ResponseParam<PaginatedResponse<ConsumedItemResponse>>(response => response.Data, "The most consumed media items of the requested page, ordered by counted sessions, consumed duration, and last consumption date.");
ResponseParam<PaginatedResponse<ConsumedItemResponse>>(response => response.CurrentPage, "The current page number.");
@@ -56,7 +60,7 @@ public class GetUserMostConsumedEndpointSummary : Summary<GetUserMostConsumedEnd
ResponseParam<ConsumedItemResponse>(response => response.CompletedSessionCount, "The number of consumption sessions of the media item that completed.");
ResponseParam<ConsumedItemResponse>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media item, over all of its sessions, in seconds.");
Response(statusCode: 200, description: "The most consumed media items of the user are returned.", contentType: "application/json",
Response(200, "The most consumed media items of the user are returned.", "application/json",
example: new PaginatedResponse<ConsumedItemResponse>
{
Data =
@@ -146,7 +150,8 @@ public class GetUserMostConsumedEndpointSummary : Summary<GetUserMostConsumedEnd
{
"TargetUserIdIsInvalid",
"LibraryIdCannotBeEmpty",
"UnsupportedMediaKind"
"UnsupportedMediaKind",
"ConsumptionDateRangeIsInvalid"
}
}
},
@@ -23,19 +23,23 @@ public class GetRecentlyConsumedEndpointSummary : Summary<GetRecentlyConsumedEnd
public GetRecentlyConsumedEndpointSummary()
{
Summary = "Gets the recently consumed media items of the current user.";
Description = "Gets one page of the media items the current user consumed, from the most recently consumed, across every kind of media or restricted to one kind and one library. Music and book sessions appear in the same list. An item whose sessions fall below the counting threshold of its kind is still listed, because the list shows the sessions that were really recorded; countedSessionCount reports only the sessions that count towards the statistics. Each item carries the display details of the media item it references: the title, the collection, the creator and the cover art. An item whose media item was deleted, or whose media library the user can no longer access, is still returned, with isAvailable set to false and empty display details, so the user can see it and delete the session. The history of another user is never returned by this route.";
Description = "Gets one page of the media items the current user consumed, from the most recently consumed, across every kind of media or restricted to one kind, one library, and a date range. Music and book sessions appear in the same list. An item whose sessions fall below the counting threshold of its kind is still listed, because the list shows the sessions that were really recorded; countedSessionCount reports only the sessions that count towards the statistics. Each item carries the display details of the media item it references: the title, the collection, the creator and the cover art. An item whose media item was deleted, or whose media library the user can no longer access, is still returned, with isAvailable set to false and empty display details, so the user can see it and delete it from the history. The history of another user is never returned by this route.";
ExampleRequest = new GetRecentlyConsumedRequest(
LibraryId: null,
MediaKind: MediaKind.MusicTrack,
CurrentPage: 1,
PerPage: 50
PerPage: 50,
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
);
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the history to. Optional.");
RequestParam(request => request.MediaKind, "The kind of media to restrict the history to. Optional.");
RequestParam(request => request.CurrentPage, "The one based page of media items to return. Optional.");
RequestParam(request => request.PerPage, "The number of media items per page. Optional.");
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
ResponseParam<PaginatedResponse<ConsumedItemResponse>>(response => response.Data, "The recently consumed media items of the requested page, from the most recently consumed.");
ResponseParam<PaginatedResponse<ConsumedItemResponse>>(response => response.CurrentPage, "The current page number.");
@@ -55,7 +59,7 @@ public class GetRecentlyConsumedEndpointSummary : Summary<GetRecentlyConsumedEnd
ResponseParam<ConsumedItemResponse>(response => response.CompletedSessionCount, "The number of consumption sessions of the media item that completed.");
ResponseParam<ConsumedItemResponse>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media item, over all of its sessions, in seconds.");
Response(statusCode: 200, description: "The recently consumed media items of the current user are returned.", contentType: "application/json",
Response(200, "The recently consumed media items of the current user are returned.", "application/json",
example: new PaginatedResponse<ConsumedItemResponse>
{
Data =
@@ -144,7 +148,8 @@ public class GetRecentlyConsumedEndpointSummary : Summary<GetRecentlyConsumedEnd
"General.Validation", new[]
{
"LibraryIdCannotBeEmpty",
"UnsupportedMediaKind"
"UnsupportedMediaKind",
"ConsumptionDateRangeIsInvalid"
}
}
},
@@ -23,13 +23,15 @@ public class GetUserRecentlyConsumedEndpointSummary : Summary<GetUserRecentlyCon
public GetUserRecentlyConsumedEndpointSummary()
{
Summary = "Gets the recently consumed media items of a user.";
Description = "Gets one page of the media items a user consumed, from the most recently consumed, across every kind of media or restricted to one kind and one library. A user can read only their own history, while an Admin can select any user with the userId route parameter; a regular user targeting another user receives the same not authorized result as a route that names no accessible user. Music and book sessions appear in the same list. An item whose sessions fall below the counting threshold of its kind is still listed, because the list shows the sessions that were really recorded; countedSessionCount reports only the sessions that count towards the statistics. Each item carries the display details of the media item it references: the title, the collection, the creator and the cover art. An item whose media item was deleted, or whose media library the user can no longer access, is still returned, with isAvailable set to false and empty display details, so the user can see it and delete the session.";
Description = "Gets one page of the media items a user consumed, from the most recently consumed, across every kind of media or restricted to one kind, one library, and a date range. A user can read only their own history, while an Admin can select any user with the userId route parameter; a regular user targeting another user receives the same not authorized result as a route that names no accessible user. Music and book sessions appear in the same list. An item whose sessions fall below the counting threshold of its kind is still listed, because the list shows the sessions that were really recorded; countedSessionCount reports only the sessions that count towards the statistics. Each item carries the display details of the media item it references: the title, the collection, the creator and the cover art. An item whose media item was deleted, or whose media library the user can no longer access, is still returned, with isAvailable set to false and empty display details, so the user can see it and delete it from the history.";
ExampleRequest = new GetRecentlyConsumedRequest(
LibraryId: null,
MediaKind: MediaKind.MusicTrack,
CurrentPage: 1,
PerPage: 50
PerPage: 50,
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
);
Params["userId"] = "The Id of the user whose history is retrieved. An Admin can name any user; a regular user can only name themselves.";
@@ -37,6 +39,8 @@ public class GetUserRecentlyConsumedEndpointSummary : Summary<GetUserRecentlyCon
RequestParam(request => request.MediaKind, "The kind of media to restrict the history to. Optional.");
RequestParam(request => request.CurrentPage, "The one based page of media items to return. Optional.");
RequestParam(request => request.PerPage, "The number of media items per page. Optional.");
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
ResponseParam<PaginatedResponse<ConsumedItemResponse>>(response => response.Data, "The recently consumed media items of the requested page, from the most recently consumed.");
ResponseParam<PaginatedResponse<ConsumedItemResponse>>(response => response.CurrentPage, "The current page number.");
@@ -56,7 +60,7 @@ public class GetUserRecentlyConsumedEndpointSummary : Summary<GetUserRecentlyCon
ResponseParam<ConsumedItemResponse>(response => response.CompletedSessionCount, "The number of consumption sessions of the media item that completed.");
ResponseParam<ConsumedItemResponse>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media item, over all of its sessions, in seconds.");
Response(statusCode: 200, description: "The recently consumed media items of the user are returned.", contentType: "application/json",
Response(200, "The recently consumed media items of the user are returned.", "application/json",
example: new PaginatedResponse<ConsumedItemResponse>
{
Data =
@@ -146,7 +150,8 @@ public class GetUserRecentlyConsumedEndpointSummary : Summary<GetUserRecentlyCon
{
"TargetUserIdIsInvalid",
"LibraryIdCannotBeEmpty",
"UnsupportedMediaKind"
"UnsupportedMediaKind",
"ConsumptionDateRangeIsInvalid"
}
}
},
@@ -46,7 +46,7 @@ public class GetTagConsumptionEndpoint : BaseEndpoint<GetTagConsumptionRequest,
}
/// <summary>
/// Gets the consumption statistics of the tags and genres of the current user.
/// Gets the consumption statistics of the tags of the current user.
/// </summary>
/// <param name="request">The request containing the optional filters and the date range.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
@@ -2,7 +2,6 @@
using FastEndpoints;
using Lumina.Contracts.Requests.MediaConsumption;
using Lumina.Contracts.Responses.MediaConsumption;
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -21,46 +20,40 @@ public class GetTagConsumptionEndpointSummary : Summary<GetTagConsumptionEndpoin
/// </summary>
public GetTagConsumptionEndpointSummary()
{
Summary = "Gets the consumption statistics of the tags and genres of the current user.";
Description = "Gets the tags and genres carried by the media items the current user consumed, grouped by lowercase name across every media kind, or restricted to one kind, one library, one term kind, and a date range. Only an item with at least one session that counts towards statistics contributes, and each item contributes its terms once regardless of how many sessions it had, so a multi-genre item adds one to each of its genres, not one per session. The names are always lowercase and culture invariant, so a tag or genre that is shared by a book and a track appears in one bucket. Tags and genres of an item whose media item was deleted, or whose media library the user can no longer access, are not included, because their terms cannot be resolved, while their sessions still count in the summary. The statistics of another user are never returned by this route.";
Summary = "Gets the consumption statistics of the tags of the current user.";
Description = "Gets the tags carried by the media items the current user consumed, grouped by lowercase name across every media kind, or restricted to one kind, one library, and a date range. Only an item with at least one session that counts towards statistics contributes, and each item contributes its tags once regardless of how many sessions it had, so a multi-tag item adds one to each of its tags, not one per session. The names are always lowercase and culture invariant, so a tag that is shared by a book and a track appears in one bucket. Tags of an item whose media item was deleted, or whose media library the user can no longer access, are not included, because their tags cannot be resolved, while their sessions still count in the summary. The statistics of another user are never returned by this route.";
ExampleRequest = new GetTagConsumptionRequest(
LibraryId: null,
MediaKind: null,
TagKind: null,
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
);
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the statistics to. Optional.");
RequestParam(request => request.MediaKind, "The kind of media to restrict the statistics to. Optional.");
RequestParam(request => request.TagKind, "Whether to return genres or tags. Optional.");
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
ResponseParam<TagConsumptionResponse>(response => response.Name, "The lowercase name of the tag or genre.");
ResponseParam<TagConsumptionResponse>(response => response.TagKind, "Whether the entry is a genre or a tag.");
ResponseParam<TagConsumptionResponse>(response => response.ConsumedItemCount, "The number of distinct media items that carry the term and were consumed.");
ResponseParam<TagConsumptionResponse>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media items that carry the term, in seconds.");
ResponseParam<TagConsumptionResponse>(response => response.Name, "The lowercase name of the tag.");
ResponseParam<TagConsumptionResponse>(response => response.ConsumedItemCount, "The number of distinct media items that carry the tag and were consumed.");
ResponseParam<TagConsumptionResponse>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media items that carry the tag, in seconds.");
Response<IReadOnlyList<TagConsumptionResponse>>(statusCode: 200, description: "The consumption statistics of the tags and genres of the current user are returned.", contentType: "application/json",
Response<IReadOnlyList<TagConsumptionResponse>>(statusCode: 200, description: "The consumption statistics of the tags of the current user are returned.", contentType: "application/json",
example:
[
new TagConsumptionResponse(
Name: "horror",
TagKind: TagKind.Genre,
Name: "favourite",
ConsumedItemCount: 3,
ConsumedDurationInSeconds: 5400
),
new TagConsumptionResponse(
Name: "fantasy",
TagKind: TagKind.Genre,
Name: "book-club",
ConsumedItemCount: 2,
ConsumedDurationInSeconds: 7320
),
new TagConsumptionResponse(
Name: "favourite",
TagKind: TagKind.Tag,
Name: "comfort-read",
ConsumedItemCount: 1,
ConsumedDurationInSeconds: 1424.5
)
@@ -116,7 +109,6 @@ public class GetTagConsumptionEndpointSummary : Summary<GetTagConsumptionEndpoin
{
"LibraryIdCannotBeEmpty",
"UnsupportedMediaKind",
"TagKindIsInvalid",
"ConsumptionDateRangeIsInvalid"
}
}
@@ -43,7 +43,7 @@ public class GetUserTagConsumptionEndpoint : BaseEndpoint<GetTagConsumptionReque
}
/// <summary>
/// Gets the consumption statistics of the tags and genres of a user.
/// Gets the consumption statistics of the tags of a user.
/// </summary>
/// <param name="request">The request containing the optional filters and the date range.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
@@ -2,7 +2,6 @@
using FastEndpoints;
using Lumina.Contracts.Requests.MediaConsumption;
using Lumina.Contracts.Responses.MediaConsumption;
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -21,13 +20,12 @@ public class GetUserTagConsumptionEndpointSummary : Summary<GetUserTagConsumptio
/// </summary>
public GetUserTagConsumptionEndpointSummary()
{
Summary = "Gets the consumption statistics of the tags and genres of a user.";
Description = "Gets the tags and genres carried by the media items a user consumed, grouped by lowercase name across every media kind, or restricted to one kind, one library, one term kind, and a date range. A user can read only their own statistics, while an Admin can select any user with the userId route parameter; a regular user targeting another user receives the same not authorized result as a route that names no accessible user. Only an item with at least one session that counts towards statistics contributes, and each item contributes its terms once regardless of how many sessions it had, so a multi-genre item adds one to each of its genres, not one per session. The names are always lowercase and culture invariant, so a tag or genre that is shared by a book and a track appears in one bucket. Tags and genres of an item whose media item was deleted, or whose media library the user can no longer access, are not included, because their terms cannot be resolved, while their sessions still count in the summary.";
Summary = "Gets the consumption statistics of the tags of a user.";
Description = "Gets the tags carried by the media items a user consumed, grouped by lowercase name across every media kind, or restricted to one kind, one library, and a date range. A user can read only their own statistics, while an Admin can select any user with the userId route parameter; a regular user targeting another user receives the same not authorized result as a route that names no accessible user. Only an item with at least one session that counts towards statistics contributes, and each item contributes its tags once regardless of how many sessions it had, so a multi-tag item adds one to each of its tags, not one per session. The names are always lowercase and culture invariant, so a tag that is shared by a book and a track appears in one bucket. Tags of an item whose media item was deleted, or whose media library the user can no longer access, are not included, because their tags cannot be resolved, while their sessions still count in the summary.";
ExampleRequest = new GetTagConsumptionRequest(
LibraryId: null,
MediaKind: null,
TagKind: null,
FromUtc: new DateTime(2026, 10, 1, 0, 0, 0, DateTimeKind.Utc),
ToUtc: new DateTime(2026, 10, 31, 23, 59, 59, DateTimeKind.Utc)
);
@@ -35,33 +33,28 @@ public class GetUserTagConsumptionEndpointSummary : Summary<GetUserTagConsumptio
Params["userId"] = "The Id of the user whose statistics are retrieved. An Admin can name any user; a regular user can only name themselves.";
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the statistics to. Optional.");
RequestParam(request => request.MediaKind, "The kind of media to restrict the statistics to. Optional.");
RequestParam(request => request.TagKind, "Whether to return genres or tags. Optional.");
RequestParam(request => request.FromUtc, "The inclusive start of the date range. Optional.");
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
ResponseParam<TagConsumptionResponse>(response => response.Name, "The lowercase name of the tag or genre.");
ResponseParam<TagConsumptionResponse>(response => response.TagKind, "Whether the entry is a genre or a tag.");
ResponseParam<TagConsumptionResponse>(response => response.ConsumedItemCount, "The number of distinct media items that carry the term and were consumed.");
ResponseParam<TagConsumptionResponse>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media items that carry the term, in seconds.");
ResponseParam<TagConsumptionResponse>(response => response.Name, "The lowercase name of the tag.");
ResponseParam<TagConsumptionResponse>(response => response.ConsumedItemCount, "The number of distinct media items that carry the tag and were consumed.");
ResponseParam<TagConsumptionResponse>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media items that carry the tag, in seconds.");
Response<IReadOnlyList<TagConsumptionResponse>>(statusCode: 200, description: "The consumption statistics of the tags and genres of the user are returned.", contentType: "application/json",
Response<IReadOnlyList<TagConsumptionResponse>>(statusCode: 200, description: "The consumption statistics of the tags of the user are returned.", contentType: "application/json",
example:
[
new TagConsumptionResponse(
Name: "horror",
TagKind: TagKind.Genre,
Name: "favourite",
ConsumedItemCount: 3,
ConsumedDurationInSeconds: 5400
),
new TagConsumptionResponse(
Name: "fantasy",
TagKind: TagKind.Genre,
Name: "book-club",
ConsumedItemCount: 2,
ConsumedDurationInSeconds: 7320
),
new TagConsumptionResponse(
Name: "favourite",
TagKind: TagKind.Tag,
Name: "comfort-read",
ConsumedItemCount: 1,
ConsumedDurationInSeconds: 1424.5
)
@@ -118,7 +111,6 @@ public class GetUserTagConsumptionEndpointSummary : Summary<GetUserTagConsumptio
"TargetUserIdIsInvalid",
"LibraryIdCannotBeEmpty",
"UnsupportedMediaKind",
"TagKindIsInvalid",
"ConsumptionDateRangeIsInvalid"
}
}