aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Models/Http/Timeline.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-07-10 15:36:51 +0800
committercrupest <crupest@outlook.com>2020-07-10 15:36:51 +0800
commitbac1c733f276ad0f449b4c60e5662d0413cd2121 (patch)
tree1aa30945ccb448e41621d6b4744c0b729c0c2e18 /Timeline/Models/Http/Timeline.cs
parent838f9377514b03404afa1d6b6e42e981174178b5 (diff)
downloadtimeline-bac1c733f276ad0f449b4c60e5662d0413cd2121.tar.gz
timeline-bac1c733f276ad0f449b4c60e5662d0413cd2121.tar.bz2
timeline-bac1c733f276ad0f449b4c60e5662d0413cd2121.zip
Add deleted field.
Diffstat (limited to 'Timeline/Models/Http/Timeline.cs')
-rw-r--r--Timeline/Models/Http/Timeline.cs15
1 files changed, 11 insertions, 4 deletions
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<TimelinePost, TimelinePostInfo, TimelinePostContentInfo>
+ public class TimelinePostContentResolver : IValueResolver<TimelinePost, TimelinePostInfo, TimelinePostContentInfo?>
{
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<Timeline, TimelineInfo>().ForMember(u => u._links, opt => opt.MapFrom<TimelineInfoLinksValueResolver>());
- CreateMap<TimelinePost, TimelinePostInfo>().ForMember(p => p.Content, opt => opt.MapFrom<TimelinePostContentResolver>());
+ CreateMap<TimelinePost, TimelinePostInfo>().ForMember(p => p.Content, opt => opt.MapFrom<TimelinePostContentResolver>())
+ .ForMember(p => p.Deleted, opt => opt.MapFrom((source, dest) => { return source.Content == null; }));
CreateMap<TimelinePatchRequest, TimelineChangePropertyRequest>();
}
}