forked from sim0n00ps/OF-DL
67 lines
1.7 KiB
C#
67 lines
1.7 KiB
C#
using OF_DL.Models.Dtos.Common;
|
|
using OF_DL.Models.Dtos.Highlights;
|
|
using OF_DL.Models.Entities.Common;
|
|
using OF_DL.Models.Entities.Highlights;
|
|
|
|
namespace OF_DL.Models.Mappers;
|
|
|
|
public static class HighlightsMapper
|
|
{
|
|
public static Highlights FromDto(HighlightsDto? dto)
|
|
{
|
|
Highlights mapped = new() { HasMore = dto?.HasMore ?? false };
|
|
|
|
if (dto?.List == null)
|
|
{
|
|
return mapped;
|
|
}
|
|
|
|
foreach (ListItemDto entry in dto.List)
|
|
{
|
|
mapped.List.Add(MapListItem(entry));
|
|
}
|
|
|
|
return mapped;
|
|
}
|
|
|
|
public static HighlightMedia FromDto(HighlightMediaDto? dto)
|
|
{
|
|
HighlightMedia mapped = new();
|
|
|
|
if (dto?.Stories == null)
|
|
{
|
|
return mapped;
|
|
}
|
|
|
|
foreach (StoryDto story in dto.Stories)
|
|
{
|
|
mapped.Stories.Add(MapStory(story));
|
|
}
|
|
|
|
return mapped;
|
|
}
|
|
|
|
private static ListItem MapListItem(ListItemDto dto) => new() { Id = dto.Id };
|
|
|
|
private static Story MapStory(StoryDto dto) =>
|
|
new() { Id = dto.Id, CreatedAt = dto.CreatedAt, Media = MapMedia(dto.Media) };
|
|
|
|
private static List<Medium>? MapMedia(List<MediumDto>? media) =>
|
|
media?.Select(MapMedium).ToList();
|
|
|
|
private static Medium MapMedium(MediumDto dto) =>
|
|
new()
|
|
{
|
|
Id = dto.Id,
|
|
Type = dto.Type,
|
|
CanView = dto.CanView,
|
|
CreatedAt = dto.CreatedAt,
|
|
Files = MapFiles(dto.Files)
|
|
};
|
|
|
|
private static Files? MapFiles(FilesDto? dto) => dto == null ? null : new Files { Full = MapFull(dto.Full) };
|
|
|
|
private static Full? MapFull(FullDto? dto) =>
|
|
dto == null ? null : new Full { Url = dto.Url };
|
|
}
|