Major refactor #141

Merged
sim0n00ps merged 55 commits from whimsical-c4lic0/OF-DL:refactor-architecture into master 2026-02-13 00:21:58 +00:00
10 changed files with 161 additions and 228 deletions
Showing only changes of commit 9766636d04 - Show all commits

View File

@ -17,9 +17,9 @@ public class ListItem
public List<object>? Preview { get; set; }
public FromUser FromUser { get; set; } = new();
public FromUser? FromUser { get; set; }
public Author Author { get; set; } = new();
public Author? Author { get; set; }
public long Id { get; set; }

View File

@ -28,7 +28,7 @@ public static class ArchivedMapper
{
Id = dto.Id,
PostedAt = dto.PostedAt,
Author = MapAuthor(dto.Author),
Author = CommonMapper.MapAuthor(dto.Author),
Text = dto.Text,
Price = dto.Price,
IsOpened = dto.IsOpened,
@ -37,25 +37,8 @@ public static class ArchivedMapper
Preview = dto.Preview
};
private static Entities.Common.Author? MapAuthor(AuthorDto? dto)
{
if (dto == null)
{
return null;
}
return new Entities.Common.Author { Id = dto.Id };
}
private static List<Medium>? MapMedia(List<MediumDto>? media)
{
if (media == null)
{
return null;
}
return media.Select(MapMedium).ToList();
}
private static List<Medium>? MapMedia(List<MediumDto>? media) =>
media == null ? null : media.Select(MapMedium).ToList();
private static Medium MapMedium(MediumDto dto) =>
new()
@ -67,50 +50,7 @@ public static class ArchivedMapper
Preview = dto.Preview
};
private static Entities.Common.Files? MapFiles(FilesDto? dto)
{
if (dto == null)
{
return null;
}
return new Entities.Common.Files { Full = MapFull(dto.Full), Drm = MapDrm(dto.Drm) };
}
private static Entities.Common.Full? MapFull(FullDto? dto) =>
dto == null ? null : new Entities.Common.Full { Url = dto.Url };
private static Entities.Common.Drm? MapDrm(DrmDto? dto)
{
if (dto == null)
{
return null;
}
return new Entities.Common.Drm
{
Manifest = MapManifest(dto.Manifest), Signature = MapSignature(dto.Signature)
};
}
private static Entities.Common.Manifest? MapManifest(ManifestDto? dto) =>
dto == null ? null : new Entities.Common.Manifest { Dash = dto.Dash };
private static Entities.Common.Signature? MapSignature(SignatureDto? dto) =>
dto == null ? null : new Entities.Common.Signature { Dash = MapDash(dto.Dash) };
private static Entities.Common.Dash? MapDash(DashDto? dto)
{
if (dto == null)
{
return null;
}
return new Entities.Common.Dash
{
CloudFrontPolicy = dto.CloudFrontPolicy,
CloudFrontSignature = dto.CloudFrontSignature,
CloudFrontKeyPairId = dto.CloudFrontKeyPairId
};
}
private static Entities.Common.Files? MapFiles(FilesDto? dto) => dto == null
? null
: new Entities.Common.Files { Full = CommonMapper.MapFull(dto.Full), Drm = CommonMapper.MapDrm(dto.Drm) };
}

View File

@ -0,0 +1,115 @@
using OF_DL.Models.Dtos.Common;
using OF_DL.Models.Entities.Common;
namespace OF_DL.Models.Mappers;
public static class CommonMapper
{
public static Author? MapAuthor(AuthorDto? dto)
{
if (dto == null || dto.Id == 0)
{
return null;
}
return new Author { Id = dto.Id };
}
private static Dash? MapDash(DashDto? dto)
{
if (dto == null || (
string.IsNullOrEmpty(dto.CloudFrontPolicy) &&
string.IsNullOrEmpty(dto.CloudFrontSignature) &&
string.IsNullOrEmpty(dto.CloudFrontKeyPairId)))
{
return null;
}
return new Dash
{
CloudFrontPolicy = dto.CloudFrontPolicy,
CloudFrontSignature = dto.CloudFrontSignature,
CloudFrontKeyPairId = dto.CloudFrontKeyPairId
};
}
public static Drm? MapDrm(DrmDto? dto)
{
if (dto == null || (dto.Manifest == new ManifestDto() && dto.Signature == new SignatureDto()))
{
return null;
}
return new Drm { Manifest = MapManifest(dto.Manifest), Signature = MapSignature(dto.Signature) };
}
public static Files? MapFiles(FilesDto? dto)
{
if (dto == null)
{
return null;
}
Full? full = MapFull(dto.Full);
Preview? preview = MapPreview(dto.Preview);
Drm? drm = MapDrm(dto.Drm);
if (full == null && preview == null && drm == null)
{
return null;
}
return new Files { Full = MapFull(dto.Full), Preview = MapPreview(dto.Preview), Drm = MapDrm(dto.Drm) };
}
public static Full? MapFull(FullDto? dto)
{
if (dto == null || string.IsNullOrEmpty(dto.Url))
{
return null;
}
return new Full { Url = dto.Url };
}
public static Manifest? MapManifest(ManifestDto? dto)
{
if (dto == null || string.IsNullOrEmpty(dto.Dash))
{
return null;
}
return new Manifest { Dash = dto.Dash };
}
public static Preview? MapPreview(PreviewDto? dto)
{
if (dto == null || string.IsNullOrEmpty(dto.Url))
{
return null;
}
return new Preview { Url = dto.Url };
}
public static Signature? MapSignature(SignatureDto? dto)
{
if (dto == null)
{
return null;
}
Dash? dash = MapDash(dto.Dash);
return dash == null ? null : new Signature { Dash = dash };
}
public static VideoSources? MapVideoSources(VideoSourcesDto? dto)
{
if (dto == null || (string.IsNullOrEmpty(dto._240) && string.IsNullOrEmpty(dto._720)))
{
return null;
}
return new VideoSources { _240 = dto._240, _720 = dto._720 };
}
}

View File

@ -59,8 +59,6 @@ public static class HighlightsMapper
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 };
private static Files? MapFiles(FilesDto? dto) =>
dto == null ? null : new Files { Full = CommonMapper.MapFull(dto.Full) };
}

View File

@ -63,35 +63,17 @@ public static class MessagesMapper
private static List<MessageEntities.Medium>? MapMedia(List<MediumDto>? media) =>
media?.Select(MapMedium).ToList();
private static FromUser? MapFromUser(FromUserDto? dto) =>
dto?.Id == null ? null : new FromUser { Id = (long)dto.Id };
private static Files? MapFiles(FilesDto? dto) =>
dto == null ? null : new Files { Full = MapFull(dto.Full), Drm = MapDrm(dto.Drm) };
private static Full? MapFull(FullDto? dto) => dto == null ? null : new Full { Url = dto.Url };
private static Drm? MapDrm(DrmDto? dto) => dto == null
? null
: new Drm { Manifest = MapManifest(dto.Manifest), Signature = MapSignature(dto.Signature) };
private static Manifest? MapManifest(ManifestDto? dto) => dto == null ? null : new Manifest { Dash = dto.Dash };
private static Signature? MapSignature(SignatureDto? dto) =>
dto == null ? null : new Signature { Dash = MapDash(dto.Dash) };
private static Dash? MapDash(DashDto? dto)
private static FromUser? MapFromUser(FromUserDto? dto)
{
if (dto == null)
if (dto?.Id == null || dto.Id == 0)
{
return null;
}
return new Dash
{
CloudFrontPolicy = dto.CloudFrontPolicy,
CloudFrontSignature = dto.CloudFrontSignature,
CloudFrontKeyPairId = dto.CloudFrontKeyPairId
};
return new FromUser { Id = dto.Id.Value };
}
private static Files? MapFiles(FilesDto? dto) => dto == null
? null
: new Files { Full = CommonMapper.MapFull(dto.Full), Drm = CommonMapper.MapDrm(dto.Drm) };
}

View File

@ -36,7 +36,7 @@ public static class PostMapper
mapped.Id = dto.Id;
mapped.PostedAt = dto.PostedAt;
mapped.Author = MapSingleAuthor(dto.Author);
mapped.Author = CommonMapper.MapAuthor(dto.Author);
mapped.Text = dto.Text;
mapped.RawText = dto.RawText;
mapped.IsOpened = dto.IsOpened;
@ -53,7 +53,7 @@ public static class PostMapper
{
Id = dto.Id,
PostedAt = dto.PostedAt,
Author = MapAuthor(dto.Author),
Author = CommonMapper.MapAuthor(dto.Author),
Text = dto.Text,
RawText = dto.RawText,
IsOpened = dto.IsOpened,
@ -63,12 +63,6 @@ public static class PostMapper
Preview = dto.Preview
};
private static Author? MapAuthor(AuthorDto? dto) =>
dto == null ? null : new Author { Id = dto.Id };
private static Author? MapSingleAuthor(AuthorDto? dto) =>
dto == null ? null : new Author { Id = dto.Id };
private static List<Medium>? MapMedia(List<MediumDto>? media) =>
media?.Select(MapMedium).ToList();
@ -84,39 +78,12 @@ public static class PostMapper
private static Files? MapFiles(FilesDto? dto) => dto == null
? null
: new Files { Full = MapFull(dto.Full), Preview = MapPreview(dto.Preview), Drm = MapDrm(dto.Drm) };
private static Full? MapFull(FullDto? dto) =>
dto == null || string.IsNullOrEmpty(dto.Url) ? null : new Full { Url = dto.Url };
private static Preview? MapPreview(PreviewDto? dto) =>
dto == null || string.IsNullOrEmpty(dto.Url) ? null : new Preview { Url = dto.Url };
private static Drm MapDrm(DrmDto? dto) => new()
{
Manifest = MapManifest(dto?.Manifest), Signature = MapSignature(dto?.Signature)
};
private static Manifest? MapManifest(ManifestDto? dto) =>
dto == null ? null : new Manifest { Dash = dto.Dash };
private static Signature? MapSignature(SignatureDto? dto) =>
dto == null ? null : new Signature { Dash = MapDash(dto.Dash) };
private static Dash? MapDash(DashDto? dto)
{
if (dto == null)
: new Files
{
return null;
}
return new Dash
{
CloudFrontPolicy = dto.CloudFrontPolicy,
CloudFrontSignature = dto.CloudFrontSignature,
CloudFrontKeyPairId = dto.CloudFrontKeyPairId
Full = CommonMapper.MapFull(dto.Full),
Preview = CommonMapper.MapPreview(dto.Preview),
Drm = CommonMapper.MapDrm(dto.Drm)
};
}
private static List<Medium>? MapSingleMedia(List<MediumDto>? media) =>
media?.Select(MapSingleMedium).ToList();
@ -129,7 +96,7 @@ public static class PostMapper
CanView = dto.CanView,
Preview = dto.Preview,
Files = MapSingleFiles(dto.Files),
VideoSources = MapVideoSources(dto.VideoSources)
VideoSources = CommonMapper.MapVideoSources(dto.VideoSources)
};
private static Files? MapSingleFiles(FilesDto? dto)
@ -141,42 +108,9 @@ public static class PostMapper
return new Files
{
Full = MapSingleFull(dto.Full), Preview = MapSinglePreview(dto.Preview), Drm = MapSingleDrm(dto.Drm)
Full = CommonMapper.MapFull(dto.Full),
Preview = CommonMapper.MapPreview(dto.Preview),
Drm = CommonMapper.MapDrm(dto.Drm)
};
}
private static Full? MapSingleFull(FullDto? dto) =>
dto == null || string.IsNullOrEmpty(dto.Url) ? null : new Full { Url = dto.Url };
private static Preview? MapSinglePreview(PreviewDto? dto) =>
dto == null || string.IsNullOrEmpty(dto.Url) ? null : new Preview { Url = dto.Url };
private static Drm? MapSingleDrm(DrmDto? dto) => dto == null
? null
: new Drm { Manifest = MapSingleManifest(dto.Manifest), Signature = MapSingleSignature(dto.Signature) };
private static Manifest? MapSingleManifest(ManifestDto? dto) =>
dto == null ? null : new Manifest { Dash = dto.Dash };
private static Signature? MapSingleSignature(SignatureDto? dto) =>
dto == null ? null : new Signature { Dash = MapSingleDash(dto.Dash) };
private static Dash? MapSingleDash(DashDto? dto)
{
if (dto == null)
{
return null;
}
return new Dash
{
CloudFrontPolicy = dto.CloudFrontPolicy,
CloudFrontSignature = dto.CloudFrontSignature,
CloudFrontKeyPairId = dto.CloudFrontKeyPairId
};
}
private static VideoSources? MapVideoSources(VideoSourcesDto? dto) => dto == null
? null
: new VideoSources { _240 = dto._240, _720 = dto._720 };
}

View File

@ -1,5 +1,4 @@
using OF_DL.Models.Dtos.Purchased;
using OF_DL.Models.Dtos.Common;
using MessageDtos = OF_DL.Models.Dtos.Messages;
using CommonEntities = OF_DL.Models.Entities.Common;
using MessageEntities = OF_DL.Models.Entities.Messages;
@ -42,14 +41,18 @@ public static class PurchasedMapper
Previews = dto.Previews,
Preview = dto.Preview,
FromUser = MapFromUser(dto.FromUser),
Author = MapAuthor(dto.Author)
Author = CommonMapper.MapAuthor(dto.Author)
};
private static CommonEntities.FromUser MapFromUser(FromUserDto? dto) =>
dto == null ? new CommonEntities.FromUser() : new CommonEntities.FromUser { Id = dto.Id };
private static CommonEntities.FromUser? MapFromUser(FromUserDto? dto)
{
if (dto == null || dto.Id == 0)
{
return null;
}
private static CommonEntities.Author MapAuthor(AuthorDto? dto) =>
dto == null ? new CommonEntities.Author() : new CommonEntities.Author { Id = dto.Id };
return new CommonEntities.FromUser { Id = dto.Id };
}
private static List<MessageEntities.Medium>? MapMedia(List<MessageDtos.MediumDto>? media) =>
media?.Select(MessagesMapper.MapMedium).ToList();

View File

@ -26,7 +26,6 @@ public static class StoriesMapper
Files = MapFiles(dto.Files)
};
private static Files MapFiles(FilesDto? dto) => new() { Full = MapFull(dto?.Full) };
private static Full MapFull(FullDto? dto) => new() { Url = dto?.Url };
private static Files MapFiles(FilesDto? dto) =>
new() { Full = CommonMapper.MapFull(dto?.Full) };
}

View File

@ -29,7 +29,7 @@ public static class StreamsMapper
{
Id = dto.Id,
PostedAt = dto.PostedAt,
Author = MapAuthor(dto.Author),
Author = CommonMapper.MapAuthor(dto.Author),
Text = dto.Text,
RawText = dto.RawText,
Price = dto.Price,
@ -39,9 +39,6 @@ public static class StreamsMapper
Preview = dto.Preview
};
private static Author? MapAuthor(AuthorDto? dto) =>
dto == null ? null : new Author { Id = dto.Id };
private static List<Medium>? MapMedia(List<MediumDto>? media) =>
media?.Select(MapMedium).ToList();
@ -55,7 +52,7 @@ public static class StreamsMapper
return null;
}
Full? full = MapFull(dto.Full);
Full? full = CommonMapper.MapFull(dto.Full);
Drm? drm = MapDrm(dto.Drm);
if (full == null && drm == null)
@ -66,43 +63,15 @@ public static class StreamsMapper
return new Files { Full = full, Drm = drm };
}
private static Full? MapFull(FullDto? dto) =>
dto == null || string.IsNullOrEmpty(dto.Url) ? null : new Full { Url = dto.Url };
private static Drm? MapDrm(DrmDto? dto)
{
if (dto?.Manifest == null || string.IsNullOrEmpty(dto.Manifest.Dash))
Manifest? manifest = CommonMapper.MapManifest(dto?.Manifest);
if (manifest == null)
{
return null;
}
Dash? dash = MapDash(dto.Signature.Dash);
if (dash == null)
{
return null;
}
return new Drm
{
Manifest = new Manifest { Dash = dto.Manifest.Dash }, Signature = new Signature { Dash = dash }
};
}
private static Dash? MapDash(DashDto? dto)
{
if (dto == null ||
string.IsNullOrEmpty(dto.CloudFrontPolicy) ||
string.IsNullOrEmpty(dto.CloudFrontSignature) ||
string.IsNullOrEmpty(dto.CloudFrontKeyPairId))
{
return null;
}
return new Dash
{
CloudFrontPolicy = dto.CloudFrontPolicy,
CloudFrontSignature = dto.CloudFrontSignature,
CloudFrontKeyPairId = dto.CloudFrontKeyPairId
};
Signature? signature = CommonMapper.MapSignature(dto?.Signature);
return signature == null ? null : new Drm { Manifest = manifest, Signature = signature };
}
}

View File

@ -22,15 +22,8 @@ public static class UserListsMapper
return mapped;
}
public static List<UsersList> FromDto(List<UsersListDto>? dto)
{
if (dto == null)
{
return [];
}
return dto.Select(MapUsersList).ToList();
}
public static List<UsersList> FromDto(List<UsersListDto>? dto) =>
dto == null ? [] : dto.Select(MapUsersList).ToList();
private static UserListItem MapListItem(UserListItemDto dto) =>
new() { Id = dto.Id, Name = dto.Name };