From 9e559fc918d4b4485ef589184348686927ebd63c Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 7 Apr 2022 22:24:59 +0800 Subject: ... --- BackEnd/Timeline/Controllers/Resource.Designer.cs | 9 - BackEnd/Timeline/Controllers/Resource.resx | 3 - BackEnd/Timeline/Controllers/TimelineController.cs | 18 +- .../Timeline/Controllers/TimelineV2Controller.cs | 33 +++ .../CatchMultipleTimelineExceptionAttribute.cs | 20 ++ BackEnd/Timeline/Filters/Resource.Designer.cs | 258 +++++++++++---------- BackEnd/Timeline/Filters/Resource.resx | 3 + 7 files changed, 194 insertions(+), 150 deletions(-) create mode 100644 BackEnd/Timeline/Controllers/TimelineV2Controller.cs create mode 100644 BackEnd/Timeline/Filters/CatchMultipleTimelineExceptionAttribute.cs (limited to 'BackEnd') diff --git a/BackEnd/Timeline/Controllers/Resource.Designer.cs b/BackEnd/Timeline/Controllers/Resource.Designer.cs index 4c9da98a..eeb2f0fa 100644 --- a/BackEnd/Timeline/Controllers/Resource.Designer.cs +++ b/BackEnd/Timeline/Controllers/Resource.Designer.cs @@ -111,15 +111,6 @@ namespace Timeline.Controllers { } } - /// - /// Looks up a localized string similar to Multiple timeline with the name exists. Please use new api to get timeline.. - /// - internal static string MessageMultipleTimeline { - get { - return ResourceManager.GetString("MessageMultipleTimeline", resourceCulture); - } - } - /// /// Looks up a localized string similar to The old password is wrong.. /// diff --git a/BackEnd/Timeline/Controllers/Resource.resx b/BackEnd/Timeline/Controllers/Resource.resx index 004bd7cc..b70e5230 100644 --- a/BackEnd/Timeline/Controllers/Resource.resx +++ b/BackEnd/Timeline/Controllers/Resource.resx @@ -159,7 +159,4 @@ A user with given username already exists. - - Multiple timeline with the name exists. Please use new api to get timeline. - \ No newline at end of file diff --git a/BackEnd/Timeline/Controllers/TimelineController.cs b/BackEnd/Timeline/Controllers/TimelineController.cs index c10a8793..7aeec02f 100644 --- a/BackEnd/Timeline/Controllers/TimelineController.cs +++ b/BackEnd/Timeline/Controllers/TimelineController.cs @@ -21,6 +21,7 @@ namespace Timeline.Controllers /// [ApiController] [Route("timelines")] + [CatchMultipleTimelineException] [ProducesErrorResponseType(typeof(CommonResponse))] public class TimelineController : MyControllerBase { @@ -120,18 +121,11 @@ namespace Timeline.Controllers [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task> TimelineGet([FromRoute][GeneralTimelineName] string timeline) - { - try - { - var timelineId = await _service.GetTimelineIdByNameAsync(timeline); - var t = await _service.GetTimelineAsync(timelineId); - var result = await Map(t); - return result; - } - catch (MultipleTimelineException) - { - return BadRequestWithCommonResponse(ErrorCodes.TimelineController.MultipleTimelineWithSameName, Resource.MessageMultipleTimeline); - } + { + var timelineId = await _service.GetTimelineIdByNameAsync(timeline); + var t = await _service.GetTimelineAsync(timelineId); + var result = await Map(t); + return result; } /// diff --git a/BackEnd/Timeline/Controllers/TimelineV2Controller.cs b/BackEnd/Timeline/Controllers/TimelineV2Controller.cs new file mode 100644 index 00000000..7543c2a8 --- /dev/null +++ b/BackEnd/Timeline/Controllers/TimelineV2Controller.cs @@ -0,0 +1,33 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Timeline.Entities; +using Timeline.Models.Http; +using Timeline.Services.Mapper; +using Timeline.Services.Timeline; + +namespace Timeline.Controllers +{ + [ApiController] + [Route("v2/timelines")] + public class TimelineV2Controller : MyControllerBase + { + private ITimelineService _timelineService; + private TimelineMapper _timelineMapper; + + public TimelineV2Controller(ITimelineService timelineService, TimelineMapper timelineMapper) + { + _timelineService = timelineService; + _timelineMapper = timelineMapper; + } + + [HttpGet("{owner}/{timeline}")] + public async Task> Get([FromRoute] string owner, [FromRoute] string timeline) + { + var timelineId = await _timelineService.GetTimelineIdAsync(owner, timeline); + var t = await _timelineService.GetTimelineAsync(timelineId); + return await _timelineMapper.MapAsync(t, Url, User); + } + } +} + diff --git a/BackEnd/Timeline/Filters/CatchMultipleTimelineExceptionAttribute.cs b/BackEnd/Timeline/Filters/CatchMultipleTimelineExceptionAttribute.cs new file mode 100644 index 00000000..db4a91bd --- /dev/null +++ b/BackEnd/Timeline/Filters/CatchMultipleTimelineExceptionAttribute.cs @@ -0,0 +1,20 @@ +using System; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; +using Timeline.Models.Http; +using Timeline.Services.Timeline; + +namespace Timeline.Filters +{ + public class CatchMultipleTimelineExceptionAttribute : ExceptionFilterAttribute + { + public override void OnException(ExceptionContext context) + { + if (context.Exception is MultipleTimelineException) + { + context.Result = new BadRequestObjectResult(new CommonResponse(ErrorCodes.TimelineController.MultipleTimelineWithSameName, Resource.MessageMultipleTimeline)); + } + } + } +} + diff --git a/BackEnd/Timeline/Filters/Resource.Designer.cs b/BackEnd/Timeline/Filters/Resource.Designer.cs index 25d0e222..d4e088cc 100644 --- a/BackEnd/Timeline/Filters/Resource.Designer.cs +++ b/BackEnd/Timeline/Filters/Resource.Designer.cs @@ -1,126 +1,132 @@ -//------------------------------------------------------------------------------ -// -// 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.Filters { - 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 Resource { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resource() { - } - - /// - /// 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.Filters.Resource", typeof(Resource).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 Content length is too big. It can't be bigger than {0}.. - /// - internal static string MessageContentLengthTooBig { - get { - return ResourceManager.GetString("MessageContentLengthTooBig", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The entity you want to create already exists. Entity type is {0}. Constraints are {1}.. - /// - internal static string MessageEntityAlreadyExist { - get { - return ResourceManager.GetString("MessageEntityAlreadyExist", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The entity you operate on does not exist. Entity type is {0}. Constraints are {1}.. - /// - internal static string MessageEntityNotExist { - get { - return ResourceManager.GetString("MessageEntityNotExist", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Image is not a square.. - /// - internal static string MessageImageBadSize { - get { - return ResourceManager.GetString("MessageImageBadSize", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Image decode failed.. - /// - internal static string MessageImageDecodeFailed { - get { - return ResourceManager.GetString("MessageImageDecodeFailed", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Specified image format does not match the actual one .. - /// - internal static string MessageImageFormatUnmatch { - get { - return ResourceManager.GetString("MessageImageFormatUnmatch", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unknown error happened to image.. - /// - internal static string MessageImageUnknownError { - get { - return ResourceManager.GetString("MessageImageUnknownError", resourceCulture); - } - } - } -} +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Timeline.Filters { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// This class was generated by MSBuild using the GenerateResource task. + /// To add or remove a member, edit your .resx file then rerun MSBuild. + /// + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Build.Tasks.StronglyTypedResourceBuilder", "15.1.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resource { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resource() { + } + + /// + /// 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.Filters.Resource", typeof(Resource).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 Content length is too big. It can't be bigger than {0}.. + /// + internal static string MessageContentLengthTooBig { + get { + return ResourceManager.GetString("MessageContentLengthTooBig", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The entity you want to create already exists. Entity type is {0}. Constraints are {1}.. + /// + internal static string MessageEntityAlreadyExist { + get { + return ResourceManager.GetString("MessageEntityAlreadyExist", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The entity you operate on does not exist. Entity type is {0}. Constraints are {1}.. + /// + internal static string MessageEntityNotExist { + get { + return ResourceManager.GetString("MessageEntityNotExist", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Image is not a square.. + /// + internal static string MessageImageBadSize { + get { + return ResourceManager.GetString("MessageImageBadSize", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Image decode failed.. + /// + internal static string MessageImageDecodeFailed { + get { + return ResourceManager.GetString("MessageImageDecodeFailed", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Specified image format does not match the actual one .. + /// + internal static string MessageImageFormatUnmatch { + get { + return ResourceManager.GetString("MessageImageFormatUnmatch", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unknown error happened to image.. + /// + internal static string MessageImageUnknownError { + get { + return ResourceManager.GetString("MessageImageUnknownError", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Multiple timeline with the name exists. Please use new api.. + /// + internal static string MessageMultipleTimeline { + get { + return ResourceManager.GetString("MessageMultipleTimeline", resourceCulture); + } + } + } +} diff --git a/BackEnd/Timeline/Filters/Resource.resx b/BackEnd/Timeline/Filters/Resource.resx index 15b13f97..92bca0e1 100644 --- a/BackEnd/Timeline/Filters/Resource.resx +++ b/BackEnd/Timeline/Filters/Resource.resx @@ -138,4 +138,7 @@ Unknown error happened to image. + + Multiple timeline with the name exists. Please use new api. + \ No newline at end of file -- cgit v1.2.3