From cb2d9949ecc1d3c4b10295eb715a9293d493c5e2 Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Sun, 3 Nov 2019 00:28:21 +0800 Subject: Design the entity model primarily. --- Timeline/Entities/TimelineMemberEntity.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Timeline/Entities/TimelineMemberEntity.cs (limited to 'Timeline/Entities/TimelineMemberEntity.cs') diff --git a/Timeline/Entities/TimelineMemberEntity.cs b/Timeline/Entities/TimelineMemberEntity.cs new file mode 100644 index 00000000..4631dc89 --- /dev/null +++ b/Timeline/Entities/TimelineMemberEntity.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Threading.Tasks; + +namespace Timeline.Entities +{ + public class TimelineMemberEntity + { + [Column("id"), Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public long Id { get; set; } + + [Column("user")] + public long UserId { get; set; } + + [ForeignKey(nameof(UserId))] + public User User { get; set; } = default!; + + [Column("timeline")] + public long TimelineId { get; set; } + + [ForeignKey(nameof(TimelineId))] + public TimelineEntity Timeline { get; set; } = default!; + } +} -- cgit v1.2.3 From 27719fa2a00e041cdb957182812508464d19a9d7 Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Sun, 3 Nov 2019 16:51:10 +0800 Subject: WIP: Design the timeline service interface. --- Timeline/Entities/TimelineMemberEntity.cs | 6 +- Timeline/Models/Timeline.cs | 42 +++++ Timeline/Resources/Services/Exception.Designer.cs | 36 ++++ Timeline/Resources/Services/Exception.resx | 12 ++ .../Services/TimelineNameBadFormatException.cs | 21 +++ Timeline/Services/TimelineNotExistException.cs | 19 ++ Timeline/Services/TimelineService.cs | 191 ++++++++++++++++++++- 7 files changed, 320 insertions(+), 7 deletions(-) create mode 100644 Timeline/Models/Timeline.cs create mode 100644 Timeline/Services/TimelineNameBadFormatException.cs create mode 100644 Timeline/Services/TimelineNotExistException.cs (limited to 'Timeline/Entities/TimelineMemberEntity.cs') diff --git a/Timeline/Entities/TimelineMemberEntity.cs b/Timeline/Entities/TimelineMemberEntity.cs index 4631dc89..c8961013 100644 --- a/Timeline/Entities/TimelineMemberEntity.cs +++ b/Timeline/Entities/TimelineMemberEntity.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Threading.Tasks; namespace Timeline.Entities { diff --git a/Timeline/Models/Timeline.cs b/Timeline/Models/Timeline.cs new file mode 100644 index 00000000..26012878 --- /dev/null +++ b/Timeline/Models/Timeline.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Timeline.Entities; + +namespace Timeline.Models +{ + public class TimelinePostInfo + { + public long Id { get; set; } + + public string? Content { get; set; } + + public DateTime Time { get; set; } + + /// + /// The username of the author. + /// + public string Author { get; set; } = default!; + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "This is a DTO class.")] + public class BaseTimelineInfo + { + public string? Description { get; set; } + + /// + /// The username of the owner. + /// + public string Owner { get; set; } = default!; + + public TimelineVisibility Visibility { get; set; } + + public List Members { get; set; } = default!; + } + + public class TimelineInfo : BaseTimelineInfo + { + public string Name { get; set; } = default!; + } +} diff --git a/Timeline/Resources/Services/Exception.Designer.cs b/Timeline/Resources/Services/Exception.Designer.cs index ddf60f45..a5785cb6 100644 --- a/Timeline/Resources/Services/Exception.Designer.cs +++ b/Timeline/Resources/Services/Exception.Designer.cs @@ -267,6 +267,42 @@ namespace Timeline.Resources.Services { } } + /// + /// Looks up a localized string similar to An exception happened when add or remove member on timeline.. + /// + internal static string TimelineMemberOperationException { + get { + return ResourceManager.GetString("TimelineMemberOperationException", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to An exception happened when operating on the {} member on timeline.. + /// + internal static string TimelineMemberOperationExceptionIndex { + get { + return ResourceManager.GetString("TimelineMemberOperationExceptionIndex", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Timeline name is of bad format. If this is a personal timeline, it means the username is of bad format and inner exception should be a UsernameBadFormatException.. + /// + internal static string TimelineNameBadFormatException { + get { + return ResourceManager.GetString("TimelineNameBadFormatException", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Timeline does not exist. If this is a personal timeline, it means the user does not exist and inner exception should be a UserNotExistException.. + /// + internal static string TimelineNotExistException { + get { + return ResourceManager.GetString("TimelineNotExistException", resourceCulture); + } + } + /// /// Looks up a localized string similar to The username is of bad format.. /// diff --git a/Timeline/Resources/Services/Exception.resx b/Timeline/Resources/Services/Exception.resx index 12bf9afb..e6622094 100644 --- a/Timeline/Resources/Services/Exception.resx +++ b/Timeline/Resources/Services/Exception.resx @@ -186,6 +186,18 @@ version claim is not a number. + + An exception happened when add or remove member on timeline. + + + An exception happened when operating on the {} member on timeline. + + + Timeline name is of bad format. If this is a personal timeline, it means the username is of bad format and inner exception should be a UsernameBadFormatException. + + + Timeline does not exist. If this is a personal timeline, it means the user does not exist and inner exception should be a UserNotExistException. + The username is of bad format. diff --git a/Timeline/Services/TimelineNameBadFormatException.cs b/Timeline/Services/TimelineNameBadFormatException.cs new file mode 100644 index 00000000..5120a175 --- /dev/null +++ b/Timeline/Services/TimelineNameBadFormatException.cs @@ -0,0 +1,21 @@ +using System; + +namespace Timeline.Services +{ + [Serializable] + public class TimelineNameBadFormatException : Exception + { + public TimelineNameBadFormatException() + : base(Resources.Services.Exception.TimelineNameBadFormatException) { } + public TimelineNameBadFormatException(string name) + : base(Resources.Services.Exception.TimelineNameBadFormatException) { Name = name; } + public TimelineNameBadFormatException(string name, Exception inner) + : base(Resources.Services.Exception.TimelineNameBadFormatException, inner) { Name = name; } + + protected TimelineNameBadFormatException( + System.Runtime.Serialization.SerializationInfo info, + System.Runtime.Serialization.StreamingContext context) : base(info, context) { } + + public string? Name { get; set; } + } +} diff --git a/Timeline/Services/TimelineNotExistException.cs b/Timeline/Services/TimelineNotExistException.cs new file mode 100644 index 00000000..6dfd0bab --- /dev/null +++ b/Timeline/Services/TimelineNotExistException.cs @@ -0,0 +1,19 @@ +using System; + +namespace Timeline.Services +{ + [Serializable] + public class TimelineNotExistException : Exception + { + public TimelineNotExistException() : base(Resources.Services.Exception.TimelineNotExistException) { } + public TimelineNotExistException(string name) + : base(Resources.Services.Exception.TimelineNotExistException) { Name = name; } + public TimelineNotExistException(string name, Exception inner) + : base(Resources.Services.Exception.TimelineNotExistException, inner) { Name = name; } + protected TimelineNotExistException( + System.Runtime.Serialization.SerializationInfo info, + System.Runtime.Serialization.StreamingContext context) : base(info, context) { } + + public string? Name { get; set; } + } +} diff --git a/Timeline/Services/TimelineService.cs b/Timeline/Services/TimelineService.cs index e6a1e845..cf130a70 100644 --- a/Timeline/Services/TimelineService.cs +++ b/Timeline/Services/TimelineService.cs @@ -1,12 +1,199 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Threading.Tasks; +using Timeline.Entities; +using Timeline.Models; namespace Timeline.Services { - public interface ITimelineService + + [Serializable] + public class TimelineMemberOperationException : Exception + { + public TimelineMemberOperationException() : base(Resources.Services.Exception.TimelineMemberOperationException) { } + public TimelineMemberOperationException(string message) : base(message) { } + public TimelineMemberOperationException(string message, Exception inner) : base(message, inner) { } + protected TimelineMemberOperationException( + System.Runtime.Serialization.SerializationInfo info, + System.Runtime.Serialization.StreamingContext context) : base(info, context) { } + + public TimelineMemberOperationException(int index, Exception inner) : base(MakeIndexMessage(index), inner) { Index = index; } + + private static string MakeIndexMessage(int index) => string.Format(CultureInfo.CurrentCulture, + Resources.Services.Exception.TimelineMemberOperationExceptionIndex, index); + + public int? Index { get; set; } + } + + /// + /// 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 Post(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); + + /// + /// Add members to a timeline. + /// + /// Username or the timeline name. See remarks of . + /// A list of new members' usernames + /// 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 . + /// + /// + /// TODO! complete this documents. + /// + Task AddMember(string name, IList usernames); + + /// + /// Remove members to a timeline. + /// + /// Username or the timeline name. See remarks of . + /// A list of members' usernames + /// 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 RemoveMember(string name, IList usernames); + } + + /// + /// Service for normal timeline. + /// + public interface ITimelineService : IBaseTimelineService + { + /// + /// Get the timeline info. + /// + /// The name of the timeline. + /// The timeline info. + Task GetTimeline(string name); + + /// + /// Create a timeline. + /// + /// The name of the timeline. + /// The owner of the timeline. + Task CreateTimeline(string name, string owner); + } + + public interface IPersonalTimelineService : IBaseTimelineService { - // TODO: Design this. + /// + /// Get the timeline info. + /// + /// The username of the owner of the personal timeline. + /// The timeline info. + Task GetTimeline(string username); } } -- cgit v1.2.3