From b9dc0062241f4dcf5221808d97a7e4c337a8b6cc Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 2 Feb 2020 14:35:30 +0800 Subject: Add timeline service. --- .../Models/Validation/NameValidator.Designer.cs | 90 ++++++++++++++ .../Resources/Models/Validation/NameValidator.resx | 129 +++++++++++++++++++++ .../Validation/UsernameValidator.Designer.cs | 90 -------------- .../Models/Validation/UsernameValidator.resx | 129 --------------------- .../Resources/Services/TimelineService.Designer.cs | 18 +++ Timeline/Resources/Services/TimelineService.resx | 6 + 6 files changed, 243 insertions(+), 219 deletions(-) create mode 100644 Timeline/Resources/Models/Validation/NameValidator.Designer.cs create mode 100644 Timeline/Resources/Models/Validation/NameValidator.resx delete mode 100644 Timeline/Resources/Models/Validation/UsernameValidator.Designer.cs delete mode 100644 Timeline/Resources/Models/Validation/UsernameValidator.resx (limited to 'Timeline/Resources') diff --git a/Timeline/Resources/Models/Validation/NameValidator.Designer.cs b/Timeline/Resources/Models/Validation/NameValidator.Designer.cs new file mode 100644 index 00000000..5b869226 --- /dev/null +++ b/Timeline/Resources/Models/Validation/NameValidator.Designer.cs @@ -0,0 +1,90 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Timeline.Resources.Models.Validation { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class NameValidator { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal NameValidator() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Models.Validation.NameValidator", typeof(NameValidator).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to An empty string is not allowed.. + /// + internal static string MessageEmptyString { + get { + return ResourceManager.GetString("MessageEmptyString", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Invalid character, only alphabet, digit, underscore and hyphen are allowed.. + /// + internal static string MessageInvalidChar { + get { + return ResourceManager.GetString("MessageInvalidChar", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Too long, more than 26 characters is not premitted.. + /// + internal static string MessageTooLong { + get { + return ResourceManager.GetString("MessageTooLong", resourceCulture); + } + } + } +} diff --git a/Timeline/Resources/Models/Validation/NameValidator.resx b/Timeline/Resources/Models/Validation/NameValidator.resx new file mode 100644 index 00000000..08a814d0 --- /dev/null +++ b/Timeline/Resources/Models/Validation/NameValidator.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + An empty string is not allowed. + + + Invalid character, only alphabet, digit, underscore and hyphen are allowed. + + + Too long, more than 26 characters is not premitted. + + \ No newline at end of file diff --git a/Timeline/Resources/Models/Validation/UsernameValidator.Designer.cs b/Timeline/Resources/Models/Validation/UsernameValidator.Designer.cs deleted file mode 100644 index ac925504..00000000 --- a/Timeline/Resources/Models/Validation/UsernameValidator.Designer.cs +++ /dev/null @@ -1,90 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Timeline.Resources.Models.Validation { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class UsernameValidator { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal UsernameValidator() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Models.Validation.UsernameValidator", typeof(UsernameValidator).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to An empty string is not allowed.. - /// - internal static string MessageEmptyString { - get { - return ResourceManager.GetString("MessageEmptyString", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Invalid character, only alphabet, digit, underscore and hyphen are allowed.. - /// - internal static string MessageInvalidChar { - get { - return ResourceManager.GetString("MessageInvalidChar", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Too long, more than 26 characters is not premitted.. - /// - internal static string MessageTooLong { - get { - return ResourceManager.GetString("MessageTooLong", resourceCulture); - } - } - } -} diff --git a/Timeline/Resources/Models/Validation/UsernameValidator.resx b/Timeline/Resources/Models/Validation/UsernameValidator.resx deleted file mode 100644 index 08a814d0..00000000 --- a/Timeline/Resources/Models/Validation/UsernameValidator.resx +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - An empty string is not allowed. - - - Invalid character, only alphabet, digit, underscore and hyphen are allowed. - - - Too long, more than 26 characters is not premitted. - - \ No newline at end of file diff --git a/Timeline/Resources/Services/TimelineService.Designer.cs b/Timeline/Resources/Services/TimelineService.Designer.cs index 8212c252..3ee5959f 100644 --- a/Timeline/Resources/Services/TimelineService.Designer.cs +++ b/Timeline/Resources/Services/TimelineService.Designer.cs @@ -77,5 +77,23 @@ namespace Timeline.Resources.Services { return ResourceManager.GetString("ExceptionFindTimelineUsernameBadFormat", resourceCulture); } } + + /// + /// Looks up a localized string similar to The timeline name is of bad format because {0}.. + /// + internal static string ExceptionTimelineNameBadFormat { + get { + return ResourceManager.GetString("ExceptionTimelineNameBadFormat", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The timeline with given name already exists.. + /// + internal static string ExceptionTimelineNameConflict { + get { + return ResourceManager.GetString("ExceptionTimelineNameConflict", resourceCulture); + } + } } } diff --git a/Timeline/Resources/Services/TimelineService.resx b/Timeline/Resources/Services/TimelineService.resx index 0429a2f8..e0d76c9a 100644 --- a/Timeline/Resources/Services/TimelineService.resx +++ b/Timeline/Resources/Services/TimelineService.resx @@ -123,4 +123,10 @@ The owner username of personal timeline is of bad format. + + The timeline name is of bad format because {0}. + + + The timeline with given name already exists. + \ No newline at end of file -- cgit v1.2.3 From 4b2569368073bbd556bbe71bd51807de91f814cb Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 3 Feb 2020 17:50:17 +0800 Subject: Add TimelineController. --- Timeline.ErrorCodes/ErrorCodes.cs | 6 +++-- .../IntegratedTests/PersonalTimelineTest.cs | 2 +- Timeline/Controllers/PersonalTimelineController.cs | 2 +- Timeline/Controllers/TimelineController.cs | 19 +++++++++++++-- Timeline/Filters/Timeline.cs | 2 +- Timeline/Models/Http/ErrorResponse.cs | 26 ++++++++++++++++++--- Timeline/Models/Http/TimelineController.cs | 8 +++++++ Timeline/Resources/Messages.Designer.cs | 27 ++++++++-------------- Timeline/Resources/Messages.resx | 15 +++++------- 9 files changed, 70 insertions(+), 37 deletions(-) (limited to 'Timeline/Resources') diff --git a/Timeline.ErrorCodes/ErrorCodes.cs b/Timeline.ErrorCodes/ErrorCodes.cs index ea74cf0e..e07fbd94 100644 --- a/Timeline.ErrorCodes/ErrorCodes.cs +++ b/Timeline.ErrorCodes/ErrorCodes.cs @@ -56,9 +56,11 @@ public const int BadFormat_BadSize = 1_103_00_03; } - public static class TimelineController + public static class TimelineCommon { - public const int MemberPut_NotExist = 1_104_01_01; + public const int NameConflict = 1_104_01_01; + public const int NotExist = 1_104_02_01; + public const int MemberPut_NotExist = 1_104_03_01; } } } diff --git a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs index cc170a98..7d0a68e8 100644 --- a/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs +++ b/Timeline.Tests/IntegratedTests/PersonalTimelineTest.cs @@ -165,7 +165,7 @@ namespace Timeline.Tests.IntegratedTests { var res = await client.PutAsync("/users/user1/timeline/members/usernotexist", null); res.Should().HaveStatusCode(400) - .And.HaveCommonBody(ErrorCodes.TimelineController.MemberPut_NotExist); + .And.HaveCommonBody(ErrorCodes.TimelineCommon.MemberPut_NotExist); } await AssertEmptyMembers(); { diff --git a/Timeline/Controllers/PersonalTimelineController.cs b/Timeline/Controllers/PersonalTimelineController.cs index 8cf098bf..b6c213d9 100644 --- a/Timeline/Controllers/PersonalTimelineController.cs +++ b/Timeline/Controllers/PersonalTimelineController.cs @@ -104,7 +104,7 @@ namespace Timeline.Controllers } catch (UserNotExistException) { - return BadRequest(ErrorResponse.TimelineController.MemberPut_NotExist()); + return BadRequest(ErrorResponse.TimelineCommon.MemberPut_NotExist()); } } diff --git a/Timeline/Controllers/TimelineController.cs b/Timeline/Controllers/TimelineController.cs index be271de7..d46189b8 100644 --- a/Timeline/Controllers/TimelineController.cs +++ b/Timeline/Controllers/TimelineController.cs @@ -102,7 +102,7 @@ namespace Timeline.Controllers } catch (UserNotExistException) { - return BadRequest(ErrorResponse.TimelineController.MemberPut_NotExist()); + return BadRequest(ErrorResponse.TimelineCommon.MemberPut_NotExist()); } } @@ -126,6 +126,21 @@ namespace Timeline.Controllers } } - // TODO: Create API . + [HttpPost("timelines")] + [Authorize] + public async Task> TimelineCreate([FromRoute] TimelineCreateRequest body) + { + var userId = this.GetUserId(); + + try + { + var timelineInfo = await _service.CreateTimeline(body.Name, userId); + return Ok(timelineInfo); + } + catch (ConflictException) + { + return BadRequest(ErrorResponse.TimelineCommon.NameConflict()); + } + } } } diff --git a/Timeline/Filters/Timeline.cs b/Timeline/Filters/Timeline.cs index ed78e645..e133c9d6 100644 --- a/Timeline/Filters/Timeline.cs +++ b/Timeline/Filters/Timeline.cs @@ -17,7 +17,7 @@ namespace Timeline.Filters } else { - throw new System.NotImplementedException(); + context.Result = new NotFoundObjectResult(ErrorResponse.TimelineCommon.NotExist()); } } } diff --git a/Timeline/Models/Http/ErrorResponse.cs b/Timeline/Models/Http/ErrorResponse.cs index a20b5386..0d23fe59 100644 --- a/Timeline/Models/Http/ErrorResponse.cs +++ b/Timeline/Models/Http/ErrorResponse.cs @@ -242,17 +242,37 @@ namespace Timeline.Models.Http } - public static class TimelineController + public static class TimelineCommon { + public static CommonResponse NameConflict(params object?[] formatArgs) + { + return new CommonResponse(ErrorCodes.TimelineCommon.NameConflict, string.Format(TimelineCommon_NameConflict, formatArgs)); + } + + public static CommonResponse CustomMessage_NameConflict(string message, params object?[] formatArgs) + { + return new CommonResponse(ErrorCodes.TimelineCommon.NameConflict, string.Format(message, formatArgs)); + } + + public static CommonResponse NotExist(params object?[] formatArgs) + { + return new CommonResponse(ErrorCodes.TimelineCommon.NotExist, string.Format(TimelineCommon_NotExist, formatArgs)); + } + + public static CommonResponse CustomMessage_NotExist(string message, params object?[] formatArgs) + { + return new CommonResponse(ErrorCodes.TimelineCommon.NotExist, string.Format(message, formatArgs)); + } + public static CommonResponse MemberPut_NotExist(params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineController.MemberPut_NotExist, string.Format(TimelineController_MemberPut_NotExist, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineCommon.MemberPut_NotExist, string.Format(TimelineCommon_MemberPut_NotExist, formatArgs)); } public static CommonResponse CustomMessage_MemberPut_NotExist(string message, params object?[] formatArgs) { - return new CommonResponse(ErrorCodes.TimelineController.MemberPut_NotExist, string.Format(message, formatArgs)); + return new CommonResponse(ErrorCodes.TimelineCommon.MemberPut_NotExist, string.Format(message, formatArgs)); } } diff --git a/Timeline/Models/Http/TimelineController.cs b/Timeline/Models/Http/TimelineController.cs index f9a4d3e5..6d461bb9 100644 --- a/Timeline/Models/Http/TimelineController.cs +++ b/Timeline/Models/Http/TimelineController.cs @@ -1,5 +1,6 @@ using System; using System.ComponentModel.DataAnnotations; +using Timeline.Models.Validation; namespace Timeline.Models.Http { @@ -11,6 +12,13 @@ namespace Timeline.Models.Http public DateTime? Time { get; set; } } + public class TimelineCreateRequest + { + [Required] + [TimelineName] + public string Name { get; set; } = default!; + } + public class TimelinePatchRequest { public string? Description { get; set; } diff --git a/Timeline/Resources/Messages.Designer.cs b/Timeline/Resources/Messages.Designer.cs index 332c8817..eeb44f10 100644 --- a/Timeline/Resources/Messages.Designer.cs +++ b/Timeline/Resources/Messages.Designer.cs @@ -151,38 +151,29 @@ namespace Timeline.Resources { } /// - /// Looks up a localized string similar to The {0}-st username to do operation {1} on is of bad format.. - /// - internal static string TimelineController_ChangeMember_UsernameBadFormat { - get { - return ResourceManager.GetString("TimelineController_ChangeMember_UsernameBadFormat", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The {0}-st user to do operation {1} on does not exist.. + /// Looks up a localized string similar to The user to set as member does not exist.. /// - internal static string TimelineController_ChangeMember_UserNotExist { + internal static string TimelineCommon_MemberPut_NotExist { get { - return ResourceManager.GetString("TimelineController_ChangeMember_UserNotExist", resourceCulture); + return ResourceManager.GetString("TimelineCommon_MemberPut_NotExist", resourceCulture); } } /// - /// Looks up a localized string similar to The user to set as member does not exist.. + /// Looks up a localized string similar to A timeline with given name already exists.. /// - internal static string TimelineController_MemberPut_NotExist { + internal static string TimelineCommon_NameConflict { get { - return ResourceManager.GetString("TimelineController_MemberPut_NotExist", resourceCulture); + return ResourceManager.GetString("TimelineCommon_NameConflict", resourceCulture); } } /// - /// Looks up a localized string similar to The post to delete does not exist.. + /// Looks up a localized string similar to The timeline with given name does not exist.. /// - internal static string TimelineController_PostOperationDelete_NotExist { + internal static string TimelineCommon_NotExist { get { - return ResourceManager.GetString("TimelineController_PostOperationDelete_NotExist", resourceCulture); + return ResourceManager.GetString("TimelineCommon_NotExist", resourceCulture); } } diff --git a/Timeline/Resources/Messages.resx b/Timeline/Resources/Messages.resx index cb6c3891..66a84d5f 100644 --- a/Timeline/Resources/Messages.resx +++ b/Timeline/Resources/Messages.resx @@ -147,17 +147,14 @@ Model is of bad format. - - The {0}-st username to do operation {1} on is of bad format. - - - The {0}-st user to do operation {1} on does not exist. - - + The user to set as member does not exist. - - The post to delete does not exist. + + A timeline with given name already exists. + + + The timeline with given name does not exist. Username or password is invalid. -- cgit v1.2.3