mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Adds the media-neutral library statistics page and separates tags from genres
This commit is contained in:
1 parent
a61fbf407c
commit
00d7eff777
118 files changed
+6132
-1154
No files matched your search
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of a genre, grouped across media kinds.
|
||||
/// </summary>
|
||||
/// <param name="Name">The lowercase name of the genre.</param>
|
||||
/// <param name="ConsumedItemCount">The number of distinct media items that carry the genre and were consumed.</param>
|
||||
/// <param name="ConsumedDurationMilliseconds">The active duration consumed in the media items that carry the genre, in milliseconds.</param>
|
||||
[DebuggerDisplay("Name: {Name}; ConsumedItemCount: {ConsumedItemCount}")]
|
||||
public sealed record GenreConsumptionDto(
|
||||
string Name,
|
||||
int ConsumedItemCount,
|
||||
long ConsumedDurationMilliseconds
|
||||
);
|
||||
@@ -1,21 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of a tag or genre, grouped across media kinds.
|
||||
/// Data transfer object for the consumption statistics of a tag, grouped across media kinds.
|
||||
/// </summary>
|
||||
/// <param name="Name">The lowercase name of the tag or genre.</param>
|
||||
/// <param name="TagKind">Whether the entry is a genre or a tag.</param>
|
||||
/// <param name="ConsumedItemCount">The number of distinct media items that carry the term and were consumed.</param>
|
||||
/// <param name="ConsumedDurationMilliseconds">The active duration consumed in the media items that carry the term, in milliseconds.</param>
|
||||
[DebuggerDisplay("TagKind: {TagKind}; Name: {Name}; ConsumedItemCount: {ConsumedItemCount}")]
|
||||
/// <param name="Name">The lowercase name of the tag.</param>
|
||||
/// <param name="ConsumedItemCount">The number of distinct media items that carry the tag and were consumed.</param>
|
||||
/// <param name="ConsumedDurationMilliseconds">The active duration consumed in the media items that carry the tag, in milliseconds.</param>
|
||||
[DebuggerDisplay("Name: {Name}; ConsumedItemCount: {ConsumedItemCount}")]
|
||||
public sealed record TagConsumptionDto(
|
||||
string Name,
|
||||
TagKind TagKind,
|
||||
int ConsumedItemCount,
|
||||
long ConsumedDurationMilliseconds
|
||||
);
|
||||
+12
@@ -3,6 +3,7 @@ using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -49,6 +50,17 @@ public interface IMediaConsumptionRecordRepository : IRepository<MediaConsumptio
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful deletion, or an error.</returns>
|
||||
Task<Result<Deleted>> DeleteForUserAsync(Guid id, Guid userId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes every consumption record of a media item of the user identified by <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the user whose consumption records are deleted.</param>
|
||||
/// <param name="mediaKind">The kind of the consumed media item.</param>
|
||||
/// <param name="mediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="libraryId">The Id of the media library that contains the media item.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful deletion, or an error.</returns>
|
||||
Task<Result<Deleted>> DeleteAllByMediaItemIdForUserAsync(Guid userId, MediaKind mediaKind, Guid mediaItemId, Guid libraryId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes every consumption record of the user identified by <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GenreConsumptionDto"/>.
|
||||
/// </summary>
|
||||
public static class GenreConsumptionDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to <see cref="GenreConsumptionResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data transfer object to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static GenreConsumptionResponse ToResponse(this GenreConsumptionDto data)
|
||||
{
|
||||
return new GenreConsumptionResponse(
|
||||
data.Name,
|
||||
data.ConsumedItemCount,
|
||||
data.ConsumedDurationMilliseconds.ToClampedTimeSpan().TotalSeconds
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to a collection of <see cref="GenreConsumptionResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data transfer objects to be converted.</param>
|
||||
/// <returns>The converted responses.</returns>
|
||||
public static IReadOnlyList<GenreConsumptionResponse> ToResponses(this IReadOnlyList<GenreConsumptionDto> data)
|
||||
{
|
||||
return [.. data.Select(item => item.ToResponse())];
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Core.MediaConsumption.Queries.GetGenreConsumption;
|
||||
using Lumina.Contracts.Requests.MediaConsumption;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="GetGenreConsumptionRequest"/>.
|
||||
/// </summary>
|
||||
public static class GetGenreConsumptionRequestMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="request"/> to <see cref="GetGenreConsumptionQuery"/>.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to be converted.</param>
|
||||
/// <param name="targetUserId">The Id of the user whose statistics are retrieved, taken from the route, or <see langword="null"/> for the current user.</param>
|
||||
/// <returns>The converted query.</returns>
|
||||
public static GetGenreConsumptionQuery ToQuery(this GetGenreConsumptionRequest request, string? targetUserId)
|
||||
{
|
||||
return new GetGenreConsumptionQuery(
|
||||
targetUserId,
|
||||
request.LibraryId,
|
||||
request.MediaKind,
|
||||
request.FromUtc,
|
||||
request.ToUtc
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -27,6 +27,6 @@ public static class GetMostConsumedRequestMapping
|
||||
PerPage = request.PerPage ?? 50
|
||||
};
|
||||
|
||||
return new GetMostConsumedQuery(targetUserId, request.LibraryId, request.MediaKind, paginationData);
|
||||
return new GetMostConsumedQuery(targetUserId, request.LibraryId, request.MediaKind, request.FromUtc, request.ToUtc, paginationData);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -27,6 +27,6 @@ public static class GetRecentlyConsumedRequestMapping
|
||||
PerPage = request.PerPage ?? 50
|
||||
};
|
||||
|
||||
return new GetRecentlyConsumedQuery(targetUserId, request.LibraryId, request.MediaKind, paginationData);
|
||||
return new GetRecentlyConsumedQuery(targetUserId, request.LibraryId, request.MediaKind, request.FromUtc, request.ToUtc, paginationData);
|
||||
}
|
||||
}
|
||||
-1
@@ -22,7 +22,6 @@ public static class GetTagConsumptionRequestMapping
|
||||
targetUserId,
|
||||
request.LibraryId,
|
||||
request.MediaKind,
|
||||
request.TagKind,
|
||||
request.FromUtc,
|
||||
request.ToUtc
|
||||
);
|
||||
|
||||
@@ -22,7 +22,6 @@ public static class TagConsumptionDtoMapping
|
||||
{
|
||||
return new TagConsumptionResponse(
|
||||
data.Name,
|
||||
data.TagKind,
|
||||
data.ConsumedItemCount,
|
||||
data.ConsumedDurationMilliseconds.ToClampedTimeSpan().TotalSeconds
|
||||
);
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Commands.DeleteConsumptionItemHistory;
|
||||
|
||||
/// <summary>
|
||||
/// Command for deleting every consumption record of a media item of a user.
|
||||
/// </summary>
|
||||
/// <param name="TargetUserId">The Id of the user the records must belong to, or <see langword="null"/> for the current user.</param>
|
||||
/// <param name="MediaKind">The kind of the consumed media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the media item.</param>
|
||||
[DebuggerDisplay("TargetUserId: {TargetUserId}; MediaKind: {MediaKind}; MediaItemId: {MediaItemId}")]
|
||||
public record DeleteConsumptionItemHistoryCommand(
|
||||
string? TargetUserId,
|
||||
MediaKind MediaKind,
|
||||
Guid MediaItemId,
|
||||
Guid LibraryId
|
||||
) : ICommand;
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.ConsumptionActivity;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Commands.DeleteConsumptionItemHistory;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the command to delete every consumption record of a media item of a user.
|
||||
/// </summary>
|
||||
public class DeleteConsumptionItemHistoryCommandHandler : ICommandHandler<DeleteConsumptionItemHistoryCommand, Result<Deleted>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IValidator<DeleteConsumptionItemHistoryCommand> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteConsumptionItemHistoryCommandHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public DeleteConsumptionItemHistoryCommandHandler(
|
||||
IUnitOfWork unitOfWork,
|
||||
ICurrentUserService currentUserService,
|
||||
IAuthorizationService authorizationService,
|
||||
IValidator<DeleteConsumptionItemHistoryCommand> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_currentUserService = currentUserService;
|
||||
_authorizationService = authorizationService;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the command to delete every consumption record of a media item of a user.
|
||||
/// </summary>
|
||||
/// <param name="command">The command to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful deletion, or an error message.</returns>
|
||||
public async Task<Result<Deleted>> HandleAsync(DeleteConsumptionItemHistoryCommand command, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(command);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// The target defaults to the current user, and the access policy is the only place that decides whether the caller may act on it.
|
||||
Guid targetUserId = command.TargetUserId is null ? userId : Guid.Parse(command.TargetUserId);
|
||||
bool canAccessTarget = await _authorizationService.EvaluatePolicyAsync<IConsumptionActivityAccessPolicy>(
|
||||
userId, new ConsumptionActivityAccessPolicyContext(targetUserId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessTarget)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
// The deletion covers every recorded session of the item in its library, not only the sessions of a date range, so the row
|
||||
// disappears from the history consistently with clearing the whole history.
|
||||
Result<Deleted> deleteResult = await _unitOfWork.MediaConsumptionRecordRepository
|
||||
.DeleteAllByMediaItemIdForUserAsync(targetUserId, command.MediaKind, command.MediaItemId, command.LibraryId, cancellationToken).ConfigureAwait(false);
|
||||
if (deleteResult.IsFailure)
|
||||
return deleteResult.Errors;
|
||||
|
||||
Result<Success> saveChangesResult = await _unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
return saveChangesResult.Errors;
|
||||
|
||||
return Result.Deleted;
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Commands.DeleteConsumptionItemHistory;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="DeleteConsumptionItemHistoryCommand"/>.
|
||||
/// </summary>
|
||||
public class DeleteConsumptionItemHistoryCommandValidator : AbstractValidator<DeleteConsumptionItemHistoryCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteConsumptionItemHistoryCommandValidator"/> class.
|
||||
/// </summary>
|
||||
public DeleteConsumptionItemHistoryCommandValidator()
|
||||
{
|
||||
// The target defaults to the current user, so an absent target is valid, but a supplied one must be a real user Id.
|
||||
RuleFor(command => command.TargetUserId)
|
||||
.Must(targetUserId => targetUserId is null ||
|
||||
(Guid.TryParse(targetUserId, out Guid parsedTargetUserId) && parsedTargetUserId != Guid.Empty))
|
||||
.WithError(Errors.MediaConsumption.TargetUserIdIsInvalid);
|
||||
|
||||
RuleFor(command => command.MediaKind)
|
||||
.IsInEnum()
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
RuleFor(command => command.MediaKind)
|
||||
.Must(mediaKind => mediaKind != MediaKind.None)
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
RuleFor(command => command.MediaItemId)
|
||||
.Must(mediaItemId => mediaItemId != Guid.Empty)
|
||||
.WithError(Errors.MediaConsumption.MediaItemIdCannotBeEmpty);
|
||||
|
||||
RuleFor(command => command.LibraryId)
|
||||
.Must(libraryId => libraryId != Guid.Empty)
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Queries.GetGenreConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Query for getting the consumption statistics of the genres of a user.
|
||||
/// </summary>
|
||||
/// <param name="TargetUserId">The Id of the user whose statistics are retrieved, or <see langword="null"/> for the current user.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to, or <see langword="null"/> for every library.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, or <see langword="null"/> when the range has no end.</param>
|
||||
[DebuggerDisplay("TargetUserId: {TargetUserId}; MediaKind: {MediaKind}")]
|
||||
public record GetGenreConsumptionQuery(
|
||||
string? TargetUserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
) : IQuery;
|
||||
+206
@@ -0,0 +1,206 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.ConsumptionActivity;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization.Policies.LibraryOwnership;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Queries.GetGenreConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the consumption statistics of the genres of a user.
|
||||
/// </summary>
|
||||
public class GetGenreConsumptionQueryHandler : IQueryHandler<GetGenreConsumptionQuery, Result<IReadOnlyList<GenreConsumptionResponse>>>
|
||||
{
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IValidator<GetGenreConsumptionQuery> _validator;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetGenreConsumptionQueryHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="unitOfWork">Injected unit of work for interacting with the data access layer repositories.</param>
|
||||
/// <param name="currentUserService">Injected service to retrieve the current user information.</param>
|
||||
/// <param name="authorizationService">Injected service for authorization related functionality.</param>
|
||||
/// <param name="validator">Injected validator for application validation rules.</param>
|
||||
public GetGenreConsumptionQueryHandler(
|
||||
IUnitOfWork unitOfWork,
|
||||
ICurrentUserService currentUserService,
|
||||
IAuthorizationService authorizationService,
|
||||
IValidator<GetGenreConsumptionQuery> validator)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_currentUserService = currentUserService;
|
||||
_authorizationService = authorizationService;
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the query to get the consumption statistics of the genres of a user.
|
||||
/// </summary>
|
||||
/// <param name="query">The query to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the requested genre statistics, or an error message.
|
||||
/// </returns>
|
||||
public async Task<Result<IReadOnlyList<GenreConsumptionResponse>>> HandleAsync(GetGenreConsumptionQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
List<Error> validationResult = _validator.Validate(query);
|
||||
if (validationResult.Count > 0)
|
||||
return validationResult;
|
||||
|
||||
// An authenticated request must always carry a user identity.
|
||||
Guid? currentUserId = _currentUserService.UserId;
|
||||
if (currentUserId is null)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
Guid userId = currentUserId.Value;
|
||||
|
||||
// The target defaults to the current user, and the access policy is the only place that decides whether the caller may read it.
|
||||
Guid targetUserId = query.TargetUserId is null ? userId : Guid.Parse(query.TargetUserId);
|
||||
bool canAccessTarget = await _authorizationService.EvaluatePolicyAsync<IConsumptionActivityAccessPolicy>(
|
||||
userId, new ConsumptionActivityAccessPolicyContext(targetUserId), cancellationToken).ConfigureAwait(false);
|
||||
if (!canAccessTarget)
|
||||
return ApplicationErrors.Authorization.NotAuthorized;
|
||||
|
||||
Guid? libraryId = query.LibraryId is null ? null : Guid.Parse(query.LibraryId);
|
||||
|
||||
Result<IReadOnlyList<MediaConsumptionRecordEntity>> getRecordsResult = await _unitOfWork.ConsumptionStatisticsRepository
|
||||
.GetForUserAsync(targetUserId, libraryId, query.MediaKind, query.FromUtc, query.ToUtc, cancellationToken).ConfigureAwait(false);
|
||||
if (getRecordsResult.IsFailure)
|
||||
return getRecordsResult.Errors;
|
||||
|
||||
// The access decision only needs the library Id that the records already carry, so it is made once per distinct library before any genre is
|
||||
// loaded. Genres of a library the caller cannot access are never read.
|
||||
Dictionary<Guid, bool> libraryAccess = [];
|
||||
foreach (Guid recordLibraryId in getRecordsResult.Value.Select(record => record.LibraryId).Distinct())
|
||||
libraryAccess[recordLibraryId] = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
userId, new LibraryOwnershipPolicyContext(recordLibraryId), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// Only the distinct item Ids of each kind in accessible libraries are read, through the catalogue repositories, in bounded chunks.
|
||||
List<Guid> trackIds = [.. getRecordsResult.Value
|
||||
.Where(record => record.MediaKind == MediaKind.MusicTrack && libraryAccess[record.LibraryId])
|
||||
.Select(record => record.MediaItemId)
|
||||
.Distinct()];
|
||||
List<TrackEntity> tracks = [];
|
||||
if (trackIds.Count > 0)
|
||||
{
|
||||
Result<IReadOnlyList<TrackEntity>> getTracksResult = await _unitOfWork.TrackRepository
|
||||
.GetByIdsAsync(trackIds, shouldIncludeNavigationProperties: true, cancellationToken).ConfigureAwait(false);
|
||||
if (getTracksResult.IsFailure)
|
||||
return getTracksResult.Errors;
|
||||
tracks = [.. getTracksResult.Value];
|
||||
}
|
||||
|
||||
List<Guid> bookIds = [.. getRecordsResult.Value
|
||||
.Where(record => record.MediaKind == MediaKind.Book && libraryAccess[record.LibraryId])
|
||||
.Select(record => record.MediaItemId)
|
||||
.Distinct()];
|
||||
List<BookEntity> books = [];
|
||||
if (bookIds.Count > 0)
|
||||
{
|
||||
Result<IReadOnlyList<BookEntity>> getBooksResult = await _unitOfWork.BookRepository
|
||||
.GetByIdsAsync(bookIds, shouldIncludeNavigationProperties: true, cancellationToken).ConfigureAwait(false);
|
||||
if (getBooksResult.IsFailure)
|
||||
return getBooksResult.Errors;
|
||||
books = [.. getBooksResult.Value];
|
||||
}
|
||||
|
||||
Dictionary<(MediaKind MediaKind, Guid MediaItemId, Guid LibraryId), List<string>> genreNamesByItem = [];
|
||||
foreach (TrackEntity track in tracks)
|
||||
{
|
||||
List<string> itemGenres = [.. track.Genres.Select(genre => genre.Name).OfType<string>()];
|
||||
if (itemGenres.Count > 0)
|
||||
genreNamesByItem[(MediaKind.MusicTrack, track.Id, track.LibraryId)] = itemGenres;
|
||||
}
|
||||
foreach (BookEntity book in books)
|
||||
{
|
||||
List<string> itemGenres = [.. book.Genres.Select(genre => genre.Name).OfType<string>()];
|
||||
if (itemGenres.Count > 0)
|
||||
genreNamesByItem[(MediaKind.Book, book.Id, book.LibraryId)] = itemGenres;
|
||||
}
|
||||
|
||||
// The records are aggregated to one row per item and library first, so an item with several sessions contributes its genres once, not once per
|
||||
// session. The library is part of the key because the item is resolved in its current library, and a record from another library must not
|
||||
// borrow the genres or the access decision of the current one. An item that moved libraries after consumption is therefore excluded from the
|
||||
// breakdown, matching the history lists that blank display data when the record and item libraries disagree.
|
||||
Dictionary<string, (int ConsumedItemCount, long ConsumedDurationMilliseconds)> genres = [];
|
||||
foreach (IGrouping<(MediaKind MediaKind, Guid MediaItemId, Guid LibraryId), MediaConsumptionRecordEntity> itemGroup in getRecordsResult.Value
|
||||
.GroupBy(record => (record.MediaKind, record.MediaItemId, record.LibraryId)))
|
||||
{
|
||||
if (!libraryAccess[itemGroup.Key.LibraryId])
|
||||
continue;
|
||||
if (!genreNamesByItem.TryGetValue((itemGroup.Key.MediaKind, itemGroup.Key.MediaItemId, itemGroup.Key.LibraryId), out List<string>? itemGenres) ||
|
||||
itemGenres.Count == 0)
|
||||
continue;
|
||||
|
||||
// The breakdown mirrors the statistics, so an item whose sessions all fall below the counting threshold of their media kind does not
|
||||
// contribute its genres or its duration to the breakdown.
|
||||
Optional<MediaConsumptionRule> ruleResult = MediaConsumptionRule.For(itemGroup.Key.MediaKind);
|
||||
if (!ruleResult.HasValue)
|
||||
continue;
|
||||
bool hasCountedSession = itemGroup.Any(record => ruleResult.Value.Counts(
|
||||
record.Status,
|
||||
record.ConsumedDurationMilliseconds.ToClampedTimeSpan(),
|
||||
record.ConsecutivePagesRead));
|
||||
if (!hasCountedSession)
|
||||
continue;
|
||||
|
||||
long consumedDurationMilliseconds = itemGroup.Sum(record => record.ConsumedDurationMilliseconds);
|
||||
AddGenres(genres, itemGenres, consumedDurationMilliseconds);
|
||||
}
|
||||
|
||||
List<GenreConsumptionDto> genreConsumptions = [.. genres
|
||||
.Select(genre => new GenreConsumptionDto(
|
||||
genre.Key,
|
||||
genre.Value.ConsumedItemCount,
|
||||
genre.Value.ConsumedDurationMilliseconds))
|
||||
.OrderByDescending(genreConsumption => genreConsumption.ConsumedItemCount)
|
||||
.ThenByDescending(genreConsumption => genreConsumption.ConsumedDurationMilliseconds)
|
||||
.ThenBy(genreConsumption => genreConsumption.Name)];
|
||||
|
||||
return Result.From(genreConsumptions.ToResponses());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the lowercase <paramref name="names"/> of one item to the accumulated <paramref name="genres"/>.
|
||||
/// </summary>
|
||||
/// <param name="genres">The accumulated genres, keyed by lowercase name.</param>
|
||||
/// <param name="names">The genre names carried by the item.</param>
|
||||
/// <param name="consumedDurationMilliseconds">The duration consumed in the item, over all of its sessions, in milliseconds.</param>
|
||||
private static void AddGenres(
|
||||
Dictionary<string, (int ConsumedItemCount, long ConsumedDurationMilliseconds)> genres,
|
||||
List<string> names,
|
||||
long consumedDurationMilliseconds)
|
||||
{
|
||||
// The item is aggregated to one row, so each distinct lowercase name of the item is counted once, regardless of how many sessions it had.
|
||||
foreach (string name in names.Select(name => name.Trim().ToLowerInvariant()).Distinct())
|
||||
{
|
||||
if (name.Length == 0)
|
||||
continue;
|
||||
if (genres.TryGetValue(name, out (int ConsumedItemCount, long ConsumedDurationMilliseconds) current))
|
||||
genres[name] = (current.ConsumedItemCount + 1, current.ConsumedDurationMilliseconds + consumedDurationMilliseconds);
|
||||
else
|
||||
genres[name] = (1, consumedDurationMilliseconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Core.MediaConsumption.Queries.GetGenreConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Validates the needed validation rules for <see cref="GetGenreConsumptionQuery"/>.
|
||||
/// </summary>
|
||||
public class GetGenreConsumptionQueryValidator : AbstractValidator<GetGenreConsumptionQuery>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetGenreConsumptionQueryValidator"/> class.
|
||||
/// </summary>
|
||||
public GetGenreConsumptionQueryValidator()
|
||||
{
|
||||
// The target defaults to the current user, so an absent target is valid, but a supplied one must be a real user Id.
|
||||
RuleFor(query => query.TargetUserId)
|
||||
.Must(targetUserId => targetUserId is null ||
|
||||
(Guid.TryParse(targetUserId, out Guid parsedTargetUserId) && parsedTargetUserId != Guid.Empty))
|
||||
.WithError(Errors.MediaConsumption.TargetUserIdIsInvalid);
|
||||
|
||||
RuleFor(query => query.LibraryId)
|
||||
.Must(libraryId => libraryId is null ||
|
||||
(Guid.TryParse(libraryId, out Guid parsedLibraryId) && parsedLibraryId != Guid.Empty))
|
||||
.WithError(Errors.Library.LibraryIdCannotBeEmpty);
|
||||
|
||||
RuleFor(query => query.MediaKind)
|
||||
.IsInEnum()
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind)
|
||||
.When(query => query.MediaKind is not null);
|
||||
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null || mediaKind != MediaKind.None)
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// An inverted range would silently return no records, so it is rejected as an invalid request instead.
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) => !fromUtc.HasValue || !query.ToUtc.HasValue || fromUtc.Value <= query.ToUtc.Value)
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
}
|
||||
+5
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -13,11 +14,15 @@ namespace Lumina.Application.Core.MediaConsumption.Queries.GetMostConsumed;
|
||||
/// <param name="TargetUserId">The Id of the user whose history is retrieved, or <see langword="null"/> for the current user.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the history to, or <see langword="null"/> for every library.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the history to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, or <see langword="null"/> when the range has no end.</param>
|
||||
/// <param name="PaginationData">The object containing the requested pagination data. When <see langword="null"/>, every matching item is returned; when present, its requested page is returned.</param>
|
||||
[DebuggerDisplay("TargetUserId: {TargetUserId}; MediaKind: {MediaKind}")]
|
||||
public record GetMostConsumedQuery(
|
||||
string? TargetUserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc,
|
||||
PaginationDataDto? PaginationData
|
||||
) : IQuery;
|
||||
+1
-1
@@ -93,7 +93,7 @@ public class GetMostConsumedQueryHandler : IQueryHandler<GetMostConsumedQuery, R
|
||||
Guid? libraryId = query.LibraryId is null ? null : Guid.Parse(query.LibraryId);
|
||||
|
||||
Result<IReadOnlyList<MediaConsumptionRecordEntity>> getRecordsResult = await _unitOfWork.ConsumptionStatisticsRepository
|
||||
.GetForUserAsync(targetUserId, libraryId, query.MediaKind, fromUtc: null, toUtc: null, cancellationToken).ConfigureAwait(false);
|
||||
.GetForUserAsync(targetUserId, libraryId, query.MediaKind, query.FromUtc, query.ToUtc, cancellationToken).ConfigureAwait(false);
|
||||
if (getRecordsResult.IsFailure)
|
||||
return getRecordsResult.Errors;
|
||||
|
||||
|
||||
+5
@@ -37,5 +37,10 @@ public class GetMostConsumedQueryValidator : AbstractValidator<GetMostConsumedQu
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null || mediaKind != MediaKind.None)
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// An inverted range would silently return no records, so it is rejected as an invalid request instead.
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) => !fromUtc.HasValue || !query.ToUtc.HasValue || fromUtc.Value <= query.ToUtc.Value)
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
}
|
||||
+5
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -13,11 +14,15 @@ namespace Lumina.Application.Core.MediaConsumption.Queries.GetRecentlyConsumed;
|
||||
/// <param name="TargetUserId">The Id of the user whose history is retrieved, or <see langword="null"/> for the current user.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the history to, or <see langword="null"/> for every library.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the history to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, or <see langword="null"/> when the range has no end.</param>
|
||||
/// <param name="PaginationData">The object containing the requested pagination data. When <see langword="null"/>, every matching item is returned; when present, its requested page is returned.</param>
|
||||
[DebuggerDisplay("TargetUserId: {TargetUserId}; MediaKind: {MediaKind}")]
|
||||
public record GetRecentlyConsumedQuery(
|
||||
string? TargetUserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc,
|
||||
PaginationDataDto? PaginationData
|
||||
) : IQuery;
|
||||
+1
-1
@@ -93,7 +93,7 @@ public class GetRecentlyConsumedQueryHandler : IQueryHandler<GetRecentlyConsumed
|
||||
Guid? libraryId = query.LibraryId is null ? null : Guid.Parse(query.LibraryId);
|
||||
|
||||
Result<IReadOnlyList<MediaConsumptionRecordEntity>> getRecordsResult = await _unitOfWork.ConsumptionStatisticsRepository
|
||||
.GetForUserAsync(targetUserId, libraryId, query.MediaKind, fromUtc: null, toUtc: null, cancellationToken).ConfigureAwait(false);
|
||||
.GetForUserAsync(targetUserId, libraryId, query.MediaKind, query.FromUtc, query.ToUtc, cancellationToken).ConfigureAwait(false);
|
||||
if (getRecordsResult.IsFailure)
|
||||
return getRecordsResult.Errors;
|
||||
|
||||
|
||||
+5
@@ -37,5 +37,10 @@ public class GetRecentlyConsumedQueryValidator : AbstractValidator<GetRecentlyCo
|
||||
RuleFor(query => query.MediaKind)
|
||||
.Must(mediaKind => mediaKind is null || mediaKind != MediaKind.None)
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
// An inverted range would silently return no records, so it is rejected as an invalid request instead.
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) => !fromUtc.HasValue || !query.ToUtc.HasValue || fromUtc.Value <= query.ToUtc.Value)
|
||||
.WithError(Errors.MediaConsumption.ConsumptionDateRangeIsInvalid);
|
||||
}
|
||||
}
|
||||
+2
-5
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
@@ -9,20 +8,18 @@ using System.Diagnostics;
|
||||
namespace Lumina.Application.Core.MediaConsumption.Queries.GetTagConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Query for getting the consumption statistics of the tags and genres of a user.
|
||||
/// Query for getting the consumption statistics of the tags of a user.
|
||||
/// </summary>
|
||||
/// <param name="TargetUserId">The Id of the user whose statistics are retrieved, or <see langword="null"/> for the current user.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to, or <see langword="null"/> for every library.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to, or <see langword="null"/> for every kind.</param>
|
||||
/// <param name="TagKind">Whether to return genres or tags, or <see langword="null"/> for both.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range, or <see langword="null"/> when the range has no start.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range, or <see langword="null"/> when the range has no end.</param>
|
||||
[DebuggerDisplay("TargetUserId: {TargetUserId}; TagKind: {TagKind}")]
|
||||
[DebuggerDisplay("TargetUserId: {TargetUserId}; MediaKind: {MediaKind}")]
|
||||
public record GetTagConsumptionQuery(
|
||||
string? TargetUserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
TagKind? TagKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
) : IQuery;
|
||||
+32
-56
@@ -15,7 +15,6 @@ using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -28,7 +27,7 @@ using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
namespace Lumina.Application.Core.MediaConsumption.Queries.GetTagConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for the query to get the consumption statistics of the tags and genres of a user.
|
||||
/// Handler for the query to get the consumption statistics of the tags of a user.
|
||||
/// </summary>
|
||||
public class GetTagConsumptionQueryHandler : IQueryHandler<GetTagConsumptionQuery, Result<IReadOnlyList<TagConsumptionResponse>>>
|
||||
{
|
||||
@@ -57,12 +56,12 @@ public class GetTagConsumptionQueryHandler : IQueryHandler<GetTagConsumptionQuer
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the query to get the consumption statistics of the tags and genres of a user.
|
||||
/// Handles the query to get the consumption statistics of the tags of a user.
|
||||
/// </summary>
|
||||
/// <param name="query">The query to be handled.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either the requested tag and genre statistics, or an error message.
|
||||
/// An <see cref="Result{TValue}"/> containing either the requested tag statistics, or an error message.
|
||||
/// </returns>
|
||||
public async Task<Result<IReadOnlyList<TagConsumptionResponse>>> HandleAsync(GetTagConsumptionQuery query, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -90,8 +89,8 @@ public class GetTagConsumptionQueryHandler : IQueryHandler<GetTagConsumptionQuer
|
||||
if (getRecordsResult.IsFailure)
|
||||
return getRecordsResult.Errors;
|
||||
|
||||
// The access decision only needs the library Id that the records already carry, so it is made once per distinct library before any term is
|
||||
// loaded. Terms of a library the caller cannot access are never read.
|
||||
// The access decision only needs the library Id that the records already carry, so it is made once per distinct library before any tag is
|
||||
// loaded. Tags of a library the caller cannot access are never read.
|
||||
Dictionary<Guid, bool> libraryAccess = [];
|
||||
foreach (Guid recordLibraryId in getRecordsResult.Value.Select(record => record.LibraryId).Distinct())
|
||||
libraryAccess[recordLibraryId] = await _authorizationService.EvaluatePolicyAsync<ILibraryOwnershipPolicy>(
|
||||
@@ -126,40 +125,36 @@ public class GetTagConsumptionQueryHandler : IQueryHandler<GetTagConsumptionQuer
|
||||
books = [.. getBooksResult.Value];
|
||||
}
|
||||
|
||||
Dictionary<(MediaKind MediaKind, Guid MediaItemId, Guid LibraryId), List<(TagKind TagKind, string Name)>> termsByItem = [];
|
||||
Dictionary<(MediaKind MediaKind, Guid MediaItemId, Guid LibraryId), List<string>> tagNamesByItem = [];
|
||||
foreach (TrackEntity track in tracks)
|
||||
{
|
||||
List<(TagKind TagKind, string Name)> itemTerms = [];
|
||||
itemTerms.AddRange(track.Tags.Select(tag => tag.Name).OfType<string>().Select(name => (TagKind.Tag, name)));
|
||||
itemTerms.AddRange(track.Genres.Select(genre => genre.Name).OfType<string>().Select(name => (TagKind.Genre, name)));
|
||||
if (itemTerms.Count > 0)
|
||||
termsByItem[(MediaKind.MusicTrack, track.Id, track.LibraryId)] = itemTerms;
|
||||
List<string> itemTags = [.. track.Tags.Select(tag => tag.Name).OfType<string>()];
|
||||
if (itemTags.Count > 0)
|
||||
tagNamesByItem[(MediaKind.MusicTrack, track.Id, track.LibraryId)] = itemTags;
|
||||
}
|
||||
foreach (BookEntity book in books)
|
||||
{
|
||||
List<(TagKind TagKind, string Name)> itemTerms = [];
|
||||
itemTerms.AddRange(book.Tags.Select(tag => tag.Name).OfType<string>().Select(name => (TagKind.Tag, name)));
|
||||
itemTerms.AddRange(book.Genres.Select(genre => genre.Name).OfType<string>().Select(name => (TagKind.Genre, name)));
|
||||
if (itemTerms.Count > 0)
|
||||
termsByItem[(MediaKind.Book, book.Id, book.LibraryId)] = itemTerms;
|
||||
List<string> itemTags = [.. book.Tags.Select(tag => tag.Name).OfType<string>()];
|
||||
if (itemTags.Count > 0)
|
||||
tagNamesByItem[(MediaKind.Book, book.Id, book.LibraryId)] = itemTags;
|
||||
}
|
||||
|
||||
// The records are aggregated to one row per item and library first, so an item with several sessions contributes its terms once, not once per
|
||||
// The records are aggregated to one row per item and library first, so an item with several sessions contributes its tags once, not once per
|
||||
// session. The library is part of the key because the item is resolved in its current library, and a record from another library must not
|
||||
// borrow the terms or the access decision of the current one. An item that moved libraries after consumption is therefore excluded from the
|
||||
// borrow the tags or the access decision of the current one. An item that moved libraries after consumption is therefore excluded from the
|
||||
// breakdown, matching the history lists that blank display data when the record and item libraries disagree.
|
||||
Dictionary<(TagKind TagKind, string Name), (int ConsumedItemCount, long ConsumedDurationMilliseconds)> terms = [];
|
||||
Dictionary<string, (int ConsumedItemCount, long ConsumedDurationMilliseconds)> tags = [];
|
||||
foreach (IGrouping<(MediaKind MediaKind, Guid MediaItemId, Guid LibraryId), MediaConsumptionRecordEntity> itemGroup in getRecordsResult.Value
|
||||
.GroupBy(record => (record.MediaKind, record.MediaItemId, record.LibraryId)))
|
||||
{
|
||||
if (!libraryAccess[itemGroup.Key.LibraryId])
|
||||
continue;
|
||||
if (!termsByItem.TryGetValue((itemGroup.Key.MediaKind, itemGroup.Key.MediaItemId, itemGroup.Key.LibraryId), out List<(TagKind TagKind, string Name)>? itemTerms) ||
|
||||
itemTerms.Count == 0)
|
||||
if (!tagNamesByItem.TryGetValue((itemGroup.Key.MediaKind, itemGroup.Key.MediaItemId, itemGroup.Key.LibraryId), out List<string>? itemTags) ||
|
||||
itemTags.Count == 0)
|
||||
continue;
|
||||
|
||||
// The breakdown mirrors the statistics, so an item whose sessions all fall below the counting threshold of their media kind does not
|
||||
// contribute its terms or its duration to the breakdown.
|
||||
// contribute its tags or its duration to the breakdown.
|
||||
Optional<MediaConsumptionRule> ruleResult = MediaConsumptionRule.For(itemGroup.Key.MediaKind);
|
||||
if (!ruleResult.HasValue)
|
||||
continue;
|
||||
@@ -171,47 +166,29 @@ public class GetTagConsumptionQueryHandler : IQueryHandler<GetTagConsumptionQuer
|
||||
continue;
|
||||
|
||||
long consumedDurationMilliseconds = itemGroup.Sum(record => record.ConsumedDurationMilliseconds);
|
||||
|
||||
if (query.TagKind is null || query.TagKind == TagKind.Tag)
|
||||
{
|
||||
List<string> tagNames = [.. itemTerms
|
||||
.Where(termRow => termRow.TagKind == TagKind.Tag)
|
||||
.Select(termRow => termRow.Name)];
|
||||
AddTerms(terms, TagKind.Tag, tagNames, consumedDurationMilliseconds);
|
||||
}
|
||||
if (query.TagKind is null || query.TagKind == TagKind.Genre)
|
||||
{
|
||||
List<string> genreNames = [.. itemTerms
|
||||
.Where(termRow => termRow.TagKind == TagKind.Genre)
|
||||
.Select(termRow => termRow.Name)];
|
||||
AddTerms(terms, TagKind.Genre, genreNames, consumedDurationMilliseconds);
|
||||
}
|
||||
AddTags(tags, itemTags, consumedDurationMilliseconds);
|
||||
}
|
||||
|
||||
List<TagConsumptionDto> tagConsumptions = [.. terms
|
||||
.Select(term => new TagConsumptionDto(
|
||||
term.Key.Name,
|
||||
term.Key.TagKind,
|
||||
term.Value.ConsumedItemCount,
|
||||
term.Value.ConsumedDurationMilliseconds))
|
||||
List<TagConsumptionDto> tagConsumptions = [.. tags
|
||||
.Select(tag => new TagConsumptionDto(
|
||||
tag.Key,
|
||||
tag.Value.ConsumedItemCount,
|
||||
tag.Value.ConsumedDurationMilliseconds))
|
||||
.OrderByDescending(tagConsumption => tagConsumption.ConsumedItemCount)
|
||||
.ThenByDescending(tagConsumption => tagConsumption.ConsumedDurationMilliseconds)
|
||||
.ThenBy(tagConsumption => tagConsumption.TagKind)
|
||||
.ThenBy(tagConsumption => tagConsumption.Name)];
|
||||
|
||||
return Result.From(tagConsumptions.ToResponses());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the lowercase <paramref name="names"/> of one item to the accumulated <paramref name="terms"/>.
|
||||
/// Adds the lowercase <paramref name="names"/> of one item to the accumulated <paramref name="tags"/>.
|
||||
/// </summary>
|
||||
/// <param name="terms">The accumulated terms, keyed by tag kind and lowercase name.</param>
|
||||
/// <param name="tagKind">Whether the names are tags or genres.</param>
|
||||
/// <param name="names">The names carried by the item.</param>
|
||||
/// <param name="tags">The accumulated tags, keyed by lowercase name.</param>
|
||||
/// <param name="names">The tag names carried by the item.</param>
|
||||
/// <param name="consumedDurationMilliseconds">The duration consumed in the item, over all of its sessions, in milliseconds.</param>
|
||||
private static void AddTerms(
|
||||
Dictionary<(TagKind TagKind, string Name), (int ConsumedItemCount, long ConsumedDurationMilliseconds)> terms,
|
||||
TagKind tagKind,
|
||||
private static void AddTags(
|
||||
Dictionary<string, (int ConsumedItemCount, long ConsumedDurationMilliseconds)> tags,
|
||||
List<string> names,
|
||||
long consumedDurationMilliseconds)
|
||||
{
|
||||
@@ -220,11 +197,10 @@ public class GetTagConsumptionQueryHandler : IQueryHandler<GetTagConsumptionQuer
|
||||
{
|
||||
if (name.Length == 0)
|
||||
continue;
|
||||
(TagKind TagKind, string Name) key = (tagKind, name);
|
||||
if (terms.TryGetValue(key, out (int ConsumedItemCount, long ConsumedDurationMilliseconds) current))
|
||||
terms[key] = (current.ConsumedItemCount + 1, current.ConsumedDurationMilliseconds + consumedDurationMilliseconds);
|
||||
if (tags.TryGetValue(name, out (int ConsumedItemCount, long ConsumedDurationMilliseconds) current))
|
||||
tags[name] = (current.ConsumedItemCount + 1, current.ConsumedDurationMilliseconds + consumedDurationMilliseconds);
|
||||
else
|
||||
terms[key] = (1, consumedDurationMilliseconds);
|
||||
tags[name] = (1, consumedDurationMilliseconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
-6
@@ -2,7 +2,6 @@
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Common.Utilities;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
#endregion
|
||||
@@ -39,11 +38,6 @@ public class GetTagConsumptionQueryValidator : AbstractValidator<GetTagConsumpti
|
||||
.Must(mediaKind => mediaKind is null || mediaKind != MediaKind.None)
|
||||
.WithError(Errors.MediaConsumption.UnsupportedMediaKind);
|
||||
|
||||
RuleFor(query => query.TagKind)
|
||||
.IsInEnum()
|
||||
.WithError(Errors.MediaConsumption.TagKindIsInvalid)
|
||||
.When(query => query.TagKind is not null);
|
||||
|
||||
// An inverted range would silently return no records, so it is rejected as an invalid request instead.
|
||||
RuleFor(query => query.FromUtc)
|
||||
.Must((query, fromUtc) => !fromUtc.HasValue || !query.ToUtc.HasValue || fromUtc.Value <= query.ToUtc.Value)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to delete every consumption record of a media item.
|
||||
/// </summary>
|
||||
/// <param name="MediaKind">The kind of the consumed media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the media item.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; MediaItemId: {MediaItemId}; LibraryId: {LibraryId}")]
|
||||
public sealed record DeleteConsumptionItemHistoryRequest(
|
||||
MediaKind MediaKind,
|
||||
Guid MediaItemId,
|
||||
Guid LibraryId
|
||||
);
|
||||
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request for getting the consumption statistics of the genres of a user.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; FromUtc: {FromUtc}; ToUtc: {ToUtc}")]
|
||||
public sealed record GetGenreConsumptionRequest(
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
);
|
||||
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -12,10 +13,14 @@ namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
/// <param name="MediaKind">The kind of media to restrict the history to. Optional.</param>
|
||||
/// <param name="CurrentPage">The one based page of media items to return. Optional.</param>
|
||||
/// <param name="PerPage">The number of media items per page. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; CurrentPage: {CurrentPage}; PerPage: {PerPage}")]
|
||||
public sealed record GetMostConsumedRequest(
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
int? CurrentPage,
|
||||
int? PerPage
|
||||
int? PerPage,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
);
|
||||
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
@@ -12,10 +13,14 @@ namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
/// <param name="MediaKind">The kind of media to restrict the history to. Optional.</param>
|
||||
/// <param name="CurrentPage">The one based page of media items to return. Optional.</param>
|
||||
/// <param name="PerPage">The number of media items per page. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; CurrentPage: {CurrentPage}; PerPage: {PerPage}")]
|
||||
public sealed record GetRecentlyConsumedRequest(
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
int? CurrentPage,
|
||||
int? PerPage
|
||||
int? PerPage,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
);
|
||||
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
@@ -8,18 +7,16 @@ using System.Diagnostics;
|
||||
namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request for getting the consumption statistics of the tags and genres of a user.
|
||||
/// Represents a request for getting the consumption statistics of the tags of a user.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to. Optional.</param>
|
||||
/// <param name="TagKind">Whether to return genres or tags. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; TagKind: {TagKind}; FromUtc: {FromUtc}; ToUtc: {ToUtc}")]
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; FromUtc: {FromUtc}; ToUtc: {ToUtc}")]
|
||||
public sealed record GetTagConsumptionRequest(
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
TagKind? TagKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the consumption statistics of a genre, grouped across media kinds.
|
||||
/// </summary>
|
||||
/// <param name="Name">The lowercase name of the genre.</param>
|
||||
/// <param name="ConsumedItemCount">The number of distinct media items that carry the genre and were consumed.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed in the media items that carry the genre, in seconds.</param>
|
||||
[DebuggerDisplay("Name: {Name}; ConsumedItemCount: {ConsumedItemCount}")]
|
||||
public sealed record GenreConsumptionResponse(
|
||||
string Name,
|
||||
int ConsumedItemCount,
|
||||
double ConsumedDurationInSeconds
|
||||
);
|
||||
@@ -1,21 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the consumption statistics of a tag or genre, grouped across media kinds.
|
||||
/// Represents the consumption statistics of a tag, grouped across media kinds.
|
||||
/// </summary>
|
||||
/// <param name="Name">The lowercase name of the tag or genre.</param>
|
||||
/// <param name="TagKind">Whether the entry is a genre or a tag.</param>
|
||||
/// <param name="ConsumedItemCount">The number of distinct media items that carry the term and were consumed.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed in the media items that carry the term, in seconds.</param>
|
||||
[DebuggerDisplay("TagKind: {TagKind}; Name: {Name}; ConsumedItemCount: {ConsumedItemCount}")]
|
||||
/// <param name="Name">The lowercase name of the tag.</param>
|
||||
/// <param name="ConsumedItemCount">The number of distinct media items that carry the tag and were consumed.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed in the media items that carry the tag, in seconds.</param>
|
||||
[DebuggerDisplay("Name: {Name}; ConsumedItemCount: {ConsumedItemCount}")]
|
||||
public sealed record TagConsumptionResponse(
|
||||
string Name,
|
||||
TagKind TagKind,
|
||||
int ConsumedItemCount,
|
||||
double ConsumedDurationInSeconds
|
||||
);
|
||||
+22
@@ -130,6 +130,28 @@ internal sealed class MediaConsumptionRecordRepository : IMediaConsumptionRecord
|
||||
return Result.Deleted;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes every consumption record of a media item of the user identified by <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
/// <param name="userId">The Id of the user whose consumption records are deleted.</param>
|
||||
/// <param name="mediaKind">The kind of the consumed media item.</param>
|
||||
/// <param name="mediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="libraryId">The Id of the media library that contains the media item.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="Result{TValue}"/> representing either a successful deletion, or an error.</returns>
|
||||
public async Task<Result<Deleted>> DeleteAllByMediaItemIdForUserAsync(Guid userId, MediaKind mediaKind, Guid mediaItemId, Guid libraryId, CancellationToken cancellationToken)
|
||||
{
|
||||
List<MediaConsumptionRecordEntity> records = await _luminaDbContext.MediaConsumptionRecords
|
||||
.Where(record => record.UserId == userId &&
|
||||
record.MediaKind == mediaKind &&
|
||||
record.MediaItemId == mediaItemId &&
|
||||
record.LibraryId == libraryId)
|
||||
.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (records.Count > 0)
|
||||
_luminaDbContext.MediaConsumptionRecords.RemoveRange(records);
|
||||
return Result.Deleted;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes every consumption record of the user identified by <paramref name="userId"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the kinds of terms that a consumed media item can be classified by.
|
||||
/// </summary>
|
||||
public enum TagKind
|
||||
{
|
||||
/// <summary>
|
||||
/// A genre.
|
||||
/// </summary>
|
||||
Genre,
|
||||
|
||||
/// <summary>
|
||||
/// A tag.
|
||||
/// </summary>
|
||||
Tag
|
||||
}
|
||||
@@ -19,7 +19,6 @@ public static partial class Errors
|
||||
public static Error ConsumptionRecordIdCannotBeEmpty => Error.Validation(description: nameof(ConsumptionRecordIdCannotBeEmpty));
|
||||
public static Error MediaItemIdCannotBeEmpty => Error.Validation(description: nameof(MediaItemIdCannotBeEmpty));
|
||||
public static Error TargetUserIdIsInvalid => Error.Validation(description: nameof(TargetUserIdIsInvalid));
|
||||
public static Error TagKindIsInvalid => Error.Validation(description: nameof(TagKindIsInvalid));
|
||||
public static Error ConsumptionDateRangeIsInvalid => Error.Validation(description: nameof(ConsumptionDateRangeIsInvalid));
|
||||
public static Error InvalidMediaPosition => Error.Validation(description: nameof(InvalidMediaPosition));
|
||||
public static Error InvalidProgressFraction => Error.Validation(description: nameof(InvalidProgressFraction));
|
||||
|
||||
+4
@@ -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";
|
||||
|
||||
+60
@@ -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);
|
||||
}
|
||||
}
|
||||
+99
@@ -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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+58
@@ -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);
|
||||
}
|
||||
}
|
||||
+101
@@ -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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+62
@@ -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);
|
||||
}
|
||||
}
|
||||
+120
@@ -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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+62
@@ -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);
|
||||
}
|
||||
}
|
||||
+122
@@ -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"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
+9
-4
@@ -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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
+9
-4
@@ -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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
+9
-4
@@ -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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
+9
-4
@@ -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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
+1
-1
@@ -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>
|
||||
|
||||
+9
-17
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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>
|
||||
|
||||
+9
-17
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the listening statistics of the current user.
|
||||
/// </summary>
|
||||
/// <param name="TotalListeningDurationInSeconds">The total duration the user listened to, over every recorded play, in seconds.</param>
|
||||
/// <param name="TotalPlayCount">The number of recorded plays that count as plays. An in-progress play counts once it reaches the threshold, so this total can exceed the completed and stopped plays together.</param>
|
||||
/// <param name="CompletedPlayCount">The number of recorded plays that completed.</param>
|
||||
/// <param name="StoppedPlayCount">The number of recorded plays that stopped before the track completed and count as plays.</param>
|
||||
/// <param name="CompletionRate">The fraction of the plays that count as plays that completed, between 0 and 1, or 0 when there is no counted play.</param>
|
||||
[DebuggerDisplay("TotalPlayCount: {TotalPlayCount}; CompletedPlayCount: {CompletedPlayCount}")]
|
||||
public sealed record MusicPlayStatisticsDto(
|
||||
double TotalListeningDurationInSeconds,
|
||||
int TotalPlayCount,
|
||||
int CompletedPlayCount,
|
||||
int StoppedPlayCount,
|
||||
double CompletionRate
|
||||
);
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a track of the listening statistics of the current user, together with its aggregated play counts.
|
||||
/// </summary>
|
||||
/// <param name="TrackId">The Id of the track.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the track.</param>
|
||||
/// <param name="AlbumId">The Id of the album that contains the track.</param>
|
||||
/// <param name="ArtistId">The Id of the artist that produced the track.</param>
|
||||
/// <param name="Title">The title of the track, if it still exists and the user can access its library.</param>
|
||||
/// <param name="AlbumTitle">The title of the album that contains the track, if it still exists and the user can access its library.</param>
|
||||
/// <param name="ArtistName">The name of the artist that produced the track, if it still exists and the user can access its library.</param>
|
||||
/// <param name="CoverPath">The path of the cover art of the album, if available.</param>
|
||||
/// <param name="LastPlayedOnUtc">The date and time of the last recorded activity of the track's most recent play.</param>
|
||||
/// <param name="PlayCount">The number of plays of the track that count as plays.</param>
|
||||
/// <param name="CompletedPlayCount">The number of plays of the track that completed.</param>
|
||||
/// <param name="ListenedDurationInSeconds">The duration the user listened to the track, over all of its counted plays, in seconds.</param>
|
||||
[DebuggerDisplay("TrackId: {TrackId}; PlayCount: {PlayCount}")]
|
||||
public sealed record PlayedTrackDto(
|
||||
Guid TrackId,
|
||||
Guid LibraryId,
|
||||
Guid AlbumId,
|
||||
Guid ArtistId,
|
||||
string? Title,
|
||||
string? AlbumTitle,
|
||||
string? ArtistName,
|
||||
string? CoverPath,
|
||||
DateTime LastPlayedOnUtc,
|
||||
int PlayCount,
|
||||
int CompletedPlayCount,
|
||||
double ListenedDurationInSeconds
|
||||
);
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of every user, together with their combined totals.
|
||||
/// </summary>
|
||||
/// <param name="Total">The combined consumption statistics of every user.</param>
|
||||
/// <param name="Users">The consumption statistics of each user.</param>
|
||||
[DebuggerDisplay("UserCount: {Users.Count}; CountedSessionCount: {Total.CountedSessionCount}")]
|
||||
public sealed record AllUsersConsumptionStatisticsDto(
|
||||
ConsumptionTotalsDto Total,
|
||||
IReadOnlyList<ConsumptionSummaryDto> Users
|
||||
);
|
||||
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a media item of the consumption history, together with its aggregated consumption counts and display details.
|
||||
/// </summary>
|
||||
/// <param name="MediaKind">The kind of the consumed media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the media item.</param>
|
||||
/// <param name="IsAvailable">Whether the media item still exists and can be accessed by the user. When <see langword="false"/>, the title, collection title, creator name, and cover path are blank, while the identity and aggregation fields remain.</param>
|
||||
/// <param name="Title">The title of the media item, or an empty string when the item is not available.</param>
|
||||
/// <param name="CollectionTitle">The title of the collection that contains the media item, or an empty string when there is none.</param>
|
||||
/// <param name="CreatorName">The name of the creator of the media item, or an empty string when there is none.</param>
|
||||
/// <param name="CoverPath">The path of the cover art of the media item, if available.</param>
|
||||
/// <param name="LastConsumedOnUtc">The date and time when the media item was last consumed.</param>
|
||||
/// <param name="CountedSessionCount">The number of consumption sessions of the media item that count towards statistics.</param>
|
||||
/// <param name="CompletedSessionCount">The number of consumption sessions of the media item that completed.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed in the media item, over all of its sessions, in seconds.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; MediaItemId: {MediaItemId}; CountedSessionCount: {CountedSessionCount}")]
|
||||
public sealed record ConsumedItemDto(
|
||||
MediaKind MediaKind,
|
||||
Guid MediaItemId,
|
||||
Guid LibraryId,
|
||||
bool IsAvailable,
|
||||
string Title,
|
||||
string CollectionTitle,
|
||||
string CreatorName,
|
||||
string? CoverPath,
|
||||
DateTime LastConsumedOnUtc,
|
||||
int CountedSessionCount,
|
||||
int CompletedSessionCount,
|
||||
double ConsumedDurationInSeconds
|
||||
);
|
||||
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of a user.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user the statistics belong to.</param>
|
||||
/// <param name="TotalConsumedDurationInSeconds">The total duration consumed over every recorded session, in seconds.</param>
|
||||
/// <param name="CountedSessionCount">The number of recorded sessions that count towards statistics.</param>
|
||||
/// <param name="CompletedSessionCount">The number of recorded sessions that completed.</param>
|
||||
/// <param name="StoppedSessionCount">The number of recorded sessions that stopped before they completed and count towards statistics.</param>
|
||||
/// <param name="CompletionRate">The fraction of the counted sessions that completed, between 0 and 1, or 0 when there is no counted session.</param>
|
||||
/// <param name="MediaKindSummaries">The consumption statistics broken down by media kind.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}; CountedSessionCount: {CountedSessionCount}")]
|
||||
public sealed record ConsumptionSummaryDto(
|
||||
Guid UserId,
|
||||
double TotalConsumedDurationInSeconds,
|
||||
int CountedSessionCount,
|
||||
int CompletedSessionCount,
|
||||
int StoppedSessionCount,
|
||||
double CompletionRate,
|
||||
IReadOnlyList<MediaKindConsumptionSummaryDto> MediaKindSummaries
|
||||
);
|
||||
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the combined consumption statistics of every user.
|
||||
/// </summary>
|
||||
/// <param name="TotalConsumedDurationInSeconds">The total duration consumed over every recorded session of every user, in seconds.</param>
|
||||
/// <param name="CountedSessionCount">The number of recorded sessions of every user that count towards statistics.</param>
|
||||
/// <param name="CompletedSessionCount">The number of recorded sessions of every user that completed.</param>
|
||||
/// <param name="StoppedSessionCount">The number of recorded sessions of every user that stopped before they completed and count towards statistics.</param>
|
||||
/// <param name="CompletionRate">The fraction of the counted sessions of every user that completed, between 0 and 1, or 0 when there is no counted session.</param>
|
||||
/// <param name="MediaKindSummaries">The combined consumption statistics broken down by media kind.</param>
|
||||
[DebuggerDisplay("CountedSessionCount: {CountedSessionCount}; CompletedSessionCount: {CompletedSessionCount}")]
|
||||
public sealed record ConsumptionTotalsDto(
|
||||
double TotalConsumedDurationInSeconds,
|
||||
int CountedSessionCount,
|
||||
int CompletedSessionCount,
|
||||
int StoppedSessionCount,
|
||||
double CompletionRate,
|
||||
IReadOnlyList<MediaKindConsumptionSummaryDto> MediaKindSummaries
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of a genre, grouped across media kinds.
|
||||
/// </summary>
|
||||
/// <param name="Name">The lowercase name of the genre.</param>
|
||||
/// <param name="ConsumedItemCount">The number of distinct media items that carry the genre and were consumed.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed in the media items that carry the genre, in seconds.</param>
|
||||
[DebuggerDisplay("Name: {Name}; ConsumedItemCount: {ConsumedItemCount}")]
|
||||
public sealed record GenreConsumptionDto(
|
||||
string Name,
|
||||
int ConsumedItemCount,
|
||||
double ConsumedDurationInSeconds
|
||||
);
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of one kind of media.
|
||||
/// </summary>
|
||||
/// <param name="MediaKind">The kind of media the statistics belong to.</param>
|
||||
/// <param name="TotalConsumedDurationInSeconds">The total duration consumed over every recorded session of the media kind, in seconds.</param>
|
||||
/// <param name="CountedSessionCount">The number of recorded sessions of the media kind that count towards statistics.</param>
|
||||
/// <param name="CompletedSessionCount">The number of recorded sessions of the media kind that completed.</param>
|
||||
/// <param name="StoppedSessionCount">The number of recorded sessions of the media kind that stopped before they completed and count towards statistics.</param>
|
||||
/// <param name="CompletionRate">The fraction of the counted sessions of the media kind that completed, between 0 and 1.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; CountedSessionCount: {CountedSessionCount}")]
|
||||
public sealed record MediaKindConsumptionSummaryDto(
|
||||
MediaKind MediaKind,
|
||||
double TotalConsumedDurationInSeconds,
|
||||
int CountedSessionCount,
|
||||
int CompletedSessionCount,
|
||||
int StoppedSessionCount,
|
||||
double CompletionRate
|
||||
);
|
||||
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the data and the proxy routes of the statistics page.
|
||||
/// </summary>
|
||||
/// <param name="Title">The localized title of the page.</param>
|
||||
/// <param name="IsAdmin">Whether the current user is an administrator and can select another user or all users.</param>
|
||||
/// <param name="CurrentUserId">The Id of the current user, or <see langword="null"/> when it cannot be determined.</param>
|
||||
/// <param name="Culture">The culture of the page.</param>
|
||||
/// <param name="GetStatisticsUrl">The route that returns the statistics of the selected user.</param>
|
||||
/// <param name="GetAllUsersStatisticsUrl">The route that returns the statistics of every user.</param>
|
||||
/// <param name="GetRecentlyConsumedUrl">The route that returns the recently consumed media items of the selected user.</param>
|
||||
/// <param name="GetMostConsumedUrl">The route that returns the most consumed media items of the selected user.</param>
|
||||
/// <param name="GetTagConsumptionUrl">The route that returns the tag consumption of the selected user.</param>
|
||||
/// <param name="GetGenreConsumptionUrl">The route that returns the genre consumption of the selected user.</param>
|
||||
/// <param name="GetLibrariesUrl">The route that returns the libraries available for the library filter.</param>
|
||||
/// <param name="GetUsersUrl">The route that returns the users available for the administrator user selector, or an empty string for a regular user.</param>
|
||||
/// <param name="DeleteConsumptionItemHistoryUrl">The route that deletes every consumption record of a media item.</param>
|
||||
/// <param name="ClearConsumptionHistoryUrl">The route that deletes the consumption history of the selected user.</param>
|
||||
/// <param name="ClearResumePointsUrl">The route that deletes the resume points of the selected user.</param>
|
||||
[DebuggerDisplay("IsAdmin: {IsAdmin}; CurrentUserId: {CurrentUserId}")]
|
||||
public sealed record StatisticsPageDto(
|
||||
string Title,
|
||||
bool IsAdmin,
|
||||
Guid? CurrentUserId,
|
||||
string Culture,
|
||||
string GetStatisticsUrl,
|
||||
string GetAllUsersStatisticsUrl,
|
||||
string GetRecentlyConsumedUrl,
|
||||
string GetMostConsumedUrl,
|
||||
string GetTagConsumptionUrl,
|
||||
string GetGenreConsumptionUrl,
|
||||
string GetLibrariesUrl,
|
||||
string GetUsersUrl,
|
||||
string DeleteConsumptionItemHistoryUrl,
|
||||
string ClearConsumptionHistoryUrl,
|
||||
string ClearResumePointsUrl
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of a tag, grouped across media kinds.
|
||||
/// </summary>
|
||||
/// <param name="Name">The lowercase name of the tag.</param>
|
||||
/// <param name="ConsumedItemCount">The number of distinct media items that carry the tag and were consumed.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed in the media items that carry the tag, in seconds.</param>
|
||||
[DebuggerDisplay("Name: {Name}; ConsumedItemCount: {ConsumedItemCount}")]
|
||||
public sealed record TagConsumptionDto(
|
||||
string Name,
|
||||
int ConsumedItemCount,
|
||||
double ConsumedDurationInSeconds
|
||||
);
|
||||
@@ -0,0 +1,52 @@
|
||||
namespace Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Enumeration for the kinds of media items of the consumption history and statistics.
|
||||
/// </summary>
|
||||
public enum MediaKind
|
||||
{
|
||||
/// <summary>
|
||||
/// No media kind. Used as the default value; it is not a valid kind for a media item.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// A track of a music library.
|
||||
/// </summary>
|
||||
MusicTrack,
|
||||
|
||||
/// <summary>
|
||||
/// An episode of a podcast.
|
||||
/// </summary>
|
||||
PodcastEpisode,
|
||||
|
||||
/// <summary>
|
||||
/// An audiobook.
|
||||
/// </summary>
|
||||
Audiobook,
|
||||
|
||||
/// <summary>
|
||||
/// A movie.
|
||||
/// </summary>
|
||||
Movie,
|
||||
|
||||
/// <summary>
|
||||
/// An episode of a TV show.
|
||||
/// </summary>
|
||||
TvEpisode,
|
||||
|
||||
/// <summary>
|
||||
/// A book of a written content library.
|
||||
/// </summary>
|
||||
Book,
|
||||
|
||||
/// <summary>
|
||||
/// A photo.
|
||||
/// </summary>
|
||||
Photo,
|
||||
|
||||
/// <summary>
|
||||
/// A video file.
|
||||
/// </summary>
|
||||
Video
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request for getting a page of the most played tracks of the current user.
|
||||
/// </summary>
|
||||
/// <param name="CurrentPage">The one based page of tracks to return. Optional. Defaults to 1.</param>
|
||||
/// <param name="PerPage">The number of tracks per page. Optional. Defaults to 10.</param>
|
||||
[DebuggerDisplay("CurrentPage: {CurrentPage}; PerPage: {PerPage}")]
|
||||
public record GetMostPlayedRequest(
|
||||
int? CurrentPage,
|
||||
int? PerPage
|
||||
);
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request for getting a page of the recently played tracks of the current user.
|
||||
/// </summary>
|
||||
/// <param name="CurrentPage">The one based page of tracks to return. Optional. Defaults to 1.</param>
|
||||
/// <param name="PerPage">The number of tracks per page. Optional. Defaults to 10.</param>
|
||||
[DebuggerDisplay("CurrentPage: {CurrentPage}; PerPage: {PerPage}")]
|
||||
public record GetRecentlyPlayedRequest(
|
||||
int? CurrentPage,
|
||||
int? PerPage
|
||||
);
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to delete the consumption history of a user.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user whose history is deleted. Optional; when omitted, the current user is used.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}")]
|
||||
public sealed record ClearConsumptionHistoryRequest(
|
||||
string? UserId
|
||||
);
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to delete the resume points of a user.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user whose resume points are deleted. Optional; when omitted, the current user is used.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the deletion to. Optional.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}; LibraryId: {LibraryId}")]
|
||||
public sealed record ClearResumePointsRequest(
|
||||
string? UserId,
|
||||
string? LibraryId
|
||||
);
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to delete every consumption record of a media item.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user whose history is deleted. Optional; when omitted, the current user is used.</param>
|
||||
/// <param name="MediaKind">The kind of the consumed media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the media item.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}; MediaKind: {MediaKind}; MediaItemId: {MediaItemId}")]
|
||||
public sealed record DeleteConsumptionItemHistoryRequest(
|
||||
string? UserId,
|
||||
MediaKind MediaKind,
|
||||
Guid MediaItemId,
|
||||
Guid LibraryId
|
||||
);
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request for getting the consumption statistics of every user.
|
||||
/// </summary>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; FromUtc: {FromUtc}; ToUtc: {ToUtc}")]
|
||||
public sealed record GetAllUsersConsumptionStatisticsRequest(
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
);
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request for getting the consumption statistics of a user.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user whose statistics are retrieved. Optional; when omitted, the current user is used.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}; MediaKind: {MediaKind}")]
|
||||
public sealed record GetConsumptionStatisticsRequest(
|
||||
string? UserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
);
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request for getting the consumption statistics of the genres of a user.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user whose statistics are retrieved. Optional; when omitted, the current user is used.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}; MediaKind: {MediaKind}; FromUtc: {FromUtc}")]
|
||||
public sealed record GetGenreConsumptionRequest(
|
||||
string? UserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
);
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request for getting a window of the most consumed media items of a user.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user whose history is retrieved. Optional; when omitted, the current user is used.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the history to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the history to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
/// <param name="CurrentPage">The one based page of media items to return. Optional.</param>
|
||||
/// <param name="PerPage">The number of media items per page. Optional.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}; MediaKind: {MediaKind}; CurrentPage: {CurrentPage}")]
|
||||
public sealed record GetMostConsumedRequest(
|
||||
string? UserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc,
|
||||
int? CurrentPage,
|
||||
int? PerPage
|
||||
);
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request for getting a window of the recently consumed media items of a user.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user whose history is retrieved. Optional; when omitted, the current user is used.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the history to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the history to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
/// <param name="CurrentPage">The one based page of media items to return. Optional.</param>
|
||||
/// <param name="PerPage">The number of media items per page. Optional.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}; MediaKind: {MediaKind}; CurrentPage: {CurrentPage}")]
|
||||
public sealed record GetRecentlyConsumedRequest(
|
||||
string? UserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc,
|
||||
int? CurrentPage,
|
||||
int? PerPage
|
||||
);
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request for getting the consumption statistics of the tags of a user.
|
||||
/// </summary>
|
||||
/// <param name="UserId">The Id of the user whose statistics are retrieved. Optional; when omitted, the current user is used.</param>
|
||||
/// <param name="LibraryId">The Id of the media library to restrict the statistics to. Optional.</param>
|
||||
/// <param name="MediaKind">The kind of media to restrict the statistics to. Optional.</param>
|
||||
/// <param name="FromUtc">The inclusive start of the date range. Optional.</param>
|
||||
/// <param name="ToUtc">The inclusive end of the date range. Optional.</param>
|
||||
[DebuggerDisplay("UserId: {UserId}; MediaKind: {MediaKind}; FromUtc: {FromUtc}")]
|
||||
public sealed record GetTagConsumptionRequest(
|
||||
string? UserId,
|
||||
string? LibraryId,
|
||||
MediaKind? MediaKind,
|
||||
DateTime? FromUtc,
|
||||
DateTime? ToUtc
|
||||
);
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace Lumina.Presentation.Web.Common.Routes;
|
||||
|
||||
/// <summary>
|
||||
/// Class for the collection of remote API routes called by this Web application.
|
||||
/// </summary>
|
||||
public static partial class ApiRoutes
|
||||
{
|
||||
/// <summary>
|
||||
/// Routes for the consumption history, consumption statistics, and resume points of the remote API.
|
||||
/// </summary>
|
||||
public static class LibraryStatistics
|
||||
{
|
||||
public const string GET_RECENTLY_CONSUMED = "users/me/consumption-history/recently-consumed";
|
||||
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_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";
|
||||
public const string CLEAR_USER_RESUME_POINTS = "users/{userId}/media-resume-points";
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace Lumina.Presentation.Web.Common.Routes;
|
||||
|
||||
/// <summary>
|
||||
/// Class for the collection of remote API routes called by this Web application.
|
||||
/// </summary>
|
||||
public static partial class ApiRoutes
|
||||
{
|
||||
/// <summary>
|
||||
/// Routes for the music play statistics endpoints of the remote API.
|
||||
/// </summary>
|
||||
public static class PlayStatistics
|
||||
{
|
||||
public const string GET_RECENTLY_PLAYED = "users/me/music-play-history/recently-played";
|
||||
public const string GET_MOST_PLAYED = "users/me/music-play-history/most-played";
|
||||
public const string GET_MUSIC_PLAY_STATISTICS = "users/me/music-play-history/statistics";
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,16 @@ public static partial class WebRoutes
|
||||
public static class LibraryStatistics
|
||||
{
|
||||
public const string INDEX = "{culture}/library/statistics";
|
||||
public const string GET_RECENTLY_PLAYED = "{culture}/library/statistics/api-get-recently-played";
|
||||
public const string GET_MOST_PLAYED = "{culture}/library/statistics/api-get-most-played";
|
||||
public const string GET_MUSIC_PLAY_STATISTICS = "{culture}/library/statistics/api-get-music-play-statistics";
|
||||
public const string GET_STATISTICS = "{culture}/library/statistics/api-get-statistics";
|
||||
public const string GET_ALL_USERS_STATISTICS = "{culture}/library/statistics/api-get-all-users-statistics";
|
||||
public const string GET_RECENTLY_CONSUMED = "{culture}/library/statistics/api-get-recently-consumed";
|
||||
public const string GET_MOST_CONSUMED = "{culture}/library/statistics/api-get-most-consumed";
|
||||
public const string GET_TAG_CONSUMPTION = "{culture}/library/statistics/api-get-tag-consumption";
|
||||
public const string GET_GENRE_CONSUMPTION = "{culture}/library/statistics/api-get-genre-consumption";
|
||||
public const string GET_LIBRARIES = "{culture}/library/statistics/api-get-libraries";
|
||||
public const string GET_USERS = "{culture}/library/statistics/api-get-users";
|
||||
public const string DELETE_CONSUMPTION_ITEM_HISTORY = "{culture}/library/statistics/api-delete-consumption-item-history";
|
||||
public const string CLEAR_CONSUMPTION_HISTORY = "{culture}/library/statistics/api-clear-consumption-history";
|
||||
public const string CLEAR_RESUME_POINTS = "{culture}/library/statistics/api-clear-resume-points";
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.ClearConsumptionHistory;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-clear-consumption-history</c> route.
|
||||
/// </summary>
|
||||
public class ClearConsumptionHistoryEndpoint : BaseEndpoint<ClearConsumptionHistoryRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ClearConsumptionHistoryEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public ClearConsumptionHistoryEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.DELETE);
|
||||
Routes(WebRoutes.LibraryStatistics.CLEAR_CONSUMPTION_HISTORY);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Statistics"));
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes every consumption record of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(ClearConsumptionHistoryRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The history belongs to the selected user, so no intermediary may store any response of this route, and the response varies by the sign in cookie.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Cookie";
|
||||
string path = string.IsNullOrWhiteSpace(request.UserId)
|
||||
? ApiRoutes.LibraryStatistics.CLEAR_CONSUMPTION_HISTORY
|
||||
: ApiRoutes.LibraryStatistics.CLEAR_USER_CONSUMPTION_HISTORY.Replace("{userId}", Uri.EscapeDataString(request.UserId), StringComparison.Ordinal);
|
||||
await _apiHttpClient.DeleteAsync(path, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess();
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.ClearConsumptionHistory;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="ClearConsumptionHistoryEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ClearConsumptionHistoryEndpointSummary : Summary<ClearConsumptionHistoryEndpoint, ClearConsumptionHistoryRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ClearConsumptionHistoryEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public ClearConsumptionHistoryEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes every consumption record of the selected user.";
|
||||
Description = "Proxies the request that deletes every recorded consumption session of the selected user to the API server. When userId is omitted, the history of the current user is deleted; an administrator can name another user. Clearing an already empty history succeeds without changing anything. The resume points are not deleted. A failure is returned as a JSON object with success set to false and a localized errorMessage.";
|
||||
|
||||
RequestParam(request => request.UserId, "The Id of the user whose history is deleted. Optional; when omitted, the current user is used.");
|
||||
|
||||
ResponseParam<SuccessResponse>(response => response.IsSuccess, "Whether the operation succeeded.");
|
||||
|
||||
Response(200, "The consumption history was cleared, or a JSON error with success set to false.",
|
||||
example: new SuccessResponse(true)
|
||||
);
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.ClearResumePoints;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-clear-resume-points</c> route.
|
||||
/// </summary>
|
||||
public class ClearResumePointsEndpoint : BaseEndpoint<ClearResumePointsRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ClearResumePointsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public ClearResumePointsEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.DELETE);
|
||||
Routes(WebRoutes.LibraryStatistics.CLEAR_RESUME_POINTS);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Statistics"));
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the resume points of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user and the optional library filter.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(ClearResumePointsRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The resume points belong to the selected user, so no intermediary may store any response of this route, and the response varies by the sign in cookie.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Cookie";
|
||||
string path = string.IsNullOrWhiteSpace(request.UserId)
|
||||
? ApiRoutes.LibraryStatistics.CLEAR_RESUME_POINTS
|
||||
: ApiRoutes.LibraryStatistics.CLEAR_USER_RESUME_POINTS.Replace("{userId}", Uri.EscapeDataString(request.UserId), StringComparison.Ordinal);
|
||||
if (!string.IsNullOrWhiteSpace(request.LibraryId))
|
||||
path += $"?libraryId={Uri.EscapeDataString(request.LibraryId)}";
|
||||
await _apiHttpClient.DeleteAsync(path, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess();
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.ClearResumePoints;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="ClearResumePointsEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ClearResumePointsEndpointSummary : Summary<ClearResumePointsEndpoint, ClearResumePointsRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ClearResumePointsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public ClearResumePointsEndpointSummary()
|
||||
{
|
||||
Summary = "Deletes the resume points of the selected user.";
|
||||
Description = "Proxies the request that deletes the resume points of the selected user, optionally limited to one library, to the API server. When userId is omitted, the resume points of the current user are deleted; an administrator can name another user. The consumption history is not deleted. A failure is returned as a JSON object with success set to false and a localized errorMessage.";
|
||||
|
||||
RequestParam(request => request.UserId, "The Id of the user whose resume points are deleted. Optional; when omitted, the current user is used.");
|
||||
RequestParam(request => request.LibraryId, "The Id of the media library to restrict the deletion to. Optional.");
|
||||
|
||||
ResponseParam<SuccessResponse>(response => response.IsSuccess, "Whether the operation succeeded.");
|
||||
|
||||
Response(200, "The resume points were removed, or a JSON error with success set to false.",
|
||||
example: new SuccessResponse(true)
|
||||
);
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.DeleteConsumptionItemHistory;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-delete-consumption-item-history</c> route.
|
||||
/// </summary>
|
||||
public class DeleteConsumptionItemHistoryEndpoint : BaseEndpoint<DeleteConsumptionItemHistoryRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteConsumptionItemHistoryEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public DeleteConsumptionItemHistoryEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.DELETE);
|
||||
Routes(WebRoutes.LibraryStatistics.DELETE_CONSUMPTION_ITEM_HISTORY);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Statistics"));
|
||||
EnableAntiforgery();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes every consumption record of a media item of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user, 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 records belong to the selected user, so no intermediary may store any response of this route, and the response varies by the sign in cookie.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Cookie";
|
||||
string path = string.IsNullOrWhiteSpace(request.UserId)
|
||||
? ApiRoutes.LibraryStatistics.DELETE_CONSUMPTION_ITEM_HISTORY
|
||||
: ApiRoutes.LibraryStatistics.DELETE_USER_CONSUMPTION_ITEM_HISTORY.Replace("{userId}", Uri.EscapeDataString(request.UserId), StringComparison.Ordinal);
|
||||
path = path
|
||||
.Replace("{mediaKind}", request.MediaKind.ToString(), StringComparison.Ordinal)
|
||||
.Replace("{mediaItemId}", request.MediaItemId.ToString(), StringComparison.Ordinal)
|
||||
.Replace("{libraryId}", request.LibraryId.ToString(), StringComparison.Ordinal);
|
||||
await _apiHttpClient.DeleteAsync(path, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess();
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.DeleteConsumptionItemHistory;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="DeleteConsumptionItemHistoryEndpoint"/> 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 selected user.";
|
||||
Description = "Proxies the request that deletes every recorded consumption session of one media item of the selected user, in the library named by the request, to the API server. The deletion covers every session of the item, independent of any date range. When userId is omitted, the history of the current user is deleted; an administrator can name another user. Deleting an item that has no recorded session succeeds without changing anything. The resume point of the media item is not deleted. A failure is returned as a JSON object with success set to false and a localized errorMessage.";
|
||||
|
||||
RequestParam(request => request.UserId, "The Id of the user whose history is deleted. Optional; when omitted, the current user is used.");
|
||||
RequestParam(request => request.MediaKind, "The kind of the consumed media item.");
|
||||
RequestParam(request => request.MediaItemId, "The Id of the consumed media item.");
|
||||
RequestParam(request => request.LibraryId, "The Id of the media library that contains the media item.");
|
||||
|
||||
ResponseParam<SuccessResponse>(response => response.IsSuccess, "Whether the operation succeeded.");
|
||||
|
||||
Response(200, "The consumption records of the media item were deleted, or a JSON error with success set to false.",
|
||||
example: new SuccessResponse(true)
|
||||
);
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.Authorization;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetAllUsersConsumptionStatistics;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-get-all-users-statistics</c> route.
|
||||
/// </summary>
|
||||
public class GetAllUsersConsumptionStatisticsEndpoint : BaseEndpoint<GetAllUsersConsumptionStatisticsRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetAllUsersConsumptionStatisticsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetAllUsersConsumptionStatisticsEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.LibraryStatistics.GET_ALL_USERS_STATISTICS);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Statistics"));
|
||||
Policies(AuthorizationPolicies.REQUIRE_ADMIN_ROLE);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the combined consumption statistics of every user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the optional filters.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetAllUsersConsumptionStatisticsRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The statistics belong to every user of the server, so no intermediary may store them, and the response varies by the sign in cookie.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Cookie";
|
||||
AllUsersConsumptionStatisticsDto response = await _apiHttpClient.GetAsync<AllUsersConsumptionStatisticsDto>(BuildStatisticsEndpoint(request), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the API endpoint used to retrieve the combined consumption statistics of every user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the optional filters.</param>
|
||||
/// <returns>The API endpoint to which the statistics request is sent.</returns>
|
||||
private static string BuildStatisticsEndpoint(GetAllUsersConsumptionStatisticsRequest request)
|
||||
{
|
||||
// The query string is rebuilt from the typed request values instead of forwarding the raw one, so that crafted text can never alter the upstream URL.
|
||||
StringBuilder endpoint = new(ApiRoutes.LibraryStatistics.GET_ALL_USERS_CONSUMPTION_STATISTICS);
|
||||
List<string> parameters = [];
|
||||
if (!string.IsNullOrWhiteSpace(request.LibraryId))
|
||||
parameters.Add($"libraryId={Uri.EscapeDataString(request.LibraryId)}");
|
||||
if (request.MediaKind is not null)
|
||||
parameters.Add($"mediaKind={Uri.EscapeDataString(request.MediaKind.Value.ToString())}");
|
||||
if (request.FromUtc is not null)
|
||||
parameters.Add($"fromUtc={Uri.EscapeDataString(request.FromUtc.Value.ToString("O", CultureInfo.InvariantCulture))}");
|
||||
if (request.ToUtc is not null)
|
||||
parameters.Add($"toUtc={Uri.EscapeDataString(request.ToUtc.Value.ToString("O", CultureInfo.InvariantCulture))}");
|
||||
if (parameters.Count > 0)
|
||||
endpoint.Append('?').Append(string.Join('&', parameters));
|
||||
return endpoint.ToString();
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetAllUsersConsumptionStatistics;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetAllUsersConsumptionStatisticsEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetAllUsersConsumptionStatisticsEndpointSummary : Summary<GetAllUsersConsumptionStatisticsEndpoint, GetAllUsersConsumptionStatisticsRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetAllUsersConsumptionStatisticsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetAllUsersConsumptionStatisticsEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the consumption statistics of every user.";
|
||||
Description = "Proxies the request that gets the combined consumption statistics of every user, together with the statistics of each user, to the API server. Only an administrator can call it. The date range is inclusive. A failure is returned as a JSON object with success set to false and a localized errorMessage.";
|
||||
|
||||
ExampleRequest = new GetAllUsersConsumptionStatisticsRequest(
|
||||
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<SuccessResponse<AllUsersConsumptionStatisticsDto>>(response => response.IsSuccess, "Whether the operation succeeded.");
|
||||
ResponseParam<AllUsersConsumptionStatisticsDto>(response => response.Total, "The combined consumption statistics of every user.");
|
||||
ResponseParam<AllUsersConsumptionStatisticsDto>(response => response.Users, "The consumption statistics of each user, ordered by user Id.");
|
||||
ResponseParam<ConsumptionTotalsDto>(response => response.TotalConsumedDurationInSeconds, "The total duration consumed over every recorded session of every user, in seconds.");
|
||||
ResponseParam<ConsumptionTotalsDto>(response => response.CountedSessionCount, "The number of recorded sessions of every user that count towards statistics.");
|
||||
ResponseParam<ConsumptionTotalsDto>(response => response.CompletedSessionCount, "The number of recorded sessions of every user that completed.");
|
||||
ResponseParam<ConsumptionTotalsDto>(response => response.StoppedSessionCount, "The number of recorded sessions of every user that stopped before they completed and count towards statistics.");
|
||||
ResponseParam<ConsumptionTotalsDto>(response => response.CompletionRate, "The fraction of the counted sessions of every user that completed, between 0 and 1, or 0 when there is no counted session.");
|
||||
ResponseParam<ConsumptionTotalsDto>(response => response.MediaKindSummaries, "The combined consumption statistics broken down by media kind.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.UserId, "The Id of the user the summary belongs to.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.TotalConsumedDurationInSeconds, "The total duration consumed over every recorded session of the user, in seconds.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.CountedSessionCount, "The number of recorded sessions of the user that count towards statistics.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.CompletedSessionCount, "The number of recorded sessions of the user that completed.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.StoppedSessionCount, "The number of recorded sessions of the user that stopped before they completed and count towards statistics.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.CompletionRate, "The fraction of the counted sessions of the user that completed, between 0 and 1, or 0 when there is no counted session.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.MediaKindSummaries, "The consumption statistics of the user broken down by media kind.");
|
||||
ResponseParam<MediaKindConsumptionSummaryDto>(response => response.MediaKind, "The kind of media the breakdown entry belongs to.");
|
||||
ResponseParam<MediaKindConsumptionSummaryDto>(response => response.TotalConsumedDurationInSeconds, "The total duration consumed over every recorded session of the media kind, in seconds.");
|
||||
ResponseParam<MediaKindConsumptionSummaryDto>(response => response.CountedSessionCount, "The number of recorded sessions of the media kind that count towards statistics.");
|
||||
ResponseParam<MediaKindConsumptionSummaryDto>(response => response.CompletedSessionCount, "The number of recorded sessions of the media kind that completed.");
|
||||
ResponseParam<MediaKindConsumptionSummaryDto>(response => response.StoppedSessionCount, "The number of recorded sessions of the media kind that stopped before they completed and count towards statistics.");
|
||||
ResponseParam<MediaKindConsumptionSummaryDto>(response => response.CompletionRate, "The fraction of the counted sessions of the media kind that completed, between 0 and 1, or 0 when there is no counted session.");
|
||||
|
||||
Response(200, "The consumption statistics of every user are returned, or a JSON error with success set to false.",
|
||||
example: new SuccessResponse<AllUsersConsumptionStatisticsDto>(true, new AllUsersConsumptionStatisticsDto(
|
||||
Total: new ConsumptionTotalsDto(
|
||||
TotalConsumedDurationInSeconds: 8744.5,
|
||||
CountedSessionCount: 6,
|
||||
CompletedSessionCount: 4,
|
||||
StoppedSessionCount: 2,
|
||||
CompletionRate: 0.6667,
|
||||
MediaKindSummaries:
|
||||
[
|
||||
new MediaKindConsumptionSummaryDto(
|
||||
MediaKind: MediaKind.MusicTrack,
|
||||
TotalConsumedDurationInSeconds: 1424.5,
|
||||
CountedSessionCount: 4,
|
||||
CompletedSessionCount: 3,
|
||||
StoppedSessionCount: 1,
|
||||
CompletionRate: 0.75
|
||||
),
|
||||
new MediaKindConsumptionSummaryDto(
|
||||
MediaKind: MediaKind.Book,
|
||||
TotalConsumedDurationInSeconds: 7320,
|
||||
CountedSessionCount: 2,
|
||||
CompletedSessionCount: 1,
|
||||
StoppedSessionCount: 1,
|
||||
CompletionRate: 0.5
|
||||
)
|
||||
]),
|
||||
Users:
|
||||
[
|
||||
new ConsumptionSummaryDto(
|
||||
UserId: Guid.Parse("1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d"),
|
||||
TotalConsumedDurationInSeconds: 8744.5,
|
||||
CountedSessionCount: 6,
|
||||
CompletedSessionCount: 4,
|
||||
StoppedSessionCount: 2,
|
||||
CompletionRate: 0.6667,
|
||||
MediaKindSummaries:
|
||||
[
|
||||
new MediaKindConsumptionSummaryDto(
|
||||
MediaKind: MediaKind.MusicTrack,
|
||||
TotalConsumedDurationInSeconds: 1424.5,
|
||||
CountedSessionCount: 4,
|
||||
CompletedSessionCount: 3,
|
||||
StoppedSessionCount: 1,
|
||||
CompletionRate: 0.75
|
||||
)
|
||||
])
|
||||
]))
|
||||
);
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetConsumptionStatistics;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-get-statistics</c> route.
|
||||
/// </summary>
|
||||
public class GetConsumptionStatisticsEndpoint : BaseEndpoint<GetConsumptionStatisticsRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetConsumptionStatisticsEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetConsumptionStatisticsEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.LibraryStatistics.GET_STATISTICS);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Statistics"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the consumption statistics of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user and the optional filters.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetConsumptionStatisticsRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The statistics belong to the selected user, so no intermediary may store them, and the response varies by the sign in cookie.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Cookie";
|
||||
ConsumptionSummaryDto response = await _apiHttpClient.GetAsync<ConsumptionSummaryDto>(BuildStatisticsEndpoint(request), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the API endpoint used to retrieve the consumption statistics of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user and the optional filters.</param>
|
||||
/// <returns>The API endpoint to which the statistics request is sent.</returns>
|
||||
private static string BuildStatisticsEndpoint(GetConsumptionStatisticsRequest request)
|
||||
{
|
||||
// The query string is rebuilt from the typed request values instead of forwarding the raw one, so that crafted text can never alter the upstream URL.
|
||||
StringBuilder endpoint = new(string.IsNullOrWhiteSpace(request.UserId)
|
||||
? ApiRoutes.LibraryStatistics.GET_CONSUMPTION_STATISTICS
|
||||
: ApiRoutes.LibraryStatistics.GET_USER_CONSUMPTION_STATISTICS.Replace("{userId}", Uri.EscapeDataString(request.UserId), StringComparison.Ordinal));
|
||||
List<string> parameters = [];
|
||||
if (!string.IsNullOrWhiteSpace(request.LibraryId))
|
||||
parameters.Add($"libraryId={Uri.EscapeDataString(request.LibraryId)}");
|
||||
if (request.MediaKind is not null)
|
||||
parameters.Add($"mediaKind={Uri.EscapeDataString(request.MediaKind.Value.ToString())}");
|
||||
if (request.FromUtc is not null)
|
||||
parameters.Add($"fromUtc={Uri.EscapeDataString(request.FromUtc.Value.ToString("O", CultureInfo.InvariantCulture))}");
|
||||
if (request.ToUtc is not null)
|
||||
parameters.Add($"toUtc={Uri.EscapeDataString(request.ToUtc.Value.ToString("O", CultureInfo.InvariantCulture))}");
|
||||
if (parameters.Count > 0)
|
||||
endpoint.Append('?').Append(string.Join('&', parameters));
|
||||
return endpoint.ToString();
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetConsumptionStatistics;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetConsumptionStatisticsEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetConsumptionStatisticsEndpointSummary : Summary<GetConsumptionStatisticsEndpoint, GetConsumptionStatisticsRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetConsumptionStatisticsEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetConsumptionStatisticsEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the consumption statistics of the selected user.";
|
||||
Description = "Proxies the request that gets the total consumed duration, the counted sessions, the completed sessions, the stopped sessions, the completion rate, and the per media kind breakdown of the selected user to the API server. When userId is omitted, the statistics of the current user are returned; an administrator can name another user. The date range is inclusive. A failure is returned as a JSON object with success set to false and a localized errorMessage.";
|
||||
|
||||
ExampleRequest = new GetConsumptionStatisticsRequest(
|
||||
UserId: null,
|
||||
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.UserId, "The Id of the user whose statistics are retrieved. Optional; when omitted, the current user is used.");
|
||||
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<SuccessResponse<ConsumptionSummaryDto>>(response => response.IsSuccess, "Whether the operation succeeded.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.UserId, "The Id of the user the statistics belong to.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.TotalConsumedDurationInSeconds, "The total duration consumed over every recorded session, in seconds.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.CountedSessionCount, "The number of recorded sessions that count towards statistics.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.CompletedSessionCount, "The number of recorded sessions that completed.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.StoppedSessionCount, "The number of recorded sessions that stopped before they completed and count towards statistics.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.CompletionRate, "The fraction of the counted sessions that completed, between 0 and 1, or 0 when there is no counted session.");
|
||||
ResponseParam<ConsumptionSummaryDto>(response => response.MediaKindSummaries, "The consumption statistics broken down by media kind.");
|
||||
ResponseParam<MediaKindConsumptionSummaryDto>(response => response.MediaKind, "The kind of media the breakdown entry belongs to.");
|
||||
ResponseParam<MediaKindConsumptionSummaryDto>(response => response.TotalConsumedDurationInSeconds, "The total duration consumed over every recorded session of the media kind, in seconds.");
|
||||
ResponseParam<MediaKindConsumptionSummaryDto>(response => response.CountedSessionCount, "The number of recorded sessions of the media kind that count towards statistics.");
|
||||
ResponseParam<MediaKindConsumptionSummaryDto>(response => response.CompletedSessionCount, "The number of recorded sessions of the media kind that completed.");
|
||||
ResponseParam<MediaKindConsumptionSummaryDto>(response => response.StoppedSessionCount, "The number of recorded sessions of the media kind that stopped before they completed and count towards statistics.");
|
||||
ResponseParam<MediaKindConsumptionSummaryDto>(response => response.CompletionRate, "The fraction of the counted sessions of the media kind that completed, between 0 and 1, or 0 when there is no counted session.");
|
||||
|
||||
Response(200, "The consumption statistics of the selected user are returned, or a JSON error with success set to false.",
|
||||
example: new SuccessResponse<ConsumptionSummaryDto>(true, new ConsumptionSummaryDto(
|
||||
UserId: Guid.Parse("1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d"),
|
||||
TotalConsumedDurationInSeconds: 8744.5,
|
||||
CountedSessionCount: 6,
|
||||
CompletedSessionCount: 4,
|
||||
StoppedSessionCount: 2,
|
||||
CompletionRate: 0.6667,
|
||||
MediaKindSummaries:
|
||||
[
|
||||
new MediaKindConsumptionSummaryDto(
|
||||
MediaKind: MediaKind.MusicTrack,
|
||||
TotalConsumedDurationInSeconds: 1424.5,
|
||||
CountedSessionCount: 4,
|
||||
CompletedSessionCount: 3,
|
||||
StoppedSessionCount: 1,
|
||||
CompletionRate: 0.75
|
||||
),
|
||||
new MediaKindConsumptionSummaryDto(
|
||||
MediaKind: MediaKind.Book,
|
||||
TotalConsumedDurationInSeconds: 7320,
|
||||
CountedSessionCount: 2,
|
||||
CompletedSessionCount: 1,
|
||||
StoppedSessionCount: 1,
|
||||
CompletionRate: 0.5
|
||||
)
|
||||
]))
|
||||
);
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetGenreConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-get-genre-consumption</c> route.
|
||||
/// </summary>
|
||||
public class GetGenreConsumptionEndpoint : BaseEndpoint<GetGenreConsumptionRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetGenreConsumptionEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetGenreConsumptionEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.LibraryStatistics.GET_GENRE_CONSUMPTION);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Statistics"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the genre consumption of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user and the optional filters.</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 statistics belong to the selected user, so no intermediary may store them, and the response varies by the sign in cookie.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Cookie";
|
||||
GenreConsumptionDto[] response = await _apiHttpClient.GetAsync<GenreConsumptionDto[]>(BuildGenreConsumptionEndpoint(request), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the API endpoint used to retrieve the genre consumption of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user and the optional filters.</param>
|
||||
/// <returns>The API endpoint to which the genre request is sent.</returns>
|
||||
private static string BuildGenreConsumptionEndpoint(GetGenreConsumptionRequest request)
|
||||
{
|
||||
// The query string is rebuilt from the typed request values instead of forwarding the raw one, so that crafted text can never alter the upstream URL.
|
||||
StringBuilder endpoint = new(string.IsNullOrWhiteSpace(request.UserId)
|
||||
? ApiRoutes.LibraryStatistics.GET_GENRE_CONSUMPTION
|
||||
: ApiRoutes.LibraryStatistics.GET_USER_GENRE_CONSUMPTION.Replace("{userId}", Uri.EscapeDataString(request.UserId), StringComparison.Ordinal));
|
||||
List<string> parameters = [];
|
||||
if (!string.IsNullOrWhiteSpace(request.LibraryId))
|
||||
parameters.Add($"libraryId={Uri.EscapeDataString(request.LibraryId)}");
|
||||
if (request.MediaKind is not null)
|
||||
parameters.Add($"mediaKind={Uri.EscapeDataString(request.MediaKind.Value.ToString())}");
|
||||
if (request.FromUtc is not null)
|
||||
parameters.Add($"fromUtc={Uri.EscapeDataString(request.FromUtc.Value.ToString("O", CultureInfo.InvariantCulture))}");
|
||||
if (request.ToUtc is not null)
|
||||
parameters.Add($"toUtc={Uri.EscapeDataString(request.ToUtc.Value.ToString("O", CultureInfo.InvariantCulture))}");
|
||||
if (parameters.Count > 0)
|
||||
endpoint.Append('?').Append(string.Join('&', parameters));
|
||||
return endpoint.ToString();
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetGenreConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetGenreConsumptionEndpoint"/> 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 genre consumption of the selected user.";
|
||||
Description = "Proxies the request that gets the genres carried by the media items the selected user consumed to the API server. When userId is omitted, the statistics of the current user are returned; an administrator can name another user. The names are lowercase and grouped across media kinds, so a genre shared by a book and a track appears in one bucket. The date range is inclusive. A failure is returned as a JSON object with success set to false and a localized errorMessage.";
|
||||
|
||||
ExampleRequest = new GetGenreConsumptionRequest(
|
||||
UserId: null,
|
||||
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.UserId, "The Id of the user whose statistics are retrieved. Optional; when omitted, the current user is used.");
|
||||
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<SuccessResponse<GenreConsumptionDto[]>>(response => response.IsSuccess, "Whether the operation succeeded.");
|
||||
ResponseParam<GenreConsumptionDto>(response => response.Name, "The lowercase name of the genre.");
|
||||
ResponseParam<GenreConsumptionDto>(response => response.ConsumedItemCount, "The number of distinct media items that carry the genre and were consumed.");
|
||||
ResponseParam<GenreConsumptionDto>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media items that carry the genre, in seconds.");
|
||||
|
||||
Response(200, "The genre consumption of the selected user is returned, or a JSON error with success set to false.",
|
||||
example: new SuccessResponse<GenreConsumptionDto[]>(true,
|
||||
[
|
||||
new GenreConsumptionDto(
|
||||
Name: "horror",
|
||||
ConsumedItemCount: 3,
|
||||
ConsumedDurationInSeconds: 5400),
|
||||
new GenreConsumptionDto(
|
||||
Name: "fantasy",
|
||||
ConsumedItemCount: 2,
|
||||
ConsumedDurationInSeconds: 7320),
|
||||
new GenreConsumptionDto(
|
||||
Name: "science fiction",
|
||||
ConsumedItemCount: 1,
|
||||
ConsumedDurationInSeconds: 1424.5)
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
+12
-11
@@ -1,28 +1,29 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetMusicPlayStatistics;
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetLibraries;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-get-music-play-statistics</c> route.
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-get-libraries</c> route.
|
||||
/// </summary>
|
||||
public class GetMusicPlayStatisticsEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
public class GetLibrariesEndpoint : BaseEndpoint<EmptyRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMusicPlayStatisticsEndpoint"/> class.
|
||||
/// Initializes a new instance of the <see cref="GetLibrariesEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetMusicPlayStatisticsEndpoint(IApiHttpClient apiHttpClient)
|
||||
public GetLibrariesEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
@@ -34,22 +35,22 @@ public class GetMusicPlayStatisticsEndpoint : BaseEndpoint<EmptyRequest, IResult
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.LibraryStatistics.GET_MUSIC_PLAY_STATISTICS);
|
||||
Routes(WebRoutes.LibraryStatistics.GET_LIBRARIES);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Statistics"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the listening statistics of the current user.
|
||||
/// Retrieves the libraries available for the library filter.
|
||||
/// </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 them, and the response varies by the sign in cookie.
|
||||
// The library list belongs to the current user, so no intermediary may store it, and the response varies by the sign in cookie.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Cookie";
|
||||
MusicPlayStatisticsDto statistics = await _apiHttpClient.GetAsync<MusicPlayStatisticsDto>(ApiRoutes.PlayStatistics.GET_MUSIC_PLAY_STATISTICS, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(statistics);
|
||||
LibraryDto[] response = await _apiHttpClient.GetAsync<LibraryDto[]>(ApiRoutes.Libraries.GET_ENABLED_LIBRARIES, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.Libraries;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetLibraries;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetLibrariesEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibrariesEndpointSummary : Summary<GetLibrariesEndpoint, EmptyRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetLibrariesEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetLibrariesEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the enabled libraries available for the library filter.";
|
||||
Description = "Proxies the request that gets the enabled media libraries available to the current user to the API server. A regular user receives only their own libraries; an administrator receives every enabled library. A failure is returned as a JSON object with success set to false and a localized errorMessage.";
|
||||
|
||||
Response(200, "The enabled media libraries are returned, or a JSON error with success set to false.",
|
||||
example: new SuccessResponse<LibraryDto[]>(true, default));
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetMostConsumed;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-get-most-consumed</c> route.
|
||||
/// </summary>
|
||||
public class GetMostConsumedEndpoint : BaseEndpoint<GetMostConsumedRequest, IResult>
|
||||
{
|
||||
private const int DEFAULT_PAGE_SIZE = 10;
|
||||
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMostConsumedEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetMostConsumedEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.LibraryStatistics.GET_MOST_CONSUMED);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Statistics"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a page of the most consumed media items of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user, the optional filters, and the page bounds.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetMostConsumedRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The history belongs to the selected user, so no intermediary may store it, and the response varies by the sign in cookie.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Cookie";
|
||||
PaginatedDto<ConsumedItemDto> response = await _apiHttpClient.GetAsync<PaginatedDto<ConsumedItemDto>>(BuildHistoryEndpoint(request), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the API endpoint used to retrieve the most consumed media items of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user, the optional filters, and the page bounds.</param>
|
||||
/// <returns>The API endpoint to which the history request is sent.</returns>
|
||||
private static string BuildHistoryEndpoint(GetMostConsumedRequest request)
|
||||
{
|
||||
// The query string is rebuilt from the typed request values instead of forwarding the raw one, so that crafted text can never alter the upstream URL.
|
||||
StringBuilder endpoint = new(string.IsNullOrWhiteSpace(request.UserId)
|
||||
? ApiRoutes.LibraryStatistics.GET_MOST_CONSUMED
|
||||
: ApiRoutes.LibraryStatistics.GET_USER_MOST_CONSUMED.Replace("{userId}", Uri.EscapeDataString(request.UserId), StringComparison.Ordinal));
|
||||
int currentPage = request.CurrentPage ?? 1;
|
||||
int perPage = request.PerPage ?? DEFAULT_PAGE_SIZE;
|
||||
List<string> parameters = [];
|
||||
if (!string.IsNullOrWhiteSpace(request.LibraryId))
|
||||
parameters.Add($"libraryId={Uri.EscapeDataString(request.LibraryId)}");
|
||||
if (request.MediaKind is not null)
|
||||
parameters.Add($"mediaKind={Uri.EscapeDataString(request.MediaKind.Value.ToString())}");
|
||||
if (request.FromUtc is not null)
|
||||
parameters.Add($"fromUtc={Uri.EscapeDataString(request.FromUtc.Value.ToString("O", CultureInfo.InvariantCulture))}");
|
||||
if (request.ToUtc is not null)
|
||||
parameters.Add($"toUtc={Uri.EscapeDataString(request.ToUtc.Value.ToString("O", CultureInfo.InvariantCulture))}");
|
||||
parameters.Add($"currentPage={currentPage.ToString(CultureInfo.InvariantCulture)}");
|
||||
parameters.Add($"perPage={perPage.ToString(CultureInfo.InvariantCulture)}");
|
||||
endpoint.Append('?').Append(string.Join('&', parameters));
|
||||
return endpoint.ToString();
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetMostConsumed;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetMostConsumedEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetMostConsumedEndpointSummary : Summary<GetMostConsumedEndpoint, GetMostConsumedRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMostConsumedEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetMostConsumedEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the most consumed media items of the selected user.";
|
||||
Description = "Proxies the request that gets a page of the most consumed media items of the selected user to the API server. When userId is omitted, the history of the current user is returned; an administrator can name another user. The items are ordered by counted sessions, consumed duration, last consumption date, and media item Id. Music and book sessions appear in the same list. The date range is inclusive. An item whose media item was deleted, or whose library is no longer accessible, is returned with isAvailable set to false and empty display fields. A failure is returned as a JSON object with success set to false and a localized errorMessage.";
|
||||
|
||||
ExampleRequest = new GetMostConsumedRequest(
|
||||
UserId: null,
|
||||
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),
|
||||
CurrentPage: 1,
|
||||
PerPage: 10
|
||||
);
|
||||
|
||||
RequestParam(request => request.UserId, "The Id of the user whose history is retrieved. Optional; when omitted, the current user is used.");
|
||||
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.FromUtc, "The inclusive start of the date range. Optional.");
|
||||
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
|
||||
RequestParam(request => request.CurrentPage, "The one based page of media items to return. Optional. Defaults to 1.");
|
||||
RequestParam(request => request.PerPage, "The number of media items per page. Optional. Defaults to 10.");
|
||||
|
||||
ResponseParam<SuccessResponse<PaginatedDto<ConsumedItemDto>>>(response => response.IsSuccess, "Whether the operation succeeded.");
|
||||
ResponseParam<PaginatedDto<ConsumedItemDto>>(response => response.Data, "The most consumed media items of the requested page, ordered by counted sessions, consumed duration, last consumption date, and media item Id.");
|
||||
ResponseParam<PaginatedDto<ConsumedItemDto>>(response => response.CurrentPage, "The current page number.");
|
||||
ResponseParam<PaginatedDto<ConsumedItemDto>>(response => response.PerPage, "The number of media items retrieved per page.");
|
||||
ResponseParam<PaginatedDto<ConsumedItemDto>>(response => response.Count, "The total number of distinct media items that match the filters.");
|
||||
ResponseParam<PaginatedDto<ConsumedItemDto>>(response => response.NumberOfPages, "The total number of pages.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.MediaKind, "The kind of the consumed media item.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.MediaItemId, "The Id of the consumed media item.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.LibraryId, "The Id of the media library that contains the media item.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.IsAvailable, "Whether the media item still exists and its library is accessible.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.Title, "The title of the media item, or an empty string when the item is not available.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.CollectionTitle, "The title of the collection that contains the media item, or an empty string when there is none.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.CreatorName, "The name of the creator of the media item, or an empty string when there is none.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.CoverPath, "The path of the cover art of the media item, if available.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.LastConsumedOnUtc, "The date and time when the media item was last consumed.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.CountedSessionCount, "The number of consumption sessions of the media item that count towards statistics.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.CompletedSessionCount, "The number of consumption sessions of the media item that completed.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media item, over all of its sessions, in seconds.");
|
||||
|
||||
Response(200, "The requested page of most consumed media items is returned, or a JSON error with success set to false.",
|
||||
example: new SuccessResponse<PaginatedDto<ConsumedItemDto>>(true, new PaginatedDto<ConsumedItemDto>(
|
||||
Data:
|
||||
[
|
||||
new ConsumedItemDto(
|
||||
MediaKind: MediaKind.MusicTrack,
|
||||
MediaItemId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"),
|
||||
LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"),
|
||||
IsAvailable: true,
|
||||
Title: "The Show Must Go On",
|
||||
CollectionTitle: "Innuendo",
|
||||
CreatorName: "Queen",
|
||||
CoverPath: "/artwork/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg",
|
||||
LastConsumedOnUtc: new DateTime(2026, 10, 24, 12, 12, 0, DateTimeKind.Utc),
|
||||
CountedSessionCount: 4,
|
||||
CompletedSessionCount: 3,
|
||||
ConsumedDurationInSeconds: 1424.5),
|
||||
new ConsumedItemDto(
|
||||
MediaKind: MediaKind.Book,
|
||||
MediaItemId: Guid.Parse("7a6b5c4d-3e2f-4a1b-8c9d-0e1f2a3b4c5d"),
|
||||
LibraryId: Guid.Parse("6c7d8e9f-0a1b-4c2d-9e3f-4a5b6c7d8e9f"),
|
||||
IsAvailable: true,
|
||||
Title: "The Fellowship of the Ring",
|
||||
CollectionTitle: string.Empty,
|
||||
CreatorName: "J. R. R. Tolkien",
|
||||
CoverPath: "/artwork/books/7a6b5c4d-3e2f-4a1b-8c9d-0e1f2a3b4c5d/cover.jpg",
|
||||
LastConsumedOnUtc: new DateTime(2026, 10, 23, 20, 40, 0, DateTimeKind.Utc),
|
||||
CountedSessionCount: 2,
|
||||
CompletedSessionCount: 1,
|
||||
ConsumedDurationInSeconds: 7320)
|
||||
],
|
||||
CurrentPage: 1,
|
||||
PerPage: 10,
|
||||
Count: 2,
|
||||
NumberOfPages: 1))
|
||||
);
|
||||
}
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetMostPlayed;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-get-most-played</c> route.
|
||||
/// </summary>
|
||||
public class GetMostPlayedEndpoint : BaseEndpoint<GetMostPlayedRequest, IResult>
|
||||
{
|
||||
private const int DEFAULT_PAGE_SIZE = 10;
|
||||
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetMostPlayedEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetMostPlayedEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.LibraryStatistics.GET_MOST_PLAYED);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Statistics"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a page of the most played tracks 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(GetMostPlayedRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The statistics belong to the authenticated user, so no intermediary may store them, and the response varies by the sign in cookie.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Cookie";
|
||||
// The query string is rebuilt from the typed request values instead of forwarding the raw one, so that crafted text can never alter the upstream URL.
|
||||
int currentPage = request.CurrentPage ?? 1;
|
||||
int perPage = request.PerPage ?? DEFAULT_PAGE_SIZE;
|
||||
string url = ApiRoutes.PlayStatistics.GET_MOST_PLAYED + $"?currentPage={currentPage.ToString(CultureInfo.InvariantCulture)}&perPage={perPage.ToString(CultureInfo.InvariantCulture)}";
|
||||
PaginatedDto<PlayedTrackDto> mostPlayed = await _apiHttpClient.GetAsync<PaginatedDto<PlayedTrackDto>>(url, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(mostPlayed);
|
||||
}
|
||||
}
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetMostPlayed;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetMostPlayedEndpoint"/> 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 = "Proxies the request that gets a page of the most played tracks of the current user to the API server. Each track is returned once, from the most played, with its counted plays, its completed plays and the duration the user listened to it.";
|
||||
|
||||
ExampleRequest = new GetMostPlayedRequest(CurrentPage: 1, PerPage: 10);
|
||||
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 10.");
|
||||
|
||||
ResponseParam<SuccessResponse<PaginatedDto<PlayedTrackDto>>>(response => response.IsSuccess, "Whether the operation succeeded.");
|
||||
ResponseParam<PaginatedDto<PlayedTrackDto>>(response => response.Data, "The most played tracks of the requested page, ordered by counted plays, listened duration, last activity, and track Id.");
|
||||
ResponseParam<PaginatedDto<PlayedTrackDto>>(response => response.CurrentPage, "The current page number.");
|
||||
ResponseParam<PaginatedDto<PlayedTrackDto>>(response => response.PerPage, "The number of tracks retrieved per page.");
|
||||
ResponseParam<PaginatedDto<PlayedTrackDto>>(response => response.Count, "The total number of tracks that match the filters.");
|
||||
ResponseParam<PaginatedDto<PlayedTrackDto>>(response => response.NumberOfPages, "The total number of pages.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.TrackId, "The Id of the track.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.LibraryId, "The Id of the media library that contains the track.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.AlbumId, "The Id of the album that contains the track.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.ArtistId, "The Id of the artist that produced the track.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.Title, "The title of the track, if it still exists and the user can access its library.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.AlbumTitle, "The title of the album that contains the track, if available.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.ArtistName, "The name of the artist that produced the track, if available.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.CoverPath, "The path of the cover art of the album, if available.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.LastPlayedOnUtc, "The date and time of the last recorded activity of the track's most recent play.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.PlayCount, "The number of plays of the track that count as plays.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.CompletedPlayCount, "The number of plays of the track that completed.");
|
||||
ResponseParam<PlayedTrackDto>(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 SuccessResponse<PaginatedDto<PlayedTrackDto>>(true, new PaginatedDto<PlayedTrackDto>(
|
||||
Data:
|
||||
[
|
||||
new PlayedTrackDto(
|
||||
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: 10,
|
||||
Count: 1,
|
||||
NumberOfPages: 1))
|
||||
);
|
||||
}
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetMusicPlayStatistics;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetMusicPlayStatisticsEndpoint"/> 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 = "Proxies the request that gets the total listening time, the counted plays, the completed plays, the stopped plays that count, and the completion rate of the current user to the API server. 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.";
|
||||
|
||||
ResponseParam<SuccessResponse<MusicPlayStatisticsDto>>(response => response.IsSuccess, "Whether the operation succeeded.");
|
||||
ResponseParam<MusicPlayStatisticsDto>(response => response.TotalListeningDurationInSeconds, "The total duration the user listened to, over every recorded play, in seconds.");
|
||||
ResponseParam<MusicPlayStatisticsDto>(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<MusicPlayStatisticsDto>(response => response.CompletedPlayCount, "The number of recorded plays that completed.");
|
||||
ResponseParam<MusicPlayStatisticsDto>(response => response.StoppedPlayCount, "The number of recorded plays that stopped before the track completed and count as plays.");
|
||||
ResponseParam<MusicPlayStatisticsDto>(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 SuccessResponse<MusicPlayStatisticsDto>(true, new MusicPlayStatisticsDto(
|
||||
TotalListeningDurationInSeconds: 93840.5,
|
||||
TotalPlayCount: 512,
|
||||
CompletedPlayCount: 388,
|
||||
StoppedPlayCount: 124,
|
||||
CompletionRate: 0.7578125))
|
||||
);
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetRecentlyConsumed;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-get-recently-consumed</c> route.
|
||||
/// </summary>
|
||||
public class GetRecentlyConsumedEndpoint : BaseEndpoint<GetRecentlyConsumedRequest, IResult>
|
||||
{
|
||||
private const int DEFAULT_PAGE_SIZE = 10;
|
||||
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRecentlyConsumedEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetRecentlyConsumedEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.LibraryStatistics.GET_RECENTLY_CONSUMED);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Statistics"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a page of the recently consumed media items of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user, the optional filters, and the page bounds.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetRecentlyConsumedRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The history belongs to the selected user, so no intermediary may store it, and the response varies by the sign in cookie.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Cookie";
|
||||
PaginatedDto<ConsumedItemDto> response = await _apiHttpClient.GetAsync<PaginatedDto<ConsumedItemDto>>(BuildHistoryEndpoint(request), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the API endpoint used to retrieve the recently consumed media items of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user, the optional filters, and the page bounds.</param>
|
||||
/// <returns>The API endpoint to which the history request is sent.</returns>
|
||||
private static string BuildHistoryEndpoint(GetRecentlyConsumedRequest request)
|
||||
{
|
||||
// The query string is rebuilt from the typed request values instead of forwarding the raw one, so that crafted text can never alter the upstream URL.
|
||||
StringBuilder endpoint = new(string.IsNullOrWhiteSpace(request.UserId)
|
||||
? ApiRoutes.LibraryStatistics.GET_RECENTLY_CONSUMED
|
||||
: ApiRoutes.LibraryStatistics.GET_USER_RECENTLY_CONSUMED.Replace("{userId}", Uri.EscapeDataString(request.UserId), StringComparison.Ordinal));
|
||||
int currentPage = request.CurrentPage ?? 1;
|
||||
int perPage = request.PerPage ?? DEFAULT_PAGE_SIZE;
|
||||
List<string> parameters = [];
|
||||
if (!string.IsNullOrWhiteSpace(request.LibraryId))
|
||||
parameters.Add($"libraryId={Uri.EscapeDataString(request.LibraryId)}");
|
||||
if (request.MediaKind is not null)
|
||||
parameters.Add($"mediaKind={Uri.EscapeDataString(request.MediaKind.Value.ToString())}");
|
||||
if (request.FromUtc is not null)
|
||||
parameters.Add($"fromUtc={Uri.EscapeDataString(request.FromUtc.Value.ToString("O", CultureInfo.InvariantCulture))}");
|
||||
if (request.ToUtc is not null)
|
||||
parameters.Add($"toUtc={Uri.EscapeDataString(request.ToUtc.Value.ToString("O", CultureInfo.InvariantCulture))}");
|
||||
parameters.Add($"currentPage={currentPage.ToString(CultureInfo.InvariantCulture)}");
|
||||
parameters.Add($"perPage={perPage.ToString(CultureInfo.InvariantCulture)}");
|
||||
endpoint.Append('?').Append(string.Join('&', parameters));
|
||||
return endpoint.ToString();
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetRecentlyConsumed;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetRecentlyConsumedEndpoint"/> endpoint, for OpenAPI.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetRecentlyConsumedEndpointSummary : Summary<GetRecentlyConsumedEndpoint, GetRecentlyConsumedRequest>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRecentlyConsumedEndpointSummary"/> class.
|
||||
/// </summary>
|
||||
public GetRecentlyConsumedEndpointSummary()
|
||||
{
|
||||
Summary = "Gets the recently consumed media items of the selected user.";
|
||||
Description = "Proxies the request that gets a page of the recently consumed media items of the selected user to the API server. When userId is omitted, the history of the current user is returned; an administrator can name another user. Music and book sessions appear in the same list. The date range is inclusive. An item whose media item was deleted, or whose library is no longer accessible, is returned with isAvailable set to false and empty display fields. A failure is returned as a JSON object with success set to false and a localized errorMessage.";
|
||||
|
||||
ExampleRequest = new GetRecentlyConsumedRequest(
|
||||
UserId: null,
|
||||
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),
|
||||
CurrentPage: 1,
|
||||
PerPage: 10
|
||||
);
|
||||
|
||||
RequestParam(request => request.UserId, "The Id of the user whose history is retrieved. Optional; when omitted, the current user is used.");
|
||||
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.FromUtc, "The inclusive start of the date range. Optional.");
|
||||
RequestParam(request => request.ToUtc, "The inclusive end of the date range. Optional.");
|
||||
RequestParam(request => request.CurrentPage, "The one based page of media items to return. Optional. Defaults to 1.");
|
||||
RequestParam(request => request.PerPage, "The number of media items per page. Optional. Defaults to 10.");
|
||||
|
||||
ResponseParam<SuccessResponse<PaginatedDto<ConsumedItemDto>>>(response => response.IsSuccess, "Whether the operation succeeded.");
|
||||
ResponseParam<PaginatedDto<ConsumedItemDto>>(response => response.Data, "The recently consumed media items of the requested page, from the most recently consumed.");
|
||||
ResponseParam<PaginatedDto<ConsumedItemDto>>(response => response.CurrentPage, "The current page number.");
|
||||
ResponseParam<PaginatedDto<ConsumedItemDto>>(response => response.PerPage, "The number of media items retrieved per page.");
|
||||
ResponseParam<PaginatedDto<ConsumedItemDto>>(response => response.Count, "The total number of distinct media items that match the filters.");
|
||||
ResponseParam<PaginatedDto<ConsumedItemDto>>(response => response.NumberOfPages, "The total number of pages.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.MediaKind, "The kind of the consumed media item.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.MediaItemId, "The Id of the consumed media item.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.LibraryId, "The Id of the media library that contains the media item.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.IsAvailable, "Whether the media item still exists and its library is accessible.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.Title, "The title of the media item, or an empty string when the item is not available.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.CollectionTitle, "The title of the collection that contains the media item, or an empty string when there is none.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.CreatorName, "The name of the creator of the media item, or an empty string when there is none.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.CoverPath, "The path of the cover art of the media item, if available.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.LastConsumedOnUtc, "The date and time when the media item was last consumed.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.CountedSessionCount, "The number of consumption sessions of the media item that count towards statistics.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.CompletedSessionCount, "The number of consumption sessions of the media item that completed.");
|
||||
ResponseParam<ConsumedItemDto>(response => response.ConsumedDurationInSeconds, "The active duration consumed in the media item, over all of its sessions, in seconds.");
|
||||
|
||||
Response(200, "The requested page of recently consumed media items is returned, or a JSON error with success set to false.",
|
||||
example: new SuccessResponse<PaginatedDto<ConsumedItemDto>>(true, new PaginatedDto<ConsumedItemDto>(
|
||||
Data:
|
||||
[
|
||||
new ConsumedItemDto(
|
||||
MediaKind: MediaKind.MusicTrack,
|
||||
MediaItemId: Guid.Parse("9f0e1d2c-3b4a-4c6d-8e7f-9a0b1c2d3e4f"),
|
||||
LibraryId: Guid.Parse("3b3a19f3-1f5a-4d5a-9a3a-5c5a4a3a2a1a"),
|
||||
IsAvailable: true,
|
||||
Title: "The Show Must Go On",
|
||||
CollectionTitle: "Innuendo",
|
||||
CreatorName: "Queen",
|
||||
CoverPath: "/artwork/albums/e8d52f7b-0a3c-4c2d-ab4f-8a7b6c5d4e3f/cover.jpg",
|
||||
LastConsumedOnUtc: new DateTime(2026, 10, 24, 12, 12, 0, DateTimeKind.Utc),
|
||||
CountedSessionCount: 4,
|
||||
CompletedSessionCount: 3,
|
||||
ConsumedDurationInSeconds: 1424.5),
|
||||
new ConsumedItemDto(
|
||||
MediaKind: MediaKind.Book,
|
||||
MediaItemId: Guid.Parse("7a6b5c4d-3e2f-4a1b-8c9d-0e1f2a3b4c5d"),
|
||||
LibraryId: Guid.Parse("6c7d8e9f-0a1b-4c2d-9e3f-4a5b6c7d8e9f"),
|
||||
IsAvailable: true,
|
||||
Title: "The Fellowship of the Ring",
|
||||
CollectionTitle: string.Empty,
|
||||
CreatorName: "J. R. R. Tolkien",
|
||||
CoverPath: "/artwork/books/7a6b5c4d-3e2f-4a1b-8c9d-0e1f2a3b4c5d/cover.jpg",
|
||||
LastConsumedOnUtc: new DateTime(2026, 10, 23, 20, 40, 0, DateTimeKind.Utc),
|
||||
CountedSessionCount: 2,
|
||||
CompletedSessionCount: 1,
|
||||
ConsumedDurationInSeconds: 7320)
|
||||
],
|
||||
CurrentPage: 1,
|
||||
PerPage: 10,
|
||||
Count: 2,
|
||||
NumberOfPages: 1))
|
||||
);
|
||||
}
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Globalization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetRecentlyPlayed;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-get-recently-played</c> route.
|
||||
/// </summary>
|
||||
public class GetRecentlyPlayedEndpoint : BaseEndpoint<GetRecentlyPlayedRequest, IResult>
|
||||
{
|
||||
private const int DEFAULT_PAGE_SIZE = 10;
|
||||
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRecentlyPlayedEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetRecentlyPlayedEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.LibraryStatistics.GET_RECENTLY_PLAYED);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Statistics"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a page of the recently played tracks 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(GetRecentlyPlayedRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The statistics belong to the authenticated user, so no intermediary may store them, and the response varies by the sign in cookie.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Cookie";
|
||||
// The query string is rebuilt from the typed request values instead of forwarding the raw one, so that crafted text can never alter the upstream URL.
|
||||
int currentPage = request.CurrentPage ?? 1;
|
||||
int perPage = request.PerPage ?? DEFAULT_PAGE_SIZE;
|
||||
string url = ApiRoutes.PlayStatistics.GET_RECENTLY_PLAYED + $"?currentPage={currentPage.ToString(CultureInfo.InvariantCulture)}&perPage={perPage.ToString(CultureInfo.InvariantCulture)}";
|
||||
PaginatedDto<PlayedTrackDto> recentlyPlayed = await _apiHttpClient.GetAsync<PaginatedDto<PlayedTrackDto>>(url, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(recentlyPlayed);
|
||||
}
|
||||
}
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.DTO.Common;
|
||||
using Lumina.Presentation.Web.Common.DTO.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.AudioLibrary.MusicLibrary.PlayHistory;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetRecentlyPlayed;
|
||||
|
||||
/// <summary>
|
||||
/// Class used for providing a textual description for the <see cref="GetRecentlyPlayedEndpoint"/> 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 = "Proxies the request that gets a page of the recently played tracks of the current user to the API server. Each track is returned once, from the most recently played, with its counted plays, its completed plays and the duration the user listened to it.";
|
||||
|
||||
ExampleRequest = new GetRecentlyPlayedRequest(CurrentPage: 1, PerPage: 10);
|
||||
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 10.");
|
||||
|
||||
ResponseParam<SuccessResponse<PaginatedDto<PlayedTrackDto>>>(response => response.IsSuccess, "Whether the operation succeeded.");
|
||||
ResponseParam<PaginatedDto<PlayedTrackDto>>(response => response.Data, "The recently played tracks of the requested page, from the most recently played.");
|
||||
ResponseParam<PaginatedDto<PlayedTrackDto>>(response => response.CurrentPage, "The current page number.");
|
||||
ResponseParam<PaginatedDto<PlayedTrackDto>>(response => response.PerPage, "The number of tracks retrieved per page.");
|
||||
ResponseParam<PaginatedDto<PlayedTrackDto>>(response => response.Count, "The total number of tracks that match the filters.");
|
||||
ResponseParam<PaginatedDto<PlayedTrackDto>>(response => response.NumberOfPages, "The total number of pages.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.TrackId, "The Id of the track.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.LibraryId, "The Id of the media library that contains the track.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.AlbumId, "The Id of the album that contains the track.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.ArtistId, "The Id of the artist that produced the track.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.Title, "The title of the track, if it still exists and the user can access its library.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.AlbumTitle, "The title of the album that contains the track, if available.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.ArtistName, "The name of the artist that produced the track, if available.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.CoverPath, "The path of the cover art of the album, if available.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.LastPlayedOnUtc, "The date and time of the last recorded activity of the track's most recent play.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.PlayCount, "The number of plays of the track that count as plays.");
|
||||
ResponseParam<PlayedTrackDto>(response => response.CompletedPlayCount, "The number of plays of the track that completed.");
|
||||
ResponseParam<PlayedTrackDto>(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 SuccessResponse<PaginatedDto<PlayedTrackDto>>(true, new PaginatedDto<PlayedTrackDto>(
|
||||
Data:
|
||||
[
|
||||
new PlayedTrackDto(
|
||||
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: 10,
|
||||
Count: 1,
|
||||
NumberOfPages: 1))
|
||||
);
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Presentation.Web.Common.Api;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaConsumption;
|
||||
using Lumina.Presentation.Web.Common.Requests.Library.Statistics;
|
||||
using Lumina.Presentation.Web.Common.Routes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Core.Endpoints.Library.Statistics.GetTagConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// API endpoint for the <c>/{culture}/library/statistics/api-get-tag-consumption</c> route.
|
||||
/// </summary>
|
||||
public class GetTagConsumptionEndpoint : BaseEndpoint<GetTagConsumptionRequest, IResult>
|
||||
{
|
||||
private readonly IApiHttpClient _apiHttpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTagConsumptionEndpoint"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiHttpClient">Injected service for interactions with the API.</param>
|
||||
public GetTagConsumptionEndpoint(IApiHttpClient apiHttpClient)
|
||||
{
|
||||
_apiHttpClient = apiHttpClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
base.Configure();
|
||||
Verbs(Http.GET);
|
||||
Routes(WebRoutes.LibraryStatistics.GET_TAG_CONSUMPTION);
|
||||
DontAutoTag();
|
||||
Options(options => options.WithTags("Statistics"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the tag consumption of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user and the optional filters.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override async Task<IResult> ExecuteAsync(GetTagConsumptionRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
// The statistics belong to the selected user, so no intermediary may store them, and the response varies by the sign in cookie.
|
||||
HttpContext.Response.Headers["Cache-Control"] = "private, no-store";
|
||||
HttpContext.Response.Headers["Vary"] = "Cookie";
|
||||
TagConsumptionDto[] response = await _apiHttpClient.GetAsync<TagConsumptionDto[]>(BuildTagConsumptionEndpoint(request), cancellationToken).ConfigureAwait(false);
|
||||
return JsonSuccess(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the API endpoint used to retrieve the tag consumption of the selected user.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the selected user and the optional filters.</param>
|
||||
/// <returns>The API endpoint to which the tag request is sent.</returns>
|
||||
private static string BuildTagConsumptionEndpoint(GetTagConsumptionRequest request)
|
||||
{
|
||||
// The query string is rebuilt from the typed request values instead of forwarding the raw one, so that crafted text can never alter the upstream URL.
|
||||
StringBuilder endpoint = new(string.IsNullOrWhiteSpace(request.UserId)
|
||||
? ApiRoutes.LibraryStatistics.GET_TAG_CONSUMPTION
|
||||
: ApiRoutes.LibraryStatistics.GET_USER_TAG_CONSUMPTION.Replace("{userId}", Uri.EscapeDataString(request.UserId), StringComparison.Ordinal));
|
||||
List<string> parameters = [];
|
||||
if (!string.IsNullOrWhiteSpace(request.LibraryId))
|
||||
parameters.Add($"libraryId={Uri.EscapeDataString(request.LibraryId)}");
|
||||
if (request.MediaKind is not null)
|
||||
parameters.Add($"mediaKind={Uri.EscapeDataString(request.MediaKind.Value.ToString())}");
|
||||
if (request.FromUtc is not null)
|
||||
parameters.Add($"fromUtc={Uri.EscapeDataString(request.FromUtc.Value.ToString("O", CultureInfo.InvariantCulture))}");
|
||||
if (request.ToUtc is not null)
|
||||
parameters.Add($"toUtc={Uri.EscapeDataString(request.ToUtc.Value.ToString("O", CultureInfo.InvariantCulture))}");
|
||||
if (parameters.Count > 0)
|
||||
endpoint.Append('?').Append(string.Join('&', parameters));
|
||||
return endpoint.ToString();
|
||||
}
|
||||
}
|
||||
Loaded 100 of 118 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user