From b5ea38b6606fea50ac4bc42dc4109dcff258b44b Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 12 Jul 2020 15:54:09 +0800 Subject: Add api in service. --- Timeline.Tests/Services/TimelineServiceTest.cs | 30 ++++++++++++++++ Timeline/Services/TimelineService.cs | 50 ++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/Timeline.Tests/Services/TimelineServiceTest.cs b/Timeline.Tests/Services/TimelineServiceTest.cs index 123c2b7f..919400a3 100644 --- a/Timeline.Tests/Services/TimelineServiceTest.cs +++ b/Timeline.Tests/Services/TimelineServiceTest.cs @@ -56,6 +56,36 @@ namespace Timeline.Tests.Services _eTagGenerator.Dispose(); } + [Theory] + [InlineData("@user")] + [InlineData("tl")] + public async Task Timeline_GetLastModified(string timelineName) + { + var time = _clock.ForwardCurrentTime(); + + var _ = TimelineHelper.ExtractTimelineName(timelineName, out var isPersonal); + if (!isPersonal) + await _timelineService.CreateTimeline(timelineName, await _userService.GetUserIdByUsername("user")); + + var t = await _timelineService.GetTimelineLastModifiedTime(timelineName); + + t.Should().Be(time); + } + + [Theory] + [InlineData("@user")] + [InlineData("tl")] + public async Task Timeline_GetUnqiueId(string timelineName) + { + var _ = TimelineHelper.ExtractTimelineName(timelineName, out var isPersonal); + if (!isPersonal) + await _timelineService.CreateTimeline(timelineName, await _userService.GetUserIdByUsername("user")); + + var uniqueId = await _timelineService.GetTimelineUniqueId(timelineName); + + uniqueId.Should().NotBeNullOrEmpty(); + } + [Theory] [InlineData("@user")] [InlineData("tl")] diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index a0d72ad3..eafb0088 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -66,6 +66,32 @@ namespace Timeline.Services /// public interface ITimelineService { + /// + /// Get the timeline last modified time (not include name change). + /// + /// The name of the timeline. + /// The timeline info. + /// Thrown when is null. + /// Throw when is of bad format. + /// + /// Thrown when timeline with name does not exist. + /// If it is a personal timeline, then inner exception is . + /// + Task GetTimelineLastModifiedTime(string timelineName); + + /// + /// Get the timeline unique id. + /// + /// The name of the timeline. + /// The timeline info. + /// Thrown when is null. + /// Throw when is of bad format. + /// + /// Thrown when timeline with name does not exist. + /// If it is a personal timeline, then inner exception is . + /// + Task GetTimelineUniqueId(string timelineName); + /// /// Get the timeline info. /// @@ -497,6 +523,30 @@ namespace Timeline.Services } } + public async Task GetTimelineLastModifiedTime(string timelineName) + { + if (timelineName == null) + throw new ArgumentNullException(nameof(timelineName)); + + var timelineId = await FindTimelineId(timelineName); + + var timelineEntity = await _database.Timelines.Where(t => t.Id == timelineId).Select(t => new { t.LastModified }).SingleAsync(); + + return timelineEntity.LastModified; + } + + public async Task GetTimelineUniqueId(string timelineName) + { + if (timelineName == null) + throw new ArgumentNullException(nameof(timelineName)); + + var timelineId = await FindTimelineId(timelineName); + + var timelineEntity = await _database.Timelines.Where(t => t.Id == timelineId).Select(t => new { t.UniqueId }).SingleAsync(); + + return timelineEntity.UniqueId; + } + public async Task GetTimeline(string timelineName) { if (timelineName == null) -- cgit v1.2.3