mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17:11:10 +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,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
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user