using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Timeline.Entities; using Timeline.Models; namespace Timeline.Services { /// /// This define the common interface of both personal timeline /// and normal timeline. /// /// /// The "name" parameter in method means name of timeline in /// while username of the owner /// of the personal timeline in . /// public interface IBaseTimelineService { /// /// Get all the posts in the timeline. /// /// Username or the timeline name. See remarks of . /// A list of all posts. /// Thrown when is null. /// /// Thrown when timeline name is of bad format. /// For normal timeline, it means name is an empty string. /// For personal timeline, it means the username is of bad format, /// the inner exception should be a . /// /// /// 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> GetPosts(string name); /// /// Create a new post in timeline. /// /// Username or the timeline name. See remarks of . /// The author's username. /// The content. /// The time of the post. If null, then use current time. /// /// Thrown when or or is null. /// /// Thrown when timeline name is of bad format. /// For normal timeline, it means name is an empty string. /// For personal timeline, it means the username is of bad format, /// the inner exception should be a . /// /// /// 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 . /// /// Thrown if is of bad format. /// Thrown if does not exist. Task CreatePost(string name, string author, string content, DateTime? time); /// /// Set the visibility permission of a timeline. /// /// Username or the timeline name. See remarks of . /// The new visibility. /// Thrown when is null. /// /// Thrown when timeline name is of bad format. /// For normal timeline, it means name is an empty string. /// For personal timeline, it means the username is of bad format, /// the inner exception should be a . /// /// /// 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 SetVisibility(string name, TimelineVisibility visibility); /// /// Set the description of a timeline. /// /// Username or the timeline name. See remarks of . /// The new description. /// Thrown when or is null. /// /// Thrown when timeline name is of bad format. /// For normal timeline, it means name is an empty string. /// For personal timeline, it means the username is of bad format, /// the inner exception should be a . /// /// /// 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 SetDescription(string name, string description); /// /// Remove members to a timeline. /// /// Username or the timeline name. See remarks of . /// A list of usernames of members to add. May be null. /// A list of usernames of members to remove. May be null. /// Thrown when is null. /// /// Thrown when timeline name is of bad format. /// For normal timeline, it means name is an empty string. /// For personal timeline, it means the username is of bad format, /// the inner exception should be a . /// /// /// 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 . /// /// /// Thrown when an exception occurs on the user list. /// The inner exception is /// when one of the username is invalid. /// The inner exception is /// when one of the user to add does not exist. /// /// /// Operating on a username that is of bad format always throws. /// Add a user that already is a member has no effects. /// Remove a user that is not a member also has not effects. /// Add a user that does not exist will throw . /// But remove one does not throw. /// Task ChangeMember(string name, IList? add, IList? remove); /// /// Verify whether a visitor has the permission to read a timeline. /// /// Username or the timeline name. See remarks of . /// The user to check on. Null means visitor without account. /// Thrown when is null. /// /// Thrown when timeline name is of bad format. /// For normal timeline, it means name is an empty string. /// For personal timeline, it means the username is of bad format, /// the inner exception should be a . /// /// /// 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 . /// /// True if can read, false if can't read. Task HasReadPermission(string name, string? username); /// /// Verify whether a user is member of a timeline. /// /// Username or the timeline name. See remarks of . /// The user to check on. /// Thrown when or is null. /// /// Thrown when timeline name is of bad format. /// For normal timeline, it means name is an empty string. /// For personal timeline, it means the username is of bad format, /// the inner exception should be a . /// /// /// 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 . /// /// /// Thrown when is not a valid username. /// /// /// Thrown when user does not exist. /// True if it is a member, false if not. Task IsMemberOf(string name, string username); } /// /// Service for normal timeline. /// 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. /// /// The name of the timeline. /// The owner of the timeline. /// Thrown when or is null. /// /// Thrown when timeline name is invalid. Currently it means it is an empty string. /// /// /// Thrown when the timeline already exists. /// /// /// Thrown when the username of the owner is not valid. /// /// /// Thrown when the owner user does not exist. Task CreateTimeline(string name, string owner); } 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. Inner exception MUST be . /// /// /// Thrown when the user does not exist. Inner exception MUST be . /// Task GetTimeline(string username); } }