aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Models
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-01-07 22:13:24 +0800
committerGitHub <noreply@github.com>2021-01-07 22:13:24 +0800
commit34b2304997bfac1e186dad660ec62d8d87fec75f (patch)
tree2ca5678d575eae81f71220896a9862468c93fcc3 /BackEnd/Timeline/Models
parente701f8bab033dd364673215e66d58a1cb9fea339 (diff)
parent04186d5f1091266b85758d4b4255c6a7c1b498f6 (diff)
downloadtimeline-34b2304997bfac1e186dad660ec62d8d87fec75f.tar.gz
timeline-34b2304997bfac1e186dad660ec62d8d87fec75f.tar.bz2
timeline-34b2304997bfac1e186dad660ec62d8d87fec75f.zip
Merge pull request #204 from crupest/back-dev
Timeline info includes highlight and bookmark info.
Diffstat (limited to 'BackEnd/Timeline/Models')
-rw-r--r--BackEnd/Timeline/Models/Http/Timeline.cs8
-rw-r--r--BackEnd/Timeline/Models/Mapper/TimelineMapper.cs14
2 files changed, 17 insertions, 5 deletions
diff --git a/BackEnd/Timeline/Models/Http/Timeline.cs b/BackEnd/Timeline/Models/Http/Timeline.cs
index 06fa4e5a..5e5889f6 100644
--- a/BackEnd/Timeline/Models/Http/Timeline.cs
+++ b/BackEnd/Timeline/Models/Http/Timeline.cs
@@ -86,7 +86,7 @@ namespace Timeline.Models.Http
{
public HttpTimeline() { }
- public HttpTimeline(string uniqueId, string title, string name, DateTime nameLastModifed, string description, HttpUser owner, TimelineVisibility visibility, List<HttpUser> members, DateTime createTime, DateTime lastModified, HttpTimelineLinks links)
+ public HttpTimeline(string uniqueId, string title, string name, DateTime nameLastModifed, string description, HttpUser owner, TimelineVisibility visibility, List<HttpUser> members, DateTime createTime, DateTime lastModified, bool isHighlight, bool isBookmark, HttpTimelineLinks links)
{
UniqueId = uniqueId;
Title = title;
@@ -98,6 +98,8 @@ namespace Timeline.Models.Http
Members = members;
CreateTime = createTime;
LastModified = lastModified;
+ IsHighlight = isHighlight;
+ IsBookmark = isBookmark;
_links = links;
}
@@ -144,6 +146,10 @@ namespace Timeline.Models.Http
/// </summary>
public DateTime LastModified { get; set; } = default!;
+ public bool IsHighlight { get; set; }
+
+ public bool IsBookmark { get; set; }
+
#pragma warning disable CA1707 // Identifiers should not contain underscores
/// <summary>
/// Related links.
diff --git a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs
index 14ca8fe9..95418573 100644
--- a/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs
+++ b/BackEnd/Timeline/Models/Mapper/TimelineMapper.cs
@@ -15,14 +15,18 @@ namespace Timeline.Models.Mapper
{
private readonly DatabaseContext _database;
private readonly UserMapper _userMapper;
+ private readonly IHighlightTimelineService _highlightTimelineService;
+ private readonly IBookmarkTimelineService _bookmarkTimelineService;
- public TimelineMapper(DatabaseContext database, UserMapper userMapper)
+ public TimelineMapper(DatabaseContext database, UserMapper userMapper, IHighlightTimelineService highlightTimelineService, IBookmarkTimelineService bookmarkTimelineService)
{
_database = database;
_userMapper = userMapper;
+ _highlightTimelineService = highlightTimelineService;
+ _bookmarkTimelineService = bookmarkTimelineService;
}
- public async Task<HttpTimeline> MapToHttp(TimelineEntity entity, IUrlHelper urlHelper)
+ public async Task<HttpTimeline> MapToHttp(TimelineEntity entity, IUrlHelper urlHelper, long? userId)
{
await _database.Entry(entity).Reference(e => e.Owner).LoadAsync();
await _database.Entry(entity).Collection(e => e.Members).Query().Include(m => m.User).LoadAsync();
@@ -40,6 +44,8 @@ namespace Timeline.Models.Mapper
members: await _userMapper.MapToHttp(entity.Members.Select(m => m.User).ToList(), urlHelper),
createTime: entity.CreateTime,
lastModified: entity.LastModified,
+ isHighlight: await _highlightTimelineService.IsHighlightTimeline(entity.Id),
+ isBookmark: userId is not null && await _bookmarkTimelineService.IsBookmark(userId.Value, entity.Id, false, false),
links: new HttpTimelineLinks(
self: urlHelper.ActionLink(nameof(TimelineController.TimelineGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { timeline = timelineName }),
posts: urlHelper.ActionLink(nameof(TimelineController.PostListGet), nameof(TimelineController)[0..^nameof(Controller).Length], new { timeline = timelineName })
@@ -47,12 +53,12 @@ namespace Timeline.Models.Mapper
);
}
- public async Task<List<HttpTimeline>> MapToHttp(List<TimelineEntity> entities, IUrlHelper urlHelper)
+ public async Task<List<HttpTimeline>> MapToHttp(List<TimelineEntity> entities, IUrlHelper urlHelper, long? userId)
{
var result = new List<HttpTimeline>();
foreach (var entity in entities)
{
- result.Add(await MapToHttp(entity, urlHelper));
+ result.Add(await MapToHttp(entity, urlHelper, userId));
}
return result;
}