diff options
author | crupest <crupest@outlook.com> | 2021-01-07 22:10:58 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-01-07 22:10:58 +0800 |
commit | 04186d5f1091266b85758d4b4255c6a7c1b498f6 (patch) | |
tree | 2ca5678d575eae81f71220896a9862468c93fcc3 | |
parent | 532c6ccd3498a0daabb3d6dbe3f0348f4b2d6a1f (diff) | |
download | timeline-04186d5f1091266b85758d4b4255c6a7c1b498f6.tar.gz timeline-04186d5f1091266b85758d4b4255c6a7c1b498f6.tar.bz2 timeline-04186d5f1091266b85758d4b4255c6a7c1b498f6.zip |
feat: Timeline info contains bookmark and highlight flag.
7 files changed, 95 insertions, 12 deletions
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/BookmarkTimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/BookmarkTimelineTest.cs index e6ae178f..99cf6d3a 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/BookmarkTimelineTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/BookmarkTimelineTest.cs @@ -83,5 +83,43 @@ namespace Timeline.Tests.IntegratedTests h.Should().BeEmpty();
}
}
+
+ [Fact]
+ public async Task TimelineGet_IsBookmarkField_ShouldWork()
+ {
+ using var client = await CreateClientAsUser();
+ await client.TestPostAsync("timelines", new TimelineCreateRequest { Name = "t" });
+
+ {
+ var t = await client.TestGetAsync<HttpTimeline>("timelines/t");
+ t.IsBookmark.Should().BeFalse();
+ }
+
+ await client.TestPutAsync("bookmarks/t");
+
+ {
+ var t = await client.TestGetAsync<HttpTimeline>("timelines/t");
+ t.IsBookmark.Should().BeTrue();
+ }
+
+ {
+ var client1 = await CreateDefaultClient();
+ var t = await client1.TestGetAsync<HttpTimeline>("timelines/t");
+ t.IsBookmark.Should().BeFalse();
+ }
+
+ {
+ var client1 = await CreateClientAsAdministrator();
+ var t = await client1.TestGetAsync<HttpTimeline>("timelines/t");
+ t.IsBookmark.Should().BeFalse();
+ }
+
+ await client.TestDeleteAsync("bookmarks/t");
+
+ {
+ var t = await client.TestGetAsync<HttpTimeline>("timelines/t");
+ t.IsBookmark.Should().BeFalse();
+ }
+ }
}
}
diff --git a/BackEnd/Timeline.Tests/IntegratedTests/HighlightTimelineTest.cs b/BackEnd/Timeline.Tests/IntegratedTests/HighlightTimelineTest.cs index a3f2855e..440759f4 100644 --- a/BackEnd/Timeline.Tests/IntegratedTests/HighlightTimelineTest.cs +++ b/BackEnd/Timeline.Tests/IntegratedTests/HighlightTimelineTest.cs @@ -86,5 +86,38 @@ namespace Timeline.Tests.IntegratedTests h.Should().BeEmpty();
}
}
+
+ [Fact]
+ public async Task TimelineGet_IsHighlighField_Should_Work()
+ {
+ using var client = await CreateClientAsAdministrator();
+ await client.TestPostAsync("timelines", new TimelineCreateRequest { Name = "t" });
+
+ {
+ var t = await client.TestGetAsync<HttpTimeline>("timelines/t");
+ t.IsHighlight.Should().BeFalse();
+ }
+
+ await client.TestPutAsync("highlights/t");
+
+ {
+ var t = await client.TestGetAsync<HttpTimeline>("timelines/t");
+ t.IsHighlight.Should().BeTrue();
+ }
+
+ {
+ var client1 = await CreateDefaultClient();
+ var t = await client1.TestGetAsync<HttpTimeline>("timelines/t");
+ t.IsHighlight.Should().BeTrue();
+ }
+
+ await client.TestDeleteAsync("highlights/t");
+
+ {
+ var t = await client.TestGetAsync<HttpTimeline>("timelines/t");
+ t.IsHighlight.Should().BeFalse();
+ }
+
+ }
}
}
diff --git a/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs b/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs index 4313115e..16793de6 100644 --- a/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs +++ b/BackEnd/Timeline/Controllers/BookmarkTimelineController.cs @@ -40,7 +40,7 @@ namespace Timeline.Controllers {
var ids = await _service.GetBookmarks(this.GetUserId());
var timelines = await _timelineService.GetTimelineList(ids);
- return await _timelineMapper.MapToHttp(timelines, Url);
+ return await _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId());
}
/// <summary>
diff --git a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs index cc19cada..ea012f76 100644 --- a/BackEnd/Timeline/Controllers/HighlightTimelineController.cs +++ b/BackEnd/Timeline/Controllers/HighlightTimelineController.cs @@ -38,7 +38,7 @@ namespace Timeline.Controllers {
var ids = await _service.GetHighlightTimelines();
var timelines = await _timelineService.GetTimelineList(ids);
- return await _timelineMapper.MapToHttp(timelines, Url);
+ return await _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId());
}
/// <summary>
diff --git a/BackEnd/Timeline/Controllers/TimelineController.cs b/BackEnd/Timeline/Controllers/TimelineController.cs index efc49952..b2e37b15 100644 --- a/BackEnd/Timeline/Controllers/TimelineController.cs +++ b/BackEnd/Timeline/Controllers/TimelineController.cs @@ -109,7 +109,7 @@ namespace Timeline.Controllers }
var timelines = await _service.GetTimelines(relationship, visibilityFilter);
- var result = await _timelineMapper.MapToHttp(timelines, Url);
+ var result = await _timelineMapper.MapToHttp(timelines, Url, this.GetOptionalUserId());
return result;
}
@@ -168,7 +168,7 @@ namespace Timeline.Controllers else
{
var t = await _service.GetTimeline(timelineId);
- var result = await _timelineMapper.MapToHttp(t, Url);
+ var result = await _timelineMapper.MapToHttp(t, Url, this.GetOptionalUserId());
return result;
}
}
@@ -363,7 +363,7 @@ namespace Timeline.Controllers }
await _service.ChangeProperty(timelineId, _mapper.Map<TimelineChangePropertyParams>(body));
var t = await _service.GetTimeline(timelineId);
- var result = await _timelineMapper.MapToHttp(t, Url);
+ var result = await _timelineMapper.MapToHttp(t, Url, this.GetOptionalUserId());
return result;
}
@@ -448,7 +448,7 @@ namespace Timeline.Controllers try
{
var timeline = await _service.CreateTimeline(body.Name, userId);
- var result = await _timelineMapper.MapToHttp(timeline, Url);
+ var result = await _timelineMapper.MapToHttp(timeline, Url, this.GetOptionalUserId());
return result;
}
catch (EntityAlreadyExistException e) when (e.EntityName == EntityNames.Timeline)
@@ -507,7 +507,7 @@ namespace Timeline.Controllers {
await _service.ChangeTimelineName(timelineId, body.NewName);
var timeline = await _service.GetTimeline(timelineId);
- return await _timelineMapper.MapToHttp(timeline, Url);
+ return await _timelineMapper.MapToHttp(timeline, Url, this.GetOptionalUserId());
}
catch (EntityAlreadyExistException)
{
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;
}
|