From 60cf54d80e62ea9180660e5a951c569f90bc4636 Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 26 Nov 2020 20:02:03 +0800 Subject: feat: Add highlight timeline entity and service. --- BackEnd/Timeline/Services/TimelineService.cs | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'BackEnd/Timeline/Services/TimelineService.cs') diff --git a/BackEnd/Timeline/Services/TimelineService.cs b/BackEnd/Timeline/Services/TimelineService.cs index 769e8bed..f8c729bf 100644 --- a/BackEnd/Timeline/Services/TimelineService.cs +++ b/BackEnd/Timeline/Services/TimelineService.cs @@ -79,6 +79,19 @@ namespace Timeline.Services /// Task GetTimelineLastModifiedTime(string timelineName); + /// + /// Get the timeline id by name. + /// + /// Timeline name. + /// Id of the timeline. + /// 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 GetTimelineIdByName(string timelineName); + /// /// Get the timeline unique id. /// @@ -105,6 +118,14 @@ namespace Timeline.Services /// Task GetTimeline(string timelineName); + /// + /// Get timeline by id. + /// + /// Id of timeline. + /// The timeline. + /// Thrown when timeline with given id does not exist. + Task GetTimelineById(long id); + /// /// Set the properties of a timeline. /// @@ -572,6 +593,18 @@ namespace Timeline.Services return timelineEntity.UniqueId; } + public async Task GetTimelineIdByName(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.Id }).SingleAsync(); + + return timelineEntity.Id; + } + public async Task GetTimeline(string timelineName) { if (timelineName == null) @@ -584,6 +617,16 @@ namespace Timeline.Services return await MapTimelineFromEntity(timelineEntity); } + public async Task GetTimelineById(long id) + { + var timelineEntity = await _database.Timelines.Where(t => t.Id == id).Include(t => t.Members).SingleOrDefaultAsync(); + + if (timelineEntity is null) + throw new TimelineNotExistException(id); + + return await MapTimelineFromEntity(timelineEntity); + } + public async Task> GetPosts(string timelineName, DateTime? modifiedSince = null, bool includeDeleted = false) { modifiedSince = modifiedSince?.MyToUtc(); -- cgit v1.2.3