From e71cb8e368d081747014f1434c5ee157660783f2 Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 2 Feb 2020 00:31:33 +0800 Subject: ... --- Timeline/Services/TimelineService.cs | 133 ++++++++++++++++------------------- 1 file changed, 59 insertions(+), 74 deletions(-) (limited to 'Timeline/Services') diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index 0ea68265..a16237ca 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -24,6 +24,37 @@ namespace Timeline.Services /// public interface IBaseTimelineService { + /// + /// Get the timeline info. + /// + /// Username or the timeline name. See remarks of . + /// The timeline info. + /// Thrown when is null. + /// Thrown when is illegal. It is not a valid timeline name (for normal timeline service) or a valid username (for personal timeline service). + /// + /// Thrown when timeline does not exist. + /// For normal timeline, it means the name does not exist. + /// For personal timeline, it means the user of that username does not exist + /// and the inner exception should be a . + /// + Task GetTimeline(string name); + + /// + /// Set the properties of a timeline. + /// + /// Username or the timeline name. See remarks of . + /// The new properties. Null member means not to change. + /// The timeline info. + /// Thrown when is null. + /// Thrown when is illegal. It is not a valid timeline name (for normal timeline service) or a valid username (for personal timeline service). + /// + /// Thrown when timeline does not exist. + /// For normal timeline, it means the name does not exist. + /// For personal timeline, it means the user of that username does not exist + /// and the inner exception should be a . + /// + Task ChangeProperty(string name, TimelinePatchRequest newProperties); + /// /// Get all the posts in the timeline. /// @@ -177,20 +208,6 @@ namespace Timeline.Services /// public interface ITimelineService : IBaseTimelineService { - /// - /// Get the timeline info. - /// - /// The name of the timeline. - /// The timeline info. - /// Thrown when is null. - /// - /// Thrown when timeline name is invalid. Currently it means it is an empty string. - /// - /// - /// Thrown when timeline with the name does not exist. - /// - Task GetTimeline(string name); - /// /// Create a timeline. /// @@ -205,37 +222,6 @@ namespace Timeline.Services public interface IPersonalTimelineService : IBaseTimelineService { - /// - /// Get the timeline info. - /// - /// The username of the owner of the personal timeline. - /// The timeline info. - /// - /// Thrown when is null. - /// - /// - /// Thrown when is of bad format. - /// - /// - /// Thrown when the user does not exist. Inner exception MUST be . - /// - Task GetTimeline(string username); - - /// - /// Set the properties of a timeline. - /// - /// Username or the timeline name. See remarks of . - /// The new properties. Null member means not to change. - /// - /// Thrown when is null. - /// - /// - /// Thrown when is of bad format. - /// - /// - /// Thrown when the user does not exist. Inner exception MUST be . - /// - Task ChangeProperty(string name, TimelinePatchRequest newProperties); } @@ -283,6 +269,34 @@ namespace Timeline.Services /// protected abstract Task FindTimelineId(string name); + public async Task GetTimeline(string name) + { + if (name == null) + throw new ArgumentNullException(nameof(name)); + + var timelineId = await FindTimelineId(name); + + var timelineEntity = await Database.Timelines.Where(t => t.Id == timelineId).SingleAsync(); + + var timelineMemberEntities = await Database.TimelineMembers.Where(m => m.TimelineId == timelineId).Select(m => new { m.UserId }).ToListAsync(); + + var owner = Mapper.Map(await UserService.GetUserById(timelineEntity.OwnerId)); + + var members = new List(); + foreach (var memberEntity in timelineMemberEntities) + { + members.Add(Mapper.Map(await UserService.GetUserById(memberEntity.UserId))); + } + + return new TimelineInfo + { + Description = timelineEntity.Description ?? "", + Owner = owner, + Visibility = timelineEntity.Visibility, + Members = members + }; + } + public async Task> GetPosts(string name) { if (name == null) @@ -569,34 +583,5 @@ namespace Timeline.Services return newTimelineEntity.Id; } } - - public async Task GetTimeline(string username) - { - if (username == null) - throw new ArgumentNullException(nameof(username)); - - var timelineId = await FindTimelineId(username); - - var timelineEntity = await Database.Timelines.Where(t => t.Id == timelineId).SingleAsync(); - - var timelineMemberEntities = await Database.TimelineMembers.Where(m => m.TimelineId == timelineId).Select(m => new { m.UserId }).ToListAsync(); - - var owner = Mapper.Map(await UserService.GetUserById(timelineEntity.OwnerId)); - - var members = new List(); - foreach (var memberEntity in timelineMemberEntities) - { - members.Add(Mapper.Map(await UserService.GetUserById(memberEntity.UserId))); - } - - return new BaseTimelineInfo - { - Description = timelineEntity.Description ?? "", - Owner = owner, - Visibility = timelineEntity.Visibility, - Members = members - }; - } - } } -- cgit v1.2.3