From b347fcf45abdae58352cf07e24ec907e1f77a31a Mon Sep 17 00:00:00 2001 From: crupest Date: Fri, 10 Jul 2020 15:36:51 +0800 Subject: Add deleted field. --- Timeline/Models/Http/Timeline.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'Timeline/Models/Http/Timeline.cs') diff --git a/Timeline/Models/Http/Timeline.cs b/Timeline/Models/Http/Timeline.cs index 80e6e69d..aad9aa7b 100644 --- a/Timeline/Models/Http/Timeline.cs +++ b/Timeline/Models/Http/Timeline.cs @@ -18,7 +18,8 @@ namespace Timeline.Models.Http public class TimelinePostInfo { public long Id { get; set; } - public TimelinePostContentInfo Content { get; set; } = default!; + public TimelinePostContentInfo? Content { get; set; } + public bool Deleted { get; set; } public DateTime Time { get; set; } public UserInfo Author { get; set; } = default!; public DateTime LastUpdated { get; set; } = default!; @@ -73,7 +74,7 @@ namespace Timeline.Models.Http } } - public class TimelinePostContentResolver : IValueResolver + public class TimelinePostContentResolver : IValueResolver { private readonly IActionContextAccessor _actionContextAccessor; private readonly IUrlHelperFactory _urlHelperFactory; @@ -84,13 +85,18 @@ namespace Timeline.Models.Http _urlHelperFactory = urlHelperFactory; } - public TimelinePostContentInfo Resolve(TimelinePost source, TimelinePostInfo destination, TimelinePostContentInfo destMember, ResolutionContext context) + public TimelinePostContentInfo? Resolve(TimelinePost source, TimelinePostInfo destination, TimelinePostContentInfo? destMember, ResolutionContext context) { var actionContext = _actionContextAccessor.AssertActionContextForUrlFill(); var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext); var sourceContent = source.Content; + if (sourceContent == null) + { + return null; + } + if (sourceContent is TextTimelinePostContent textContent) { return new TimelinePostContentInfo @@ -122,7 +128,8 @@ namespace Timeline.Models.Http public TimelineInfoAutoMapperProfile() { CreateMap().ForMember(u => u._links, opt => opt.MapFrom()); - CreateMap().ForMember(p => p.Content, opt => opt.MapFrom()); + CreateMap().ForMember(p => p.Content, opt => opt.MapFrom()) + .ForMember(p => p.Deleted, opt => opt.MapFrom((source, dest) => { return source.Content == null; })); CreateMap(); } } -- cgit v1.2.3