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

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

No files matched your search

@@ -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
);
@@ -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())];
}
}
@@ -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
);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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
);