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
+10
-10
@@ -20,24 +20,24 @@ public class MediaConsumptionRecordEntity : IStorageEntity, IAuditableEntity
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the user that started the consumption session.
|
||||
/// Gets or sets the Id of the user that started the consumption session.
|
||||
/// </summary>
|
||||
public required Guid UserId { get; init; }
|
||||
public required Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the media library that contains the consumed media item.
|
||||
/// Gets or sets the Id of the media library that contains the consumed media item.
|
||||
/// </summary>
|
||||
public required Guid LibraryId { get; init; }
|
||||
public required Guid LibraryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kind of media that was consumed.
|
||||
/// Gets or sets the kind of media that was consumed.
|
||||
/// </summary>
|
||||
public required MediaKind MediaKind { get; init; }
|
||||
public required MediaKind MediaKind { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the consumed media item.
|
||||
/// Gets or sets the Id of the consumed media item.
|
||||
/// </summary>
|
||||
public required Guid MediaItemId { get; init; }
|
||||
public required Guid MediaItemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the state of the consumption session.
|
||||
@@ -45,9 +45,9 @@ public class MediaConsumptionRecordEntity : IStorageEntity, IAuditableEntity
|
||||
public ConsumptionStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time when the consumption session started.
|
||||
/// Gets or sets the date and time when the consumption session started.
|
||||
/// </summary>
|
||||
public required DateTime StartedOnUtc { get; init; }
|
||||
public required DateTime StartedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the consumption session last received activity.
|
||||
|
||||
+8
-8
@@ -20,24 +20,24 @@ public class MediaResumePointEntity : IStorageEntity, IAuditableEntity
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the user that owns the resume point.
|
||||
/// Gets or sets the Id of the user that owns the resume point.
|
||||
/// </summary>
|
||||
public required Guid UserId { get; init; }
|
||||
public required Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the media library that contains the media item.
|
||||
/// Gets or sets the Id of the media library that contains the media item.
|
||||
/// </summary>
|
||||
public required Guid LibraryId { get; init; }
|
||||
public required Guid LibraryId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kind of media that is resumed.
|
||||
/// Gets or sets the kind of media that is resumed.
|
||||
/// </summary>
|
||||
public required MediaKind MediaKind { get; init; }
|
||||
public required MediaKind MediaKind { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the media item to resume.
|
||||
/// Gets or sets the Id of the media item to resume.
|
||||
/// </summary>
|
||||
public required Guid MediaItemId { get; init; }
|
||||
public required Guid MediaItemId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kind of representation used by the position at which the media item can be resumed.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Favorites;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaConsumption;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaContributors;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.MusicLibrary;
|
||||
@@ -167,6 +168,16 @@ public interface IUnitOfWork
|
||||
/// </summary>
|
||||
IFavoriteRepository FavoriteRepository { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media consumption record repository.
|
||||
/// </summary>
|
||||
IMediaConsumptionRecordRepository MediaConsumptionRecordRepository { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the media resume point repository.
|
||||
/// </summary>
|
||||
IMediaResumePointRepository MediaResumePointRepository { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Saves the changes made to the database.
|
||||
/// </summary>
|
||||
|
||||
+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