diff options
author | 杨宇千 <crupest@outlook.com> | 2019-10-17 20:46:57 +0800 |
---|---|---|
committer | 杨宇千 <crupest@outlook.com> | 2019-10-17 20:46:57 +0800 |
commit | fa2a3282c51d831b25f374803301e75eac15d11c (patch) | |
tree | dc7688d7d2dd5ab28a7e3c553154ee84676f75d2 /Timeline/Models | |
parent | 21de8da2feab19d3fbc392e71bf0dcec25ec8d6b (diff) | |
download | timeline-fa2a3282c51d831b25f374803301e75eac15d11c.tar.gz timeline-fa2a3282c51d831b25f374803301e75eac15d11c.tar.bz2 timeline-fa2a3282c51d831b25f374803301e75eac15d11c.zip |
...
Diffstat (limited to 'Timeline/Models')
-rw-r--r-- | Timeline/Models/Http/Common.cs | 74 | ||||
-rw-r--r-- | Timeline/Models/Http/Token.cs | 2 |
2 files changed, 48 insertions, 28 deletions
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
- {
- /// <summary>
- /// Used when the model is invaid.
- /// For example a required field is null.
- /// </summary>
- 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<T> : 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<ResponseData> Create() =>
+ new CommonDataResponse<ResponseData>(0, "A new item is created.", new ResponseData(true));
+ public static CommonDataResponse<ResponseData> Modify() =>
+ new CommonDataResponse<ResponseData>(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<ResponseData> Delete() =>
+ new CommonDataResponse<ResponseData>(0, "An existent item is deleted.", new ResponseData(true));
+ public static CommonDataResponse<ResponseData> NotExist() =>
+ new CommonDataResponse<ResponseData>(0, "The item does not exist.", new ResponseData(false));
}
}
diff --git a/Timeline/Models/Http/Token.cs b/Timeline/Models/Http/Token.cs index 68a66d0a..615b6d8a 100644 --- a/Timeline/Models/Http/Token.cs +++ b/Timeline/Models/Http/Token.cs @@ -10,7 +10,7 @@ namespace Timeline.Models.Http public string Password { get; set; }
// in days, optional
[Range(1, 365)]
- public int? ExpireOffset { get; set; }
+ public int? Expire { get; set; }
}
public class CreateTokenResponse
|