using Core.Enumerations; using Core.Abstractions.Models; using DomainObjects; using DomainObjects.Enumerations; using DomainObjects.Documents.Posts; using DomainObjects.Documents.Users; using DomainObjects.Documents.Categories; namespace WeatherForecast.Models.Blog.Responses { #region Media attachment /// /// /// public class GetBlogItemSlugMediaAttachmentResponseModel { /// /// /// public string Src { get; set; } /// /// /// public MediaTypes MediaType { get; set; } /// /// /// public string? Alt { get; set; } /// /// /// public string? Target { get; set; } /// /// /// public string? Title { get; set; } /// /// /// public string? Description { get; set; } /// /// /// /// /// public GetBlogItemSlugMediaAttachmentResponseModel(MediaAttachment mediaAttachment, Locales locale) { var l10n = mediaAttachment.L10n.Single(x => x.Locale == locale); Src = mediaAttachment.Src; MediaType = mediaAttachment.MediaType; Alt = l10n.Alt; Target = l10n.Target; Title = l10n.Title; Description = l10n.Description; } } #endregion #region Author /// /// /// public class GetBlogItemSlugAuthorModel : ResponseModelBase { /// /// /// public GetBlogItemSlugMediaAttachmentResponseModel? Avatar { get; set; } /// /// /// public string NickName { get; set; } /// /// /// /// /// public GetBlogItemSlugAuthorModel(User author, Locales locale) { if(author.Avatar != null) Avatar = new GetBlogItemSlugMediaAttachmentResponseModel(author.Avatar, locale); NickName = author.Username; } } #endregion #region Category /// /// /// public class GetBlogItemSlugCategoryResponseModel : ResponseModelBase { /// /// /// public string Slug { get; set; } /// /// /// public string Text { get; set; } /// /// /// /// /// public GetBlogItemSlugCategoryResponseModel(Category category, Locales locale) { var l10n = category.L10n.Single(x => x.Locale == locale); Slug = l10n.Slug; Text = l10n.Text; } } #endregion #region Blog item /// /// /// public class GetBlogItemSlugResponseModel : ResponseModelBase { /// /// /// public string? Slug { get; set; } /// /// /// public string? Description { get; set; } /// /// /// public string? Title { get; set; } /// /// /// public string? ShortText { get; set; } /// /// /// public string? Text { get; set; } /// /// /// public string? PlainText { get; set; } /// /// /// public string? ContentType { get; set; } /// /// /// public List? Badges { get; set; } /// /// /// public List? MediaAttachemnts { get; set; } /// /// /// public GetBlogItemSlugAuthorModel? Author { get; set; } /// /// /// public DateTime Created { get; set; } /// /// /// public List? Tags { get; set; } /// /// /// public List Categories { get; set; } /// /// /// public bool? FamilyFriendly { get; set; } /// /// /// public uint? ReadTime { get; set; } /// /// /// public uint? Likes { get; set; } /// /// /// /// /// /// /// public GetBlogItemSlugResponseModel(BlogDocument blogItem, List categories, User author, Locales locale) { var postItemL10n = blogItem.L10n.Single(x => x.Locale == locale); Slug = postItemL10n.Slug; Badges = postItemL10n.Badges; Title = postItemL10n.Title; ShortText = postItemL10n.ShortText; Text = postItemL10n.Text; PlainText = postItemL10n.PlainText; Badges = postItemL10n.Badges; Created = blogItem.Created; Tags = blogItem.Tags; Categories = categories.Select(x => new GetBlogItemSlugCategoryResponseModel(x, locale)).ToList(); MediaAttachemnts = blogItem.MediaAttachments?.Select(x => new GetBlogItemSlugMediaAttachmentResponseModel(x, locale)).ToList(); Author = new GetBlogItemSlugAuthorModel(author, locale); ReadTime = blogItem.ReadTime; Likes = blogItem.Likes; } } #endregion }