Adds the media consumption lifecycle commands and repository wiring

This commit is contained in:
BinaryAlley committed 2026-10-24 17:07:31 +03:00
1 parent 2ffacb5360
commit bde7ee4b1f
30 files changed
+1962 -28

No files matched your search

@@ -0,0 +1,30 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaConsumption.Commands.CompleteConsumption;
using Lumina.Contracts.Requests.MediaConsumption;
#endregion
namespace Lumina.Application.Common.Mapping.MediaConsumption;
/// <summary>
/// Extension methods for converting <see cref="CompleteConsumptionRequest"/>.
/// </summary>
public static class CompleteConsumptionRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="CompleteConsumptionCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <param name="consumptionRecordId">The Id of the consumption record, taken from the route.</param>
/// <returns>The converted command.</returns>
public static CompleteConsumptionCommand ToCommand(this CompleteConsumptionRequest request, string? consumptionRecordId)
{
return new CompleteConsumptionCommand(
consumptionRecordId,
request.Position?.Kind,
request.Position?.TimeOffsetSeconds,
request.Position?.Location,
request.ProgressFraction,
request.ConsumedDurationInSeconds
);
}
}
@@ -0,0 +1,31 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaConsumption.Commands.ReportConsumptionProgress;
using Lumina.Contracts.Requests.MediaConsumption;
#endregion
namespace Lumina.Application.Common.Mapping.MediaConsumption;
/// <summary>
/// Extension methods for converting <see cref="ReportConsumptionProgressRequest"/>.
/// </summary>
public static class ReportConsumptionProgressRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="ReportConsumptionProgressCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <param name="consumptionRecordId">The Id of the consumption record, taken from the route.</param>
/// <returns>The converted command.</returns>
public static ReportConsumptionProgressCommand ToCommand(this ReportConsumptionProgressRequest request, string? consumptionRecordId)
{
return new ReportConsumptionProgressCommand(
consumptionRecordId,
request.Position?.Kind,
request.Position?.TimeOffsetSeconds,
request.Position?.Location,
request.ProgressFraction,
request.ConsumedDurationInSeconds,
request.ConsecutivePagesRead
);
}
}
@@ -0,0 +1,30 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.MediaConsumption.Commands.StopConsumption;
using Lumina.Contracts.Requests.MediaConsumption;
#endregion
namespace Lumina.Application.Common.Mapping.MediaConsumption;
/// <summary>
/// Extension methods for converting <see cref="StopConsumptionRequest"/>.
/// </summary>
public static class StopConsumptionRequestMapping
{
/// <summary>
/// Converts <paramref name="request"/> to <see cref="StopConsumptionCommand"/>.
/// </summary>
/// <param name="request">The request to be converted.</param>
/// <param name="consumptionRecordId">The Id of the consumption record, taken from the route.</param>
/// <returns>The converted command.</returns>
public static StopConsumptionCommand ToCommand(this StopConsumptionRequest request, string? consumptionRecordId)
{
return new StopConsumptionCommand(
consumptionRecordId,
request.Position?.Kind,
request.Position?.TimeOffsetSeconds,
request.Position?.Location,
request.ProgressFraction,
request.ConsumedDurationInSeconds
);
}
}
@@ -59,9 +59,7 @@ public static class LibraryEntityMapping
if (pathTemplateResult.IsFailure)
return pathTemplateResult.Errors;
LibraryConsumptionSettings consumptionSettings = LibraryConsumptionSettings.Create(
repositoryEntity.ShouldTrackConsumptionProgress,
Optional<int>.FromNullable(repositoryEntity.CompletionThresholdPercentage));
LibraryConsumptionSettings consumptionSettings = repositoryEntity.ToDomainValueObject();
return Library.Create(
LibraryId.Create(repositoryEntity.Id),
@@ -81,6 +79,18 @@ public static class LibraryEntityMapping
);
}
/// <summary>
/// Converts the consumption settings stored on <paramref name="repositoryEntity"/> to <see cref="LibraryConsumptionSettings"/>.
/// </summary>
/// <param name="repositoryEntity">The repository entity whose consumption settings are converted.</param>
/// <returns>The converted consumption settings.</returns>
public static LibraryConsumptionSettings ToDomainValueObject(this LibraryEntity repositoryEntity)
{
return LibraryConsumptionSettings.Create(
repositoryEntity.ShouldTrackConsumptionProgress,
Optional<int>.FromNullable(repositoryEntity.CompletionThresholdPercentage));
}
/// <summary>
/// Builds the path template of a media library from its ordered stored parts.
/// </summary>