From 434be212c77bdade04722046e92c3dac25d0aff3 Mon Sep 17 00:00:00 2001 From: crupest Date: Sun, 25 Apr 2021 19:30:12 +0800 Subject: refactor: Remove splitted error code project. --- .../Timeline.ErrorCodes.CodeGenerator/Program.cs | 77 ------------------- .../Timeline.ErrorCodes.CodeGenerator.csproj | 16 ---- .../packages.lock.json | 24 ------ BackEnd/Timeline.ErrorCodes/ErrorCodes.cs | 88 ---------------------- .../Timeline.ErrorCodes/Timeline.ErrorCodes.csproj | 7 -- BackEnd/Timeline.ErrorCodes/packages.lock.json | 6 -- BackEnd/Timeline.Tests/packages.lock.json | 6 +- BackEnd/Timeline.sln | 12 --- BackEnd/Timeline/ErrorCodes.cs | 88 ++++++++++++++++++++++ BackEnd/Timeline/Timeline.csproj | 4 - 10 files changed, 89 insertions(+), 239 deletions(-) delete mode 100644 BackEnd/Timeline.ErrorCodes.CodeGenerator/Program.cs delete mode 100644 BackEnd/Timeline.ErrorCodes.CodeGenerator/Timeline.ErrorCodes.CodeGenerator.csproj delete mode 100644 BackEnd/Timeline.ErrorCodes.CodeGenerator/packages.lock.json delete mode 100644 BackEnd/Timeline.ErrorCodes/ErrorCodes.cs delete mode 100644 BackEnd/Timeline.ErrorCodes/Timeline.ErrorCodes.csproj delete mode 100644 BackEnd/Timeline.ErrorCodes/packages.lock.json create mode 100644 BackEnd/Timeline/ErrorCodes.cs (limited to 'BackEnd') diff --git a/BackEnd/Timeline.ErrorCodes.CodeGenerator/Program.cs b/BackEnd/Timeline.ErrorCodes.CodeGenerator/Program.cs deleted file mode 100644 index 84ab5908..00000000 --- a/BackEnd/Timeline.ErrorCodes.CodeGenerator/Program.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using System.Text; - -namespace Timeline.ErrorCodes.CodeGenerator -{ - class Program - { - static void Main(string[] args) - { - string Indent(int n) - { - const string indent = " "; - return string.Concat(Enumerable.Repeat(indent, n)); - } - - StringBuilder code = new StringBuilder(); - - code.AppendLine("using static Timeline.Resources.Messages;"); - code.AppendLine(); - code.AppendLine("namespace Timeline.Models.Http"); - code.AppendLine("{"); - - int depth = 1; - - void RecursiveAddErrorCode(Type type, bool root) - { - code.AppendLine($"{Indent(depth)}public static class {(root ? "ErrorResponse" : type.Name)}"); - code.AppendLine($"{Indent(depth)}{{"); - - foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy) - .Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(int))) - { - var path = type.FullName.Replace("+", ".").Replace("Timeline.Models.Http.ErrorCodes.", "") + "." + field.Name; - - code.AppendLine($"{Indent(depth + 1)}public static CommonResponse {field.Name}(params object?[] formatArgs)"); - code.AppendLine($"{Indent(depth + 1)}{{"); - code.AppendLine($"{Indent(depth + 2)}return new CommonResponse({"ErrorCodes." + path}, string.Format({path.Replace(".", "_")}, formatArgs));"); - code.AppendLine($"{Indent(depth + 1)}}}"); - code.AppendLine(); - code.AppendLine($"{Indent(depth + 1)}public static CommonResponse CustomMessage_{field.Name}(string message, params object?[] formatArgs)"); - code.AppendLine($"{Indent(depth + 1)}{{"); - code.AppendLine($"{Indent(depth + 2)}return new CommonResponse({"ErrorCodes." + path}, string.Format(message, formatArgs));"); - code.AppendLine($"{Indent(depth + 1)}}}"); - code.AppendLine(); - } - - depth += 1; - - foreach (var nestedType in type.GetNestedTypes()) - { - RecursiveAddErrorCode(nestedType, false); - } - - depth -= 1; - - code.AppendLine($"{Indent(depth)}}}"); - code.AppendLine(); - } - - RecursiveAddErrorCode(typeof(Timeline.Models.Http.ErrorCodes), true); - - code.AppendLine("}"); - - var generatedCode = code.ToString(); - - Console.WriteLine(generatedCode); - - TextCopy.ClipboardService.SetText(generatedCode); - var oldColor = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("Code has copied to clipboard!"); - Console.ForegroundColor = oldColor; - } - } -} diff --git a/BackEnd/Timeline.ErrorCodes.CodeGenerator/Timeline.ErrorCodes.CodeGenerator.csproj b/BackEnd/Timeline.ErrorCodes.CodeGenerator/Timeline.ErrorCodes.CodeGenerator.csproj deleted file mode 100644 index 767bec39..00000000 --- a/BackEnd/Timeline.ErrorCodes.CodeGenerator/Timeline.ErrorCodes.CodeGenerator.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - net5.0 - - - - - - - - - - - diff --git a/BackEnd/Timeline.ErrorCodes.CodeGenerator/packages.lock.json b/BackEnd/Timeline.ErrorCodes.CodeGenerator/packages.lock.json deleted file mode 100644 index bbe8e02a..00000000 --- a/BackEnd/Timeline.ErrorCodes.CodeGenerator/packages.lock.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": 1, - "dependencies": { - ".NETCoreApp,Version=v5.0": { - "TextCopy": { - "type": "Direct", - "requested": "[4.2.0, )", - "resolved": "4.2.0", - "contentHash": "NY2UAFIjBJj+3aABP5tyO6ooEdkJxIGtwRNqvMQKLmyIeZiyGvM4XYbkKNntyQlhyFhhfBww05C3D/0DdimfaQ==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "3.1.4" - } - }, - "Microsoft.Extensions.DependencyInjection.Abstractions": { - "type": "Transitive", - "resolved": "3.1.4", - "contentHash": "AceHamXNKDMDwIoZqEoApLp8s3935wSC3VXrPaRWa0wWOaEcYdDlo1nWQ1zLiezoDmpJzV7FqDm53E0Ty/hEMg==" - }, - "timeline.errorcodes": { - "type": "Project" - } - } - } -} \ No newline at end of file diff --git a/BackEnd/Timeline.ErrorCodes/ErrorCodes.cs b/BackEnd/Timeline.ErrorCodes/ErrorCodes.cs deleted file mode 100644 index 87d451f2..00000000 --- a/BackEnd/Timeline.ErrorCodes/ErrorCodes.cs +++ /dev/null @@ -1,88 +0,0 @@ -namespace Timeline.Models.Http -{ - /// - /// All error code constants. - /// - /// - /// Format: 1bbbccdd - /// - public static class ErrorCodes - { - public static class Common - { - public const int InvalidModel = 1_000_0001; - public const int Forbid = 1_000_0002; - public const int UnknownEndpoint = 1_000_0003; - public const int Unauthorized = 1_000_0004; - - public static class Header - { - public const int IfNonMatch_BadFormat = 1_000_01_01; - public const int IfModifiedSince_BadFormat = 1_000_01_02; - } - - public static class Content - { - public const int TooBig = 1_000_11_01; - } - - public static class Token - { - public const int TimeExpired = 1_000_21_01; - public const int VersionExpired = 1_000_21_02; - public const int BadFormat = 1_000_21_03; - public const int UserNotExist = 1_000_21_04; - public const int Unknown = 1_000_21_05; - } - } - - public static class UserCommon - { - public const int NotExist = 1_001_0001; - } - - public static class TokenController - { - public const int Create_BadCredential = 1_101_01_01; - public const int Verify_BadFormat = 1_101_02_01; - public const int Verify_UserNotExist = 1_101_02_02; - public const int Verify_OldVersion = 1_101_02_03; - public const int Verify_TimeExpired = 1_101_02_04; - } - - public static class UserController - { - public const int UsernameConflict = 1_102_01_01; - public const int ChangePassword_BadOldPassword = 1_102_02_01; - public const int ChangePermission_RootUser = 1_102_03_01; - public const int Delete_RootUser = 1_102_04_01; - } - - public static class UserAvatar - { - public const int BadFormat_CantDecode = 1_103_00_01; - public const int BadFormat_UnmatchedFormat = 1_103_00_02; - public const int BadFormat_BadSize = 1_103_00_03; - } - - public static class TimelineController - { - public const int NameConflict = 1_104_01_01; - public const int NotExist = 1_104_02_01; - public const int QueryRelateNotExist = 1_104_04_01; - public const int PostNotExist = 1_104_05_01; - public const int PostDataNotExist = 1_104_05_02; - } - - public static class HighlightTimelineController - { - public const int NonHighlight = 1_105_01_01; - } - - public static class BookmarkTimelineController - { - public const int NonBookmark = 1_106_01_01; - } - } -} - diff --git a/BackEnd/Timeline.ErrorCodes/Timeline.ErrorCodes.csproj b/BackEnd/Timeline.ErrorCodes/Timeline.ErrorCodes.csproj deleted file mode 100644 index 563e6f93..00000000 --- a/BackEnd/Timeline.ErrorCodes/Timeline.ErrorCodes.csproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - net5.0 - - - diff --git a/BackEnd/Timeline.ErrorCodes/packages.lock.json b/BackEnd/Timeline.ErrorCodes/packages.lock.json deleted file mode 100644 index 79ad3024..00000000 --- a/BackEnd/Timeline.ErrorCodes/packages.lock.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "version": 1, - "dependencies": { - ".NETCoreApp,Version=v5.0": {} - } -} \ No newline at end of file diff --git a/BackEnd/Timeline.Tests/packages.lock.json b/BackEnd/Timeline.Tests/packages.lock.json index 0ec5ade5..6a445ddc 100644 --- a/BackEnd/Timeline.Tests/packages.lock.json +++ b/BackEnd/Timeline.Tests/packages.lock.json @@ -1602,12 +1602,8 @@ "Microsoft.EntityFrameworkCore.Sqlite": "5.0.5", "NSwag.AspNetCore": "13.10.9", "SixLabors.ImageSharp": "1.0.3", - "System.IdentityModel.Tokens.Jwt": "6.10.2", - "Timeline.ErrorCodes": "1.0.0" + "System.IdentityModel.Tokens.Jwt": "6.10.2" } - }, - "timeline.errorcodes": { - "type": "Project" } } } diff --git a/BackEnd/Timeline.sln b/BackEnd/Timeline.sln index 40a32ee9..a9d35520 100644 --- a/BackEnd/Timeline.sln +++ b/BackEnd/Timeline.sln @@ -6,10 +6,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Timeline", "Timeline\Timeli EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Timeline.Tests", "Timeline.Tests\Timeline.Tests.csproj", "{3D76D578-37BC-43C2-97BF-9C6DD3825F10}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Timeline.ErrorCodes", "Timeline.ErrorCodes\Timeline.ErrorCodes.csproj", "{1044E3B0-1010-47CA-956E-B6E8FE87055B}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Timeline.ErrorCodes.CodeGenerator", "Timeline.ErrorCodes.CodeGenerator\Timeline.ErrorCodes.CodeGenerator.csproj", "{D0263FD3-DC6A-4676-A746-FDAFCDACC5F2}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,14 +20,6 @@ Global {3D76D578-37BC-43C2-97BF-9C6DD3825F10}.Debug|Any CPU.Build.0 = Debug|Any CPU {3D76D578-37BC-43C2-97BF-9C6DD3825F10}.Release|Any CPU.ActiveCfg = Release|Any CPU {3D76D578-37BC-43C2-97BF-9C6DD3825F10}.Release|Any CPU.Build.0 = Release|Any CPU - {1044E3B0-1010-47CA-956E-B6E8FE87055B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1044E3B0-1010-47CA-956E-B6E8FE87055B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1044E3B0-1010-47CA-956E-B6E8FE87055B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1044E3B0-1010-47CA-956E-B6E8FE87055B}.Release|Any CPU.Build.0 = Release|Any CPU - {D0263FD3-DC6A-4676-A746-FDAFCDACC5F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D0263FD3-DC6A-4676-A746-FDAFCDACC5F2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D0263FD3-DC6A-4676-A746-FDAFCDACC5F2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D0263FD3-DC6A-4676-A746-FDAFCDACC5F2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BackEnd/Timeline/ErrorCodes.cs b/BackEnd/Timeline/ErrorCodes.cs new file mode 100644 index 00000000..87d451f2 --- /dev/null +++ b/BackEnd/Timeline/ErrorCodes.cs @@ -0,0 +1,88 @@ +namespace Timeline.Models.Http +{ + /// + /// All error code constants. + /// + /// + /// Format: 1bbbccdd + /// + public static class ErrorCodes + { + public static class Common + { + public const int InvalidModel = 1_000_0001; + public const int Forbid = 1_000_0002; + public const int UnknownEndpoint = 1_000_0003; + public const int Unauthorized = 1_000_0004; + + public static class Header + { + public const int IfNonMatch_BadFormat = 1_000_01_01; + public const int IfModifiedSince_BadFormat = 1_000_01_02; + } + + public static class Content + { + public const int TooBig = 1_000_11_01; + } + + public static class Token + { + public const int TimeExpired = 1_000_21_01; + public const int VersionExpired = 1_000_21_02; + public const int BadFormat = 1_000_21_03; + public const int UserNotExist = 1_000_21_04; + public const int Unknown = 1_000_21_05; + } + } + + public static class UserCommon + { + public const int NotExist = 1_001_0001; + } + + public static class TokenController + { + public const int Create_BadCredential = 1_101_01_01; + public const int Verify_BadFormat = 1_101_02_01; + public const int Verify_UserNotExist = 1_101_02_02; + public const int Verify_OldVersion = 1_101_02_03; + public const int Verify_TimeExpired = 1_101_02_04; + } + + public static class UserController + { + public const int UsernameConflict = 1_102_01_01; + public const int ChangePassword_BadOldPassword = 1_102_02_01; + public const int ChangePermission_RootUser = 1_102_03_01; + public const int Delete_RootUser = 1_102_04_01; + } + + public static class UserAvatar + { + public const int BadFormat_CantDecode = 1_103_00_01; + public const int BadFormat_UnmatchedFormat = 1_103_00_02; + public const int BadFormat_BadSize = 1_103_00_03; + } + + public static class TimelineController + { + public const int NameConflict = 1_104_01_01; + public const int NotExist = 1_104_02_01; + public const int QueryRelateNotExist = 1_104_04_01; + public const int PostNotExist = 1_104_05_01; + public const int PostDataNotExist = 1_104_05_02; + } + + public static class HighlightTimelineController + { + public const int NonHighlight = 1_105_01_01; + } + + public static class BookmarkTimelineController + { + public const int NonBookmark = 1_106_01_01; + } + } +} + diff --git a/BackEnd/Timeline/Timeline.csproj b/BackEnd/Timeline/Timeline.csproj index 0365d0fd..08441c85 100644 --- a/BackEnd/Timeline/Timeline.csproj +++ b/BackEnd/Timeline/Timeline.csproj @@ -47,10 +47,6 @@ - - - - True -- cgit v1.2.3