aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-07-12 15:54:09 +0800
committercrupest <crupest@outlook.com>2020-07-12 15:54:09 +0800
commit5658347ebafdae2bb82e96f57299e40ddec58f28 (patch)
tree9c5e5ad90fc30f05d1b80b42515998a519e7e7a8
parent712cd6b079138e116a6de5d121b875094087e8a9 (diff)
downloadtimeline-5658347ebafdae2bb82e96f57299e40ddec58f28.tar.gz
timeline-5658347ebafdae2bb82e96f57299e40ddec58f28.tar.bz2
timeline-5658347ebafdae2bb82e96f57299e40ddec58f28.zip
Add api in service.
-rw-r--r--Timeline.Tests/Services/TimelineServiceTest.cs30
-rw-r--r--Timeline/Services/TimelineService.cs50
2 files changed, 80 insertions, 0 deletions
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
@@ -59,6 +59,36 @@ namespace Timeline.Tests.Services
[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")]
public async Task Timeline_LastModified(string timelineName)
{
var initTime = _clock.ForwardCurrentTime();
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
@@ -67,6 +67,32 @@ namespace Timeline.Services
public interface ITimelineService
{
/// <summary>
+ /// Get the timeline last modified time (not include name change).
+ /// </summary>
+ /// <param name="timelineName">The name of the timeline.</param>
+ /// <returns>The timeline info.</returns>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="timelineName"/> is null.</exception>
+ /// <exception cref="ArgumentException">Throw when <paramref name="timelineName"/> is of bad format.</exception>
+ /// <exception cref="TimelineNotExistException">
+ /// Thrown when timeline with name <paramref name="timelineName"/> does not exist.
+ /// If it is a personal timeline, then inner exception is <see cref="UserNotExistException"/>.
+ /// </exception>
+ Task<DateTime> GetTimelineLastModifiedTime(string timelineName);
+
+ /// <summary>
+ /// Get the timeline unique id.
+ /// </summary>
+ /// <param name="timelineName">The name of the timeline.</param>
+ /// <returns>The timeline info.</returns>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="timelineName"/> is null.</exception>
+ /// <exception cref="ArgumentException">Throw when <paramref name="timelineName"/> is of bad format.</exception>
+ /// <exception cref="TimelineNotExistException">
+ /// Thrown when timeline with name <paramref name="timelineName"/> does not exist.
+ /// If it is a personal timeline, then inner exception is <see cref="UserNotExistException"/>.
+ /// </exception>
+ Task<string> GetTimelineUniqueId(string timelineName);
+
+ /// <summary>
/// Get the timeline info.
/// </summary>
/// <param name="timelineName">The name of the timeline.</param>
@@ -497,6 +523,30 @@ namespace Timeline.Services
}
}
+ public async Task<DateTime> 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<string> 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<Models.Timeline> GetTimeline(string timelineName)
{
if (timelineName == null)