mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Adds media consumption contracts, DTOs, and mappings
This commit is contained in:
1 parent
9247d9fe0f
commit
822ccc9adc
34 files changed
+1374
No files matched your search
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.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="ConsumedDurationMilliseconds">The active duration consumed in the media item, over all of its sessions, in milliseconds.</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,
|
||||
long ConsumedDurationMilliseconds
|
||||
);
|
||||
@@ -0,0 +1,39 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a media consumption session.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the consumption record.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the consumed media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="MediaKind">The kind of media that was consumed.</param>
|
||||
/// <param name="Status">The state of the consumption session.</param>
|
||||
/// <param name="StartedOnUtc">The date and time when the session started.</param>
|
||||
/// <param name="LastActivityOnUtc">The date and time when the session last received activity.</param>
|
||||
/// <param name="EndedOnUtc">The date and time when the session completed or stopped, if it has ended.</param>
|
||||
/// <param name="ConsumedDurationMilliseconds">The active duration consumed by the session, in milliseconds.</param>
|
||||
/// <param name="LastPosition">The last known position for the media item, if any.</param>
|
||||
/// <param name="LastProgressFraction">The latest reported progress fraction of the media item.</param>
|
||||
/// <param name="ConsecutivePagesRead">The number of consecutive pages read in the session.</param>
|
||||
[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; Status: {Status}")]
|
||||
public sealed record ConsumptionRecordDto(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
Guid MediaItemId,
|
||||
MediaKind MediaKind,
|
||||
ConsumptionStatus Status,
|
||||
DateTime StartedOnUtc,
|
||||
DateTime LastActivityOnUtc,
|
||||
DateTime? EndedOnUtc,
|
||||
long ConsumedDurationMilliseconds,
|
||||
MediaPositionDto? LastPosition,
|
||||
double LastProgressFraction,
|
||||
int ConsecutivePagesRead
|
||||
);
|
||||
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.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="TotalConsumedDurationMilliseconds">The total duration consumed over every recorded session, in milliseconds.</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 ConsumptionStatisticsDto(
|
||||
Guid UserId,
|
||||
long TotalConsumedDurationMilliseconds,
|
||||
int CountedSessionCount,
|
||||
int CompletedSessionCount,
|
||||
int StoppedSessionCount,
|
||||
double CompletionRate,
|
||||
IReadOnlyList<MediaKindConsumptionStatisticsDto> MediaKindSummaries
|
||||
);
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the consumption statistics of a user for one kind of media.
|
||||
/// </summary>
|
||||
/// <param name="MediaKind">The kind of media the statistics belong to.</param>
|
||||
/// <param name="TotalConsumedDurationMilliseconds">The total duration consumed over every recorded session of the media kind, in milliseconds.</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, or 0 when there is no counted session.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; CountedSessionCount: {CountedSessionCount}")]
|
||||
public sealed record MediaKindConsumptionStatisticsDto(
|
||||
MediaKind MediaKind,
|
||||
long TotalConsumedDurationMilliseconds,
|
||||
int CountedSessionCount,
|
||||
int CompletedSessionCount,
|
||||
int StoppedSessionCount,
|
||||
double CompletionRate
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for a position reached in a media item during a consumption session.
|
||||
/// </summary>
|
||||
/// <param name="Kind">The kind of representation used by the position.</param>
|
||||
/// <param name="TimeOffsetMilliseconds">The position within the media item, in milliseconds, when the position is a time offset.</param>
|
||||
/// <param name="Location">The opaque locator within the media item, when the position is not a time offset.</param>
|
||||
[DebuggerDisplay("Kind: {Kind}; TimeOffsetMilliseconds: {TimeOffsetMilliseconds}")]
|
||||
public sealed record MediaPositionDto(
|
||||
MediaPositionKind Kind,
|
||||
long? TimeOffsetMilliseconds,
|
||||
string? Location
|
||||
);
|
||||
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DTO.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Data transfer object for the point at which a user can resume consuming a media item.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the resume point.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the media item to resume.</param>
|
||||
/// <param name="MediaKind">The kind of media that is resumed.</param>
|
||||
/// <param name="LastPosition">The position at which the media item can be resumed.</param>
|
||||
/// <param name="LastProgressFraction">The progress fraction at which the media item can be resumed.</param>
|
||||
/// <param name="LastConsumedOnUtc">The date and time when the media item was last consumed.</param>
|
||||
[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; MediaItemId: {MediaItemId}")]
|
||||
public sealed record ResumePointDto(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
Guid MediaItemId,
|
||||
MediaKind MediaKind,
|
||||
MediaPositionDto LastPosition,
|
||||
double LastProgressFraction,
|
||||
DateTime LastConsumedOnUtc
|
||||
);
|
||||
@@ -0,0 +1,21 @@
|
||||
#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.
|
||||
/// </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}")]
|
||||
public sealed record TagConsumptionDto(
|
||||
string Name,
|
||||
TagKind TagKind,
|
||||
int ConsumedItemCount,
|
||||
long ConsumedDurationMilliseconds
|
||||
);
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Repository entity for a media consumption session.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; Status: {Status}")]
|
||||
public class MediaConsumptionRecordEntity : IStorageEntity, IAuditableEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the consumption record.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the user that started the consumption session.
|
||||
/// </summary>
|
||||
public required Guid UserId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the media library that contains the consumed media item.
|
||||
/// </summary>
|
||||
public required Guid LibraryId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kind of media that was consumed.
|
||||
/// </summary>
|
||||
public required MediaKind MediaKind { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the consumed media item.
|
||||
/// </summary>
|
||||
public required Guid MediaItemId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the state of the consumption session.
|
||||
/// </summary>
|
||||
public ConsumptionStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date and time when the consumption session started.
|
||||
/// </summary>
|
||||
public required DateTime StartedOnUtc { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the consumption session last received activity.
|
||||
/// </summary>
|
||||
public DateTime LastActivityOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the consumption session completed or stopped, if it has ended.
|
||||
/// </summary>
|
||||
public DateTime? EndedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the active duration consumed by the session, in milliseconds. It is stored as a whole number of milliseconds so that the
|
||||
/// stored value is independent of the persistence medium's support for time values.
|
||||
/// </summary>
|
||||
public long ConsumedDurationMilliseconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the kind of representation used by the last known position, if the session has a known position.
|
||||
/// </summary>
|
||||
public MediaPositionKind? LastPositionKind { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the last known position within the media item, in milliseconds, when the position is a time offset.
|
||||
/// </summary>
|
||||
public long? LastPositionTimeOffsetMilliseconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the last known opaque locator within the media item, when the position is not a time offset.
|
||||
/// </summary>
|
||||
public string? LastPositionLocation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the latest reported progress fraction of the media item.
|
||||
/// </summary>
|
||||
public double LastProgressFraction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the number of consecutive pages read in the consumption session.
|
||||
/// </summary>
|
||||
public int ConsecutivePagesRead { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the version of the stored row. It is used as an optimistic concurrency token, so that a report that read the record before
|
||||
/// another report changed it can never overwrite the newer state.
|
||||
/// </summary>
|
||||
public long Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
/// </summary>
|
||||
public DateTime? UpdatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Repository entity for the point at which a user can resume consuming a media item.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; MediaItemId: {MediaItemId}")]
|
||||
public class MediaResumePointEntity : IStorageEntity, IAuditableEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Id of the resume point.
|
||||
/// </summary>
|
||||
public required Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the user that owns the resume point.
|
||||
/// </summary>
|
||||
public required Guid UserId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the media library that contains the media item.
|
||||
/// </summary>
|
||||
public required Guid LibraryId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kind of media that is resumed.
|
||||
/// </summary>
|
||||
public required MediaKind MediaKind { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Id of the media item to resume.
|
||||
/// </summary>
|
||||
public required Guid MediaItemId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kind of representation used by the position at which the media item can be resumed.
|
||||
/// </summary>
|
||||
public required MediaPositionKind LastPositionKind { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the position within the media item, in milliseconds, when the position is a time offset.
|
||||
/// </summary>
|
||||
public long? LastPositionTimeOffsetMilliseconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the opaque locator within the media item, when the position is not a time offset.
|
||||
/// </summary>
|
||||
public string? LastPositionLocation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the progress fraction at which the media item can be resumed.
|
||||
/// </summary>
|
||||
public double LastProgressFraction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date and time when the media item was last consumed.
|
||||
/// </summary>
|
||||
public DateTime LastConsumedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the version of the stored row. It is used as an optimistic concurrency token, so that a report that read the resume point before
|
||||
/// another report changed it can never overwrite the newer state.
|
||||
/// </summary>
|
||||
public long Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the time and date when the entity was added.
|
||||
/// </summary>
|
||||
public required DateTime CreatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Id of the user that created the entity.
|
||||
/// </summary>
|
||||
public required Guid CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional time and date when the entity was updated.
|
||||
/// </summary>
|
||||
public DateTime? UpdatedOnUtc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the optional Id of the user that updated the entity.
|
||||
/// </summary>
|
||||
public required Guid? UpdatedBy { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Application.Common.DTO.Pagination;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="ConsumedItemDto"/>.
|
||||
/// </summary>
|
||||
public static class ConsumedItemDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to <see cref="ConsumedItemResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data transfer object to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static ConsumedItemResponse ToResponse(this ConsumedItemDto data)
|
||||
{
|
||||
return new ConsumedItemResponse(
|
||||
data.MediaKind,
|
||||
data.MediaItemId,
|
||||
data.LibraryId,
|
||||
data.IsAvailable,
|
||||
data.Title,
|
||||
data.CollectionTitle,
|
||||
data.CreatorName,
|
||||
data.CoverPath,
|
||||
DateTime.SpecifyKind(data.LastConsumedOnUtc, DateTimeKind.Utc),
|
||||
data.CountedSessionCount,
|
||||
data.CompletedSessionCount,
|
||||
TimeSpan.FromMilliseconds(data.ConsumedDurationMilliseconds).TotalSeconds
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to a paginated collection of <see cref="ConsumedItemResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The paginated data transfer objects to be converted.</param>
|
||||
/// <returns>The converted paginated responses.</returns>
|
||||
public static PaginatedResponse<ConsumedItemResponse> ToResponses(this PaginatedResultDto<ConsumedItemDto> data)
|
||||
{
|
||||
return new PaginatedResponse<ConsumedItemResponse>
|
||||
{
|
||||
Data = [.. data.Data.Select(item => item.ToResponse())],
|
||||
CurrentPage = data.CurrentPage,
|
||||
PerPage = data.PerPage,
|
||||
Count = data.Count,
|
||||
NumberOfPages = data.NumberOfPages
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="ConsumptionRecordDto"/>. This mapping is the record response builder for repository-driven
|
||||
/// single-record reads.
|
||||
/// </summary>
|
||||
public static class ConsumptionRecordDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to <see cref="ConsumptionRecordResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data transfer object to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static ConsumptionRecordResponse ToResponse(this ConsumptionRecordDto data)
|
||||
{
|
||||
return new ConsumptionRecordResponse(
|
||||
data.Id,
|
||||
data.LibraryId,
|
||||
data.MediaItemId,
|
||||
data.MediaKind,
|
||||
data.Status,
|
||||
DateTime.SpecifyKind(data.StartedOnUtc, DateTimeKind.Utc),
|
||||
DateTime.SpecifyKind(data.LastActivityOnUtc, DateTimeKind.Utc),
|
||||
data.EndedOnUtc.HasValue ? DateTime.SpecifyKind(data.EndedOnUtc.Value, DateTimeKind.Utc) : null,
|
||||
TimeSpan.FromMilliseconds(data.ConsumedDurationMilliseconds).TotalSeconds,
|
||||
data.LastPosition?.ToResponse(),
|
||||
data.LastProgressFraction,
|
||||
data.ConsecutivePagesRead
|
||||
);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using System;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="ConsumptionStatisticsDto"/>.
|
||||
/// </summary>
|
||||
public static class ConsumptionStatisticsDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to <see cref="ConsumptionSummaryResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data transfer object to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static ConsumptionSummaryResponse ToResponse(this ConsumptionStatisticsDto data)
|
||||
{
|
||||
return new ConsumptionSummaryResponse(
|
||||
data.UserId,
|
||||
TimeSpan.FromMilliseconds(data.TotalConsumedDurationMilliseconds).TotalSeconds,
|
||||
data.CountedSessionCount,
|
||||
data.CompletedSessionCount,
|
||||
data.StoppedSessionCount,
|
||||
data.CompletionRate,
|
||||
[.. data.MediaKindSummaries.Select(mediaKindSummary => mediaKindSummary.ToResponse())]
|
||||
);
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MediaConsumptionRecordEntity"/>.
|
||||
/// </summary>
|
||||
public static class MediaConsumptionRecordEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="MediaConsumptionRecord"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="MediaConsumptionRecord"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MediaConsumptionRecord> ToDomainEntity(this MediaConsumptionRecordEntity repositoryEntity)
|
||||
{
|
||||
Optional<DateTime> endedOnUtc = repositoryEntity.EndedOnUtc.HasValue
|
||||
? Optional<DateTime>.Some(DateTime.SpecifyKind(repositoryEntity.EndedOnUtc.Value, DateTimeKind.Utc))
|
||||
: Optional<DateTime>.None();
|
||||
|
||||
Optional<MediaPosition> lastPosition = Optional<MediaPosition>.None();
|
||||
if (repositoryEntity.LastPositionKind.HasValue)
|
||||
{
|
||||
MediaPositionKind positionKind = repositoryEntity.LastPositionKind.Value;
|
||||
if (positionKind == MediaPositionKind.TimeOffset)
|
||||
{
|
||||
if (!repositoryEntity.LastPositionTimeOffsetMilliseconds.HasValue ||
|
||||
repositoryEntity.LastPositionTimeOffsetMilliseconds.Value < 0 ||
|
||||
repositoryEntity.LastPositionLocation is not null)
|
||||
return DomainErrors.MediaConsumption.InvalidMediaPosition;
|
||||
lastPosition = Optional<MediaPosition>.Some(
|
||||
MediaPosition.CreateTimeOffset(TimeSpan.FromMilliseconds(repositoryEntity.LastPositionTimeOffsetMilliseconds.Value)));
|
||||
}
|
||||
else if (positionKind == MediaPositionKind.Location)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(repositoryEntity.LastPositionLocation) ||
|
||||
repositoryEntity.LastPositionTimeOffsetMilliseconds.HasValue)
|
||||
return DomainErrors.MediaConsumption.InvalidMediaPosition;
|
||||
lastPosition = Optional<MediaPosition>.Some(MediaPosition.CreateLocation(repositoryEntity.LastPositionLocation));
|
||||
}
|
||||
else
|
||||
return DomainErrors.MediaConsumption.InvalidMediaPosition;
|
||||
}
|
||||
|
||||
return MediaConsumptionRecord.Reconstitute(
|
||||
MediaConsumptionRecordId.Create(repositoryEntity.Id),
|
||||
UserId.Create(repositoryEntity.UserId),
|
||||
LibraryId.Create(repositoryEntity.LibraryId),
|
||||
MediaItemId.Create(repositoryEntity.MediaItemId),
|
||||
repositoryEntity.MediaKind,
|
||||
repositoryEntity.Status,
|
||||
DateTime.SpecifyKind(repositoryEntity.StartedOnUtc, DateTimeKind.Utc),
|
||||
DateTime.SpecifyKind(repositoryEntity.LastActivityOnUtc, DateTimeKind.Utc),
|
||||
endedOnUtc,
|
||||
TimeSpan.FromMilliseconds(repositoryEntity.ConsumedDurationMilliseconds),
|
||||
lastPosition,
|
||||
repositoryEntity.LastProgressFraction,
|
||||
repositoryEntity.ConsecutivePagesRead
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="ConsumptionRecordDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>The converted data transfer object.</returns>
|
||||
public static ConsumptionRecordDto ToDto(this MediaConsumptionRecordEntity repositoryEntity)
|
||||
{
|
||||
MediaPositionDto? lastPosition = null;
|
||||
if (repositoryEntity.LastPositionKind.HasValue)
|
||||
{
|
||||
lastPosition = new MediaPositionDto(
|
||||
repositoryEntity.LastPositionKind.Value,
|
||||
repositoryEntity.LastPositionTimeOffsetMilliseconds,
|
||||
repositoryEntity.LastPositionLocation);
|
||||
}
|
||||
|
||||
return new ConsumptionRecordDto(
|
||||
repositoryEntity.Id,
|
||||
repositoryEntity.LibraryId,
|
||||
repositoryEntity.MediaItemId,
|
||||
repositoryEntity.MediaKind,
|
||||
repositoryEntity.Status,
|
||||
DateTime.SpecifyKind(repositoryEntity.StartedOnUtc, DateTimeKind.Utc),
|
||||
DateTime.SpecifyKind(repositoryEntity.LastActivityOnUtc, DateTimeKind.Utc),
|
||||
repositoryEntity.EndedOnUtc.HasValue ? DateTime.SpecifyKind(repositoryEntity.EndedOnUtc.Value, DateTimeKind.Utc) : null,
|
||||
repositoryEntity.ConsumedDurationMilliseconds,
|
||||
lastPosition,
|
||||
repositoryEntity.LastProgressFraction,
|
||||
repositoryEntity.ConsecutivePagesRead
|
||||
);
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MediaConsumptionRecord"/>. The record is mapped directly to its repository entity and to its response.
|
||||
/// Repository-driven single-record reads map the entity to its DTO and then to the response.
|
||||
/// </summary>
|
||||
public static class MediaConsumptionRecordMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="MediaConsumptionRecordEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static MediaConsumptionRecordEntity ToRepositoryEntity(this MediaConsumptionRecord domainEntity)
|
||||
{
|
||||
return new MediaConsumptionRecordEntity
|
||||
{
|
||||
Id = domainEntity.Id.Value,
|
||||
UserId = domainEntity.UserId.Value,
|
||||
LibraryId = domainEntity.LibraryId.Value,
|
||||
MediaKind = domainEntity.MediaKind,
|
||||
MediaItemId = domainEntity.MediaItemId.Value,
|
||||
Status = domainEntity.Status,
|
||||
StartedOnUtc = domainEntity.StartedOnUtc,
|
||||
LastActivityOnUtc = domainEntity.LastActivityOnUtc,
|
||||
EndedOnUtc = domainEntity.EndedOnUtc.HasValue ? domainEntity.EndedOnUtc.Value : null,
|
||||
// Stored time is truncated to whole milliseconds instead of rounded, so a retried report of the same fractional second maps to
|
||||
// the same stored value and is not rejected as a decrease by the domain.
|
||||
ConsumedDurationMilliseconds = (long)domainEntity.ConsumedDuration.TotalMilliseconds,
|
||||
LastPositionKind = domainEntity.LastPosition.HasValue ? domainEntity.LastPosition.Value.Kind : null,
|
||||
LastPositionTimeOffsetMilliseconds = domainEntity.LastPosition.HasValue && domainEntity.LastPosition.Value.TimeOffset.HasValue
|
||||
? (long)domainEntity.LastPosition.Value.TimeOffset.Value.TotalMilliseconds
|
||||
: null,
|
||||
LastPositionLocation = domainEntity.LastPosition.HasValue && domainEntity.LastPosition.Value.Location.HasValue
|
||||
? domainEntity.LastPosition.Value.Location.Value
|
||||
: null,
|
||||
LastProgressFraction = domainEntity.LastProgressFraction,
|
||||
ConsecutivePagesRead = domainEntity.ConsecutivePagesRead,
|
||||
Version = 1,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
// The audit columns are owned by the auditing interceptor, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="ConsumptionRecordDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted data transfer object.</returns>
|
||||
public static ConsumptionRecordDto ToDto(this MediaConsumptionRecord domainEntity)
|
||||
{
|
||||
return new ConsumptionRecordDto(
|
||||
domainEntity.Id.Value,
|
||||
domainEntity.LibraryId.Value,
|
||||
domainEntity.MediaItemId.Value,
|
||||
domainEntity.MediaKind,
|
||||
domainEntity.Status,
|
||||
DateTime.SpecifyKind(domainEntity.StartedOnUtc, DateTimeKind.Utc),
|
||||
DateTime.SpecifyKind(domainEntity.LastActivityOnUtc, DateTimeKind.Utc),
|
||||
domainEntity.EndedOnUtc.HasValue ? DateTime.SpecifyKind(domainEntity.EndedOnUtc.Value, DateTimeKind.Utc) : null,
|
||||
(long)domainEntity.ConsumedDuration.TotalMilliseconds,
|
||||
domainEntity.LastPosition.HasValue ? domainEntity.LastPosition.Value.ToDto() : null,
|
||||
domainEntity.LastProgressFraction,
|
||||
domainEntity.ConsecutivePagesRead
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="ConsumptionRecordResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static ConsumptionRecordResponse ToResponse(this MediaConsumptionRecord domainEntity)
|
||||
{
|
||||
return new ConsumptionRecordResponse(
|
||||
domainEntity.Id.Value,
|
||||
domainEntity.LibraryId.Value,
|
||||
domainEntity.MediaItemId.Value,
|
||||
domainEntity.MediaKind,
|
||||
domainEntity.Status,
|
||||
DateTime.SpecifyKind(domainEntity.StartedOnUtc, DateTimeKind.Utc),
|
||||
DateTime.SpecifyKind(domainEntity.LastActivityOnUtc, DateTimeKind.Utc),
|
||||
domainEntity.EndedOnUtc.HasValue ? DateTime.SpecifyKind(domainEntity.EndedOnUtc.Value, DateTimeKind.Utc) : null,
|
||||
domainEntity.ConsumedDuration.TotalSeconds,
|
||||
domainEntity.LastPosition.HasValue ? domainEntity.LastPosition.Value.ToResponse() : null,
|
||||
domainEntity.LastProgressFraction,
|
||||
domainEntity.ConsecutivePagesRead
|
||||
);
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MediaKindConsumptionStatisticsDto"/>.
|
||||
/// </summary>
|
||||
public static class MediaKindConsumptionStatisticsDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to <see cref="MediaKindConsumptionSummaryResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data transfer object to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static MediaKindConsumptionSummaryResponse ToResponse(this MediaKindConsumptionStatisticsDto data)
|
||||
{
|
||||
return new MediaKindConsumptionSummaryResponse(
|
||||
data.MediaKind,
|
||||
TimeSpan.FromMilliseconds(data.TotalConsumedDurationMilliseconds).TotalSeconds,
|
||||
data.CountedSessionCount,
|
||||
data.CompletedSessionCount,
|
||||
data.StoppedSessionCount,
|
||||
data.CompletionRate
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MediaPositionDto"/>. This mapping is the position response builder for repository-driven reads.
|
||||
/// </summary>
|
||||
public static class MediaPositionDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to <see cref="MediaPositionResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data transfer object to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static MediaPositionResponse ToResponse(this MediaPositionDto data)
|
||||
{
|
||||
return new MediaPositionResponse(
|
||||
data.Kind,
|
||||
data.TimeOffsetMilliseconds.HasValue ? TimeSpan.FromMilliseconds(data.TimeOffsetMilliseconds.Value).TotalSeconds : null,
|
||||
data.Location
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MediaPosition"/>. The position is mapped directly to its DTO and to its response.
|
||||
/// </summary>
|
||||
public static class MediaPositionMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainValueObject"/> to <see cref="MediaPositionDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainValueObject">The domain value object to be converted.</param>
|
||||
/// <returns>The converted data transfer object.</returns>
|
||||
public static MediaPositionDto ToDto(this MediaPosition domainValueObject)
|
||||
{
|
||||
return new MediaPositionDto(
|
||||
domainValueObject.Kind,
|
||||
domainValueObject.TimeOffset.HasValue ? (long)domainValueObject.TimeOffset.Value.TotalMilliseconds : null,
|
||||
domainValueObject.Location.HasValue ? domainValueObject.Location.Value : null
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainValueObject"/> to <see cref="MediaPositionResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainValueObject">The domain value object to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static MediaPositionResponse ToResponse(this MediaPosition domainValueObject)
|
||||
{
|
||||
return new MediaPositionResponse(
|
||||
domainValueObject.Kind,
|
||||
domainValueObject.TimeOffset.HasValue ? domainValueObject.TimeOffset.Value.TotalSeconds : null,
|
||||
domainValueObject.Location.HasValue ? domainValueObject.Location.Value : null
|
||||
);
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaResumePointAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaResumePointAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using System;
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MediaResumePointEntity"/>.
|
||||
/// </summary>
|
||||
public static class MediaResumePointEntityMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="MediaResumePoint"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="Result{TValue}"/> containing either a successfully converted <see cref="MediaResumePoint"/>, or an error message.
|
||||
/// </returns>
|
||||
public static Result<MediaResumePoint> ToDomainEntity(this MediaResumePointEntity repositoryEntity)
|
||||
{
|
||||
MediaPosition lastPosition;
|
||||
if (repositoryEntity.LastPositionKind == MediaPositionKind.TimeOffset)
|
||||
{
|
||||
if (!repositoryEntity.LastPositionTimeOffsetMilliseconds.HasValue ||
|
||||
repositoryEntity.LastPositionTimeOffsetMilliseconds.Value < 0 ||
|
||||
repositoryEntity.LastPositionLocation is not null)
|
||||
return DomainErrors.MediaConsumption.InvalidMediaPosition;
|
||||
lastPosition = MediaPosition.CreateTimeOffset(TimeSpan.FromMilliseconds(repositoryEntity.LastPositionTimeOffsetMilliseconds.Value));
|
||||
}
|
||||
else if (repositoryEntity.LastPositionKind == MediaPositionKind.Location)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(repositoryEntity.LastPositionLocation) ||
|
||||
repositoryEntity.LastPositionTimeOffsetMilliseconds.HasValue)
|
||||
return DomainErrors.MediaConsumption.InvalidMediaPosition;
|
||||
lastPosition = MediaPosition.CreateLocation(repositoryEntity.LastPositionLocation);
|
||||
}
|
||||
else
|
||||
return DomainErrors.MediaConsumption.InvalidMediaPosition;
|
||||
|
||||
return MediaResumePoint.Reconstitute(
|
||||
MediaResumePointId.Create(repositoryEntity.Id),
|
||||
UserId.Create(repositoryEntity.UserId),
|
||||
LibraryId.Create(repositoryEntity.LibraryId),
|
||||
MediaItemId.Create(repositoryEntity.MediaItemId),
|
||||
repositoryEntity.MediaKind,
|
||||
lastPosition,
|
||||
repositoryEntity.LastProgressFraction,
|
||||
DateTime.SpecifyKind(repositoryEntity.LastConsumedOnUtc, DateTimeKind.Utc),
|
||||
DateTime.SpecifyKind(repositoryEntity.CreatedOnUtc, DateTimeKind.Utc),
|
||||
repositoryEntity.UpdatedOnUtc.HasValue
|
||||
? Optional<DateTime>.Some(DateTime.SpecifyKind(repositoryEntity.UpdatedOnUtc.Value, DateTimeKind.Utc))
|
||||
: Optional<DateTime>.None()
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="repositoryEntity"/> to <see cref="ResumePointDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="repositoryEntity">The repository entity to be converted.</param>
|
||||
/// <returns>The converted data transfer object.</returns>
|
||||
public static ResumePointDto ToDto(this MediaResumePointEntity repositoryEntity)
|
||||
{
|
||||
return new ResumePointDto(
|
||||
repositoryEntity.Id,
|
||||
repositoryEntity.LibraryId,
|
||||
repositoryEntity.MediaItemId,
|
||||
repositoryEntity.MediaKind,
|
||||
new MediaPositionDto(
|
||||
repositoryEntity.LastPositionKind,
|
||||
repositoryEntity.LastPositionTimeOffsetMilliseconds,
|
||||
repositoryEntity.LastPositionLocation),
|
||||
repositoryEntity.LastProgressFraction,
|
||||
DateTime.SpecifyKind(repositoryEntity.LastConsumedOnUtc, DateTimeKind.Utc)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaResumePointAggregate;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="MediaResumePoint"/>. The resume point is mapped directly to its repository entity and to its response.
|
||||
/// Repository-driven single-record reads map the entity to its DTO and then to the response.
|
||||
/// </summary>
|
||||
public static class MediaResumePointMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="MediaResumePointEntity"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted repository entity.</returns>
|
||||
public static MediaResumePointEntity ToRepositoryEntity(this MediaResumePoint domainEntity)
|
||||
{
|
||||
return new MediaResumePointEntity
|
||||
{
|
||||
Id = domainEntity.Id.Value,
|
||||
UserId = domainEntity.UserId.Value,
|
||||
LibraryId = domainEntity.LibraryId.Value,
|
||||
MediaKind = domainEntity.MediaKind,
|
||||
MediaItemId = domainEntity.MediaItemId.Value,
|
||||
LastPositionKind = domainEntity.LastPosition.Kind,
|
||||
LastPositionTimeOffsetMilliseconds = domainEntity.LastPosition.TimeOffset.HasValue
|
||||
? (long)domainEntity.LastPosition.TimeOffset.Value.TotalMilliseconds
|
||||
: null,
|
||||
LastPositionLocation = domainEntity.LastPosition.Location.HasValue
|
||||
? domainEntity.LastPosition.Location.Value
|
||||
: null,
|
||||
LastProgressFraction = domainEntity.LastProgressFraction,
|
||||
LastConsumedOnUtc = domainEntity.LastConsumedOnUtc,
|
||||
Version = 1,
|
||||
CreatedOnUtc = domainEntity.CreatedOnUtc,
|
||||
CreatedBy = Guid.Empty,
|
||||
// The audit columns are owned by the auditing interceptor, so they are never mapped here.
|
||||
UpdatedOnUtc = null,
|
||||
UpdatedBy = null
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="ResumePointDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted data transfer object.</returns>
|
||||
public static ResumePointDto ToDto(this MediaResumePoint domainEntity)
|
||||
{
|
||||
return new ResumePointDto(
|
||||
domainEntity.Id.Value,
|
||||
domainEntity.LibraryId.Value,
|
||||
domainEntity.MediaItemId.Value,
|
||||
domainEntity.MediaKind,
|
||||
domainEntity.LastPosition.ToDto(),
|
||||
domainEntity.LastProgressFraction,
|
||||
DateTime.SpecifyKind(domainEntity.LastConsumedOnUtc, DateTimeKind.Utc)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="domainEntity"/> to <see cref="ResumePointResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="domainEntity">The domain entity to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static ResumePointResponse ToResponse(this MediaResumePoint domainEntity)
|
||||
{
|
||||
return new ResumePointResponse(
|
||||
domainEntity.Id.Value,
|
||||
domainEntity.LibraryId.Value,
|
||||
domainEntity.MediaItemId.Value,
|
||||
domainEntity.MediaKind,
|
||||
domainEntity.LastPosition.ToResponse(),
|
||||
domainEntity.LastProgressFraction,
|
||||
DateTime.SpecifyKind(domainEntity.LastConsumedOnUtc, DateTimeKind.Utc)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="ResumePointDto"/>. This mapping is the resume point response builder for repository-driven
|
||||
/// single-record reads.
|
||||
/// </summary>
|
||||
public static class ResumePointDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to <see cref="ResumePointResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data transfer object to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static ResumePointResponse ToResponse(this ResumePointDto data)
|
||||
{
|
||||
return new ResumePointResponse(
|
||||
data.Id,
|
||||
data.LibraryId,
|
||||
data.MediaItemId,
|
||||
data.MediaKind,
|
||||
data.LastPosition.ToResponse(),
|
||||
data.LastProgressFraction,
|
||||
DateTime.SpecifyKind(data.LastConsumedOnUtc, DateTimeKind.Utc)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DTO.MediaConsumption;
|
||||
using Lumina.Contracts.Responses.MediaConsumption;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.Mapping.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for converting <see cref="TagConsumptionDto"/>.
|
||||
/// </summary>
|
||||
public static class TagConsumptionDtoMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to <see cref="TagConsumptionResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data transfer object to be converted.</param>
|
||||
/// <returns>The converted response.</returns>
|
||||
public static TagConsumptionResponse ToResponse(this TagConsumptionDto data)
|
||||
{
|
||||
return new TagConsumptionResponse(
|
||||
data.Name,
|
||||
data.TagKind,
|
||||
data.ConsumedItemCount,
|
||||
TimeSpan.FromMilliseconds(data.ConsumedDurationMilliseconds).TotalSeconds
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <paramref name="data"/> to a collection of <see cref="TagConsumptionResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="data">The data transfer objects to be converted.</param>
|
||||
/// <returns>The converted responses.</returns>
|
||||
public static IReadOnlyList<TagConsumptionResponse> ToResponses(this IReadOnlyList<TagConsumptionDto> data)
|
||||
{
|
||||
return [.. data.Select(item => item.ToResponse())];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to report that a media consumption session completed.
|
||||
/// </summary>
|
||||
/// <param name="Position">The final position reported for the media item, if the client knows it. Optional.</param>
|
||||
/// <param name="ProgressFraction">The fraction of the media item that the client reached, between 0 and 1. Required.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed by the session, in seconds. Required.</param>
|
||||
[DebuggerDisplay("ProgressFraction: {ProgressFraction}; ConsumedDurationInSeconds: {ConsumedDurationInSeconds}")]
|
||||
public sealed record CompleteConsumptionRequest(
|
||||
MediaPositionRequest? Position,
|
||||
double ProgressFraction,
|
||||
double ConsumedDurationInSeconds
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to report a position in a media consumption session.
|
||||
/// </summary>
|
||||
/// <param name="Kind">The kind of the position. Required.</param>
|
||||
/// <param name="TimeOffsetSeconds">The position within the media item, in seconds, when the position is a time offset. Optional.</param>
|
||||
/// <param name="Location">The opaque locator within the media item, when the position is not a time offset. Optional.</param>
|
||||
[DebuggerDisplay("Kind: {Kind}; TimeOffsetSeconds: {TimeOffsetSeconds}")]
|
||||
public sealed record MediaPositionRequest(
|
||||
string? Kind,
|
||||
double? TimeOffsetSeconds,
|
||||
string? Location
|
||||
);
|
||||
@@ -0,0 +1,20 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to report the progress of a media consumption session.
|
||||
/// </summary>
|
||||
/// <param name="Position">The last position reported for the media item, if the client knows it. Optional.</param>
|
||||
/// <param name="ProgressFraction">The fraction of the media item that the client reached, between 0 and 1. Required.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed by the session, in seconds. Required.</param>
|
||||
/// <param name="ConsecutivePagesRead">The number of consecutive pages read in the current session, used by page based media such as books and ignored for other kinds. Defaults to 0. Optional.</param>
|
||||
[DebuggerDisplay("ProgressFraction: {ProgressFraction}; ConsumedDurationInSeconds: {ConsumedDurationInSeconds}; ConsecutivePagesRead: {ConsecutivePagesRead}")]
|
||||
public sealed record ReportConsumptionProgressRequest(
|
||||
MediaPositionRequest? Position,
|
||||
double ProgressFraction,
|
||||
double ConsumedDurationInSeconds,
|
||||
int ConsecutivePagesRead = 0
|
||||
);
|
||||
@@ -0,0 +1,18 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Requests.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a request to report that a media consumption session stopped.
|
||||
/// </summary>
|
||||
/// <param name="Position">The final position reported for the media item, if the client knows it. Optional.</param>
|
||||
/// <param name="ProgressFraction">The fraction of the media item that the client reached, between 0 and 1. Required.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed by the session, in seconds. Required.</param>
|
||||
[DebuggerDisplay("ProgressFraction: {ProgressFraction}; ConsumedDurationInSeconds: {ConsumedDurationInSeconds}")]
|
||||
public sealed record StopConsumptionRequest(
|
||||
MediaPositionRequest? Position,
|
||||
double ProgressFraction,
|
||||
double ConsumedDurationInSeconds
|
||||
);
|
||||
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents 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 ConsumedItemResponse(
|
||||
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,39 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a media consumption session.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the consumption record.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the consumed media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the consumed media item.</param>
|
||||
/// <param name="MediaKind">The kind of media that was consumed.</param>
|
||||
/// <param name="Status">The state of the consumption session.</param>
|
||||
/// <param name="StartedOnUtc">The date and time when the session started.</param>
|
||||
/// <param name="LastActivityOnUtc">The date and time when the session last received activity.</param>
|
||||
/// <param name="EndedOnUtc">The date and time when the session completed or stopped, if it has ended.</param>
|
||||
/// <param name="ConsumedDurationInSeconds">The active duration consumed by the session, in seconds.</param>
|
||||
/// <param name="LastPosition">The last known position for the media item, if any.</param>
|
||||
/// <param name="LastProgressFraction">The latest reported progress fraction of the media item.</param>
|
||||
/// <param name="ConsecutivePagesRead">The number of consecutive pages read in the session.</param>
|
||||
[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; Status: {Status}")]
|
||||
public sealed record ConsumptionRecordResponse(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
Guid MediaItemId,
|
||||
MediaKind MediaKind,
|
||||
ConsumptionStatus Status,
|
||||
DateTime StartedOnUtc,
|
||||
DateTime LastActivityOnUtc,
|
||||
DateTime? EndedOnUtc,
|
||||
double ConsumedDurationInSeconds,
|
||||
MediaPositionResponse? LastPosition,
|
||||
double LastProgressFraction,
|
||||
int ConsecutivePagesRead
|
||||
);
|
||||
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents 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 ConsumptionSummaryResponse(
|
||||
Guid UserId,
|
||||
double TotalConsumedDurationInSeconds,
|
||||
int CountedSessionCount,
|
||||
int CompletedSessionCount,
|
||||
int StoppedSessionCount,
|
||||
double CompletionRate,
|
||||
IReadOnlyList<MediaKindConsumptionSummaryResponse> MediaKindSummaries
|
||||
);
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the consumption statistics of a user for 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, or 0 when there is no counted session.</param>
|
||||
[DebuggerDisplay("MediaKind: {MediaKind}; CountedSessionCount: {CountedSessionCount}")]
|
||||
public sealed record MediaKindConsumptionSummaryResponse(
|
||||
MediaKind MediaKind,
|
||||
double TotalConsumedDurationInSeconds,
|
||||
int CountedSessionCount,
|
||||
int CompletedSessionCount,
|
||||
int StoppedSessionCount,
|
||||
double CompletionRate
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a position reached in a media item during a consumption session.
|
||||
/// </summary>
|
||||
/// <param name="Kind">The kind of representation used by the position.</param>
|
||||
/// <param name="TimeOffsetSeconds">The position within the media item, in seconds, when the position is a time offset.</param>
|
||||
/// <param name="Location">The opaque locator within the media item, when the position is not a time offset.</param>
|
||||
[DebuggerDisplay("Kind: {Kind}; TimeOffsetSeconds: {TimeOffsetSeconds}")]
|
||||
public sealed record MediaPositionResponse(
|
||||
MediaPositionKind Kind,
|
||||
double? TimeOffsetSeconds,
|
||||
string? Location
|
||||
);
|
||||
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Responses.MediaConsumption;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the point at which a user can resume consuming a media item.
|
||||
/// </summary>
|
||||
/// <param name="Id">The Id of the resume point.</param>
|
||||
/// <param name="LibraryId">The Id of the media library that contains the media item.</param>
|
||||
/// <param name="MediaItemId">The Id of the media item to resume.</param>
|
||||
/// <param name="MediaKind">The kind of media that is resumed.</param>
|
||||
/// <param name="LastPosition">The position at which the media item can be resumed.</param>
|
||||
/// <param name="LastProgressFraction">The progress fraction at which the media item can be resumed.</param>
|
||||
/// <param name="LastConsumedOnUtc">The date and time when the media item was last consumed.</param>
|
||||
[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; MediaItemId: {MediaItemId}")]
|
||||
public sealed record ResumePointResponse(
|
||||
Guid Id,
|
||||
Guid LibraryId,
|
||||
Guid MediaItemId,
|
||||
MediaKind MediaKind,
|
||||
MediaPositionResponse LastPosition,
|
||||
double LastProgressFraction,
|
||||
DateTime LastConsumedOnUtc
|
||||
);
|
||||
@@ -0,0 +1,21 @@
|
||||
#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.
|
||||
/// </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}")]
|
||||
public sealed record TagConsumptionResponse(
|
||||
string Name,
|
||||
TagKind TagKind,
|
||||
int ConsumedItemCount,
|
||||
double ConsumedDurationInSeconds
|
||||
);
|
||||
@@ -0,0 +1,17 @@
|
||||
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
|
||||
}
|
||||
@@ -14,6 +14,8 @@ public static partial class Errors
|
||||
public static Error UnsupportedMediaKind => Error.Validation(description: nameof(UnsupportedMediaKind));
|
||||
public static Error MediaKindCannotStartCompleted => Error.Forbidden(description: nameof(MediaKindCannotStartCompleted));
|
||||
public static Error MediaKindCannotResume => Error.Forbidden(description: nameof(MediaKindCannotResume));
|
||||
public static Error ConsumptionRecordNotFound => Error.NotFound(description: nameof(ConsumptionRecordNotFound));
|
||||
public static Error MediaResumePointNotFound => Error.NotFound(description: nameof(MediaResumePointNotFound));
|
||||
public static Error InvalidMediaPosition => Error.Validation(description: nameof(InvalidMediaPosition));
|
||||
public static Error InvalidProgressFraction => Error.Validation(description: nameof(InvalidProgressFraction));
|
||||
public static Error ConsumedDurationMustBeNonNegative => Error.Validation(description: nameof(ConsumedDurationMustBeNonNegative));
|
||||
|
||||
Reference in new issue
Block a user