From fa2a3282c51d831b25f374803301e75eac15d11c Mon Sep 17 00:00:00 2001 From: 杨宇千 Date: Thu, 17 Oct 2019 20:46:57 +0800 Subject: ... --- Timeline/Models/Http/Common.cs | 74 +++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 27 deletions(-) (limited to 'Timeline/Models/Http/Common.cs') diff --git a/Timeline/Models/Http/Common.cs b/Timeline/Models/Http/Common.cs index a72f187c..af185e85 100644 --- a/Timeline/Models/Http/Common.cs +++ b/Timeline/Models/Http/Common.cs @@ -2,43 +2,29 @@ namespace Timeline.Models.Http { public class CommonResponse { - public static class ErrorCodes - { - /// - /// Used when the model is invaid. - /// For example a required field is null. - /// - public const int InvalidModel = -100; - - public const int Header_Missing_ContentType = -111; - public const int Header_Missing_ContentLength = -112; - public const int Header_Zero_ContentLength = -113; - public const int Header_BadFormat_IfNonMatch = -114; - } - public static CommonResponse InvalidModel(string message) { - return new CommonResponse(ErrorCodes.InvalidModel, message); + return new CommonResponse(ErrorCodes.Http.Common.InvalidModel, message); } public static CommonResponse MissingContentType() { - return new CommonResponse(ErrorCodes.Header_Missing_ContentType, "Header Content-Type is required."); + return new CommonResponse(ErrorCodes.Http.Common.Header.Missing_ContentType, "Header Content-Type is required."); } public static CommonResponse MissingContentLength() { - return new CommonResponse(ErrorCodes.Header_Missing_ContentLength, "Header Content-Length is missing or of bad format."); + return new CommonResponse(ErrorCodes.Http.Common.Header.Missing_ContentLength, "Header Content-Length is missing or of bad format."); } public static CommonResponse ZeroContentLength() { - return new CommonResponse(ErrorCodes.Header_Zero_ContentLength, "Header Content-Length must not be 0."); + return new CommonResponse(ErrorCodes.Http.Common.Header.Zero_ContentLength, "Header Content-Length must not be 0."); } public static CommonResponse BadIfNonMatch() { - return new CommonResponse(ErrorCodes.Header_BadFormat_IfNonMatch, "Header If-Non-Match is of bad format."); + return new CommonResponse(ErrorCodes.Http.Common.Header.BadFormat_IfNonMatch, "Header If-Non-Match is of bad format."); } public CommonResponse() @@ -56,21 +42,55 @@ namespace Timeline.Models.Http public string Message { get; set; } } + public class CommonDataResponse : CommonResponse + { + public CommonDataResponse() + { + + } + + public CommonDataResponse(int code, string message, T data) + : base(code, message) + { + Data = data; + } + + public T Data { get; set; } + } + public static class CommonPutResponse { - public const int CreatedCode = 0; - public const int ModifiedCode = 1; + public class ResponseData + { + public ResponseData(bool create) + { + Create = create; + } - public static CommonResponse Created { get; } = new CommonResponse(CreatedCode, "A new item is created."); - public static CommonResponse Modified { get; } = new CommonResponse(ModifiedCode, "An existent item is modified."); + public bool Create { get; set; } + } + + public static CommonDataResponse Create() => + new CommonDataResponse(0, "A new item is created.", new ResponseData(true)); + public static CommonDataResponse Modify() => + new CommonDataResponse(0, "An existent item is modified.", new ResponseData(false)); } public static class CommonDeleteResponse { - public const int DeletedCode = 0; - public const int NotExistsCode = 1; + public class ResponseData + { + public ResponseData(bool delete) + { + Delete = delete; + } + + public bool Delete { get; set; } + } - public static CommonResponse Deleted { get; } = new CommonResponse(DeletedCode, "An existent item is deleted."); - public static CommonResponse NotExists { get; } = new CommonResponse(NotExistsCode, "The item does not exist."); + public static CommonDataResponse Delete() => + new CommonDataResponse(0, "An existent item is deleted.", new ResponseData(true)); + public static CommonDataResponse NotExist() => + new CommonDataResponse(0, "The item does not exist.", new ResponseData(false)); } } -- cgit v1.2.3