From 01c3c5800f9b8a7b89d98b28ea748d496497c0b2 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 13 Feb 2021 15:09:21 +0800 Subject: feat: Post info add editable field. --- BackEnd/Timeline/Models/Mapper/TimelineMapper.cs | 37 ++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'BackEnd/Timeline/Models/Mapper/TimelineMapper.cs') diff --git a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs index 5c46fa81..191e2f70 100644 --- a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs +++ b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs @@ -16,13 +16,17 @@ namespace Timeline.Models.Mapper private readonly UserMapper _userMapper; private readonly IHighlightTimelineService _highlightTimelineService; private readonly IBookmarkTimelineService _bookmarkTimelineService; + private readonly ITimelineService _timelineService; + private readonly ITimelinePostService _timelinePostService; - public TimelineMapper(DatabaseContext database, UserMapper userMapper, IHighlightTimelineService highlightTimelineService, IBookmarkTimelineService bookmarkTimelineService) + public TimelineMapper(DatabaseContext database, UserMapper userMapper, IHighlightTimelineService highlightTimelineService, IBookmarkTimelineService bookmarkTimelineService, ITimelineService timelineService, ITimelinePostService timelinePostService) { _database = database; _userMapper = userMapper; _highlightTimelineService = highlightTimelineService; _bookmarkTimelineService = bookmarkTimelineService; + _timelineService = timelineService; + _timelinePostService = timelinePostService; } public async Task MapToHttp(TimelineEntity entity, IUrlHelper urlHelper, long? userId) @@ -64,7 +68,7 @@ namespace Timeline.Models.Mapper } - public async Task MapToHttp(TimelinePostEntity entity, string timelineName, IUrlHelper urlHelper) + public async Task MapToHttp(TimelinePostEntity entity, string timelineName, IUrlHelper urlHelper, long? userId, bool isAdministrator) { _ = timelineName; @@ -79,6 +83,22 @@ namespace Timeline.Models.Mapper author = await _userMapper.MapToHttp(entity.Author, urlHelper); } + bool editable; + + if (userId is null) + { + editable = false; + } + else if (isAdministrator) + { + editable = true; + } + else + { + editable = await _timelinePostService.HasPostModifyPermission(entity.TimelineId, entity.LocalId, userId.Value); + } + + return new HttpTimelinePost( id: entity.LocalId, dataList: dataDigestList, @@ -86,18 +106,25 @@ namespace Timeline.Models.Mapper author: author, color: entity.Color, deleted: entity.Deleted, - lastUpdated: entity.LastUpdated + lastUpdated: entity.LastUpdated, + timelineName: timelineName, + editable: editable ); } - public async Task> MapToHttp(List entities, string timelineName, IUrlHelper urlHelper) + public async Task> MapToHttp(List entities, string timelineName, IUrlHelper urlHelper, long? userId, bool isAdministrator) { var result = new List(); foreach (var entity in entities) { - result.Add(await MapToHttp(entity, timelineName, urlHelper)); + result.Add(await MapToHttp(entity, timelineName, urlHelper, userId, isAdministrator)); } return result; } + + internal Task MapToHttp(TimelinePostEntity post, string timeline, IUrlHelper url) + { + throw new System.NotImplementedException(); + } } } -- cgit v1.2.3