mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11:10 +00:00
Adds the media consumption lifecycle commands and repository wiring
This commit is contained in:
1 parent
2ffacb5360
commit
bde7ee4b1f
30 files changed
+1962
-28
No files matched your search
+30
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
+31
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
+30
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
+13
-3
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user