From 89c106169bd2a16310fdaa6e0c48a3402d97de3a Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Thu, 24 Oct 2019 16:56:41 +0800 Subject: ... --- Timeline/Models/Http/Common.cs | 66 ++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 19 deletions(-) (limited to 'Timeline/Models/Http/Common.cs') diff --git a/Timeline/Models/Http/Common.cs b/Timeline/Models/Http/Common.cs index c741837a..39ddddd9 100644 --- a/Timeline/Models/Http/Common.cs +++ b/Timeline/Models/Http/Common.cs @@ -5,46 +5,74 @@ namespace Timeline.Models.Http { public class CommonResponse { - public static CommonResponse InvalidModel(string message) + internal static CommonResponse InvalidModel(string message) { return new CommonResponse(ErrorCodes.Http.Common.InvalidModel, message); } - public static CommonResponse MissingContentType() + public CommonResponse() { - return new CommonResponse(ErrorCodes.Http.Common.Header.Missing_ContentType, "Header Content-Type is required."); + } - public static CommonResponse MissingContentLength() + public CommonResponse(int code, string message) { - return new CommonResponse(ErrorCodes.Http.Common.Header.Missing_ContentLength, "Header Content-Length is missing or of bad format."); + Code = code; + Message = message; } - public static CommonResponse ZeroContentLength() + public int Code { get; set; } + public string? Message { get; set; } + } + + internal static class HeaderErrorResponse + { + internal static CommonResponse MissingContentType(IStringLocalizerFactory localizerFactory) { - return new CommonResponse(ErrorCodes.Http.Common.Header.Zero_ContentLength, "Header Content-Length must not be 0."); + var localizer = localizerFactory.Create("Models.Http.Common"); + return new CommonResponse(ErrorCodes.Http.Common.Header.Missing_ContentType, localizer["HeaderMissingContentType"]); } - public static CommonResponse BadIfNonMatch() + internal static CommonResponse MissingContentLength(IStringLocalizerFactory localizerFactory) { - return new CommonResponse(ErrorCodes.Http.Common.Header.BadFormat_IfNonMatch, "Header If-Non-Match is of bad format."); + var localizer = localizerFactory.Create("Models.Http.Common"); + return new CommonResponse(ErrorCodes.Http.Common.Header.Missing_ContentLength, localizer["HeaderMissingContentLength"]); } - public CommonResponse() + internal static CommonResponse ZeroContentLength(IStringLocalizerFactory localizerFactory) { + var localizer = localizerFactory.Create("Models.Http.Common"); + return new CommonResponse(ErrorCodes.Http.Common.Header.Zero_ContentLength, localizer["HeaderZeroContentLength"]); + } + internal static CommonResponse BadIfNonMatch(IStringLocalizerFactory localizerFactory) + { + var localizer = localizerFactory.Create("Models.Http.Common"); + return new CommonResponse(ErrorCodes.Http.Common.Header.BadFormat_IfNonMatch, localizer["HeaderBadIfNonMatch"]); } + } - public CommonResponse(int code, string message) + internal static class ContentErrorResponse + { + internal static CommonResponse TooBig(IStringLocalizerFactory localizerFactory, string maxLength) { - Code = code; - Message = message; + var localizer = localizerFactory.Create("Models.Http.Common"); + return new CommonResponse(ErrorCodes.Http.Common.Content.TooBig, localizer["ContentTooBig", maxLength]); } - public int Code { get; set; } - public string? Message { get; set; } + internal static CommonResponse UnmatchedLength_Smaller(IStringLocalizerFactory localizerFactory) + { + var localizer = localizerFactory.Create("Models.Http.Common"); + return new CommonResponse(ErrorCodes.Http.Common.Content.UnmatchedLength_Smaller, localizer["ContentUnmatchedLengthSmaller"]); + } + internal static CommonResponse UnmatchedLength_Bigger(IStringLocalizerFactory localizerFactory) + { + var localizer = localizerFactory.Create("Models.Http.Common"); + return new CommonResponse(ErrorCodes.Http.Common.Content.UnmatchedLength_Bigger, localizer["ContentUnmatchedLengthBigger"]); + } } + public class CommonDataResponse : CommonResponse { public CommonDataResponse() @@ -87,13 +115,13 @@ namespace Timeline.Models.Http internal static CommonPutResponse Create(IStringLocalizerFactory localizerFactory) { var localizer = localizerFactory.Create("Models.Http.Common"); - return new CommonPutResponse(0, localizer["ResponsePutCreate"], true); + return new CommonPutResponse(0, localizer["PutCreate"], true); } internal static CommonPutResponse Modify(IStringLocalizerFactory localizerFactory) { var localizer = localizerFactory.Create("Models.Http.Common"); - return new CommonPutResponse(0, localizer["ResponsePutModify"], false); + return new CommonPutResponse(0, localizer["PutModify"], false); } } @@ -124,13 +152,13 @@ namespace Timeline.Models.Http internal static CommonDeleteResponse Delete(IStringLocalizerFactory localizerFactory) { var localizer = localizerFactory.Create("Models.Http.Common"); - return new CommonDeleteResponse(0, localizer["ResponseDeleteDelete"], true); + return new CommonDeleteResponse(0, localizer["DeleteDelete"], true); } internal static CommonDeleteResponse NotExist(IStringLocalizerFactory localizerFactory) { var localizer = localizerFactory.Create("Models.Models.Http.Common"); - return new CommonDeleteResponse(0, localizer["ResponseDeleteNotExist"], false); + return new CommonDeleteResponse(0, localizer["DeleteNotExist"], false); } } } -- cgit v1.2.3