diff options
author | crupest <crupest@outlook.com> | 2021-01-07 16:23:20 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-01-07 16:23:20 +0800 |
commit | 7594a16e38304739487b053405153379faee6e58 (patch) | |
tree | bb99d1a24fffc9c4142219b9c25dc66e3d2b60d2 /BackEnd/Timeline/Models/Http/CommonResponse.cs | |
parent | 97e094c97dc9ed79cf7daa0a93568e1933015bdd (diff) | |
download | timeline-7594a16e38304739487b053405153379faee6e58.tar.gz timeline-7594a16e38304739487b053405153379faee6e58.tar.bz2 timeline-7594a16e38304739487b053405153379faee6e58.zip |
史诗级重构!
Diffstat (limited to 'BackEnd/Timeline/Models/Http/CommonResponse.cs')
-rw-r--r-- | BackEnd/Timeline/Models/Http/CommonResponse.cs | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Models/Http/CommonResponse.cs b/BackEnd/Timeline/Models/Http/CommonResponse.cs new file mode 100644 index 00000000..3d0ed509 --- /dev/null +++ b/BackEnd/Timeline/Models/Http/CommonResponse.cs @@ -0,0 +1,130 @@ +using static Timeline.Resources.Models.Http.Common;
+
+namespace Timeline.Models.Http
+{
+ public class CommonResponse
+ {
+ public CommonResponse()
+ {
+
+ }
+
+ public CommonResponse(int code, string message)
+ {
+ Code = code;
+ Message = message;
+ }
+
+ public int Code { get; set; }
+ 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; } = default!;
+ }
+
+ public class CommonPutResponse : CommonDataResponse<CommonPutResponse.ResponseData>
+ {
+ public class ResponseData
+ {
+ public ResponseData() { }
+
+ public ResponseData(bool create)
+ {
+ Create = create;
+ }
+
+ public bool Create { get; set; }
+ }
+
+ public CommonPutResponse()
+ {
+
+ }
+
+ public CommonPutResponse(int code, string message, bool create)
+ : base(code, message, new ResponseData(create))
+ {
+
+ }
+
+ internal static CommonPutResponse Create(bool create)
+ {
+ return new CommonPutResponse(0, MessagePutCreate, create);
+ }
+
+ internal static CommonPutResponse Create()
+ {
+ return new CommonPutResponse(0, MessagePutCreate, true);
+ }
+
+ internal static CommonPutResponse Modify()
+ {
+ return new CommonPutResponse(0, MessagePutModify, false);
+ }
+ }
+
+ /// <summary>
+ /// Common response for delete method.
+ /// </summary>
+ public class CommonDeleteResponse : CommonDataResponse<CommonDeleteResponse.ResponseData>
+ {
+ /// <summary></summary>
+ public class ResponseData
+ {
+ /// <summary></summary>
+ public ResponseData() { }
+
+ /// <summary></summary>
+ public ResponseData(bool delete)
+ {
+ Delete = delete;
+ }
+
+ /// <summary>
+ /// True if the entry is deleted. False if the entry does not exist.
+ /// </summary>
+ public bool Delete { get; set; }
+ }
+
+ /// <summary></summary>
+ public CommonDeleteResponse()
+ {
+
+ }
+
+ /// <summary></summary>
+ public CommonDeleteResponse(int code, string message, bool delete)
+ : base(code, message, new ResponseData(delete))
+ {
+
+ }
+
+ internal static CommonDeleteResponse Create(bool delete)
+ {
+ return new CommonDeleteResponse(0, MessageDeleteDelete, delete);
+ }
+
+ internal static CommonDeleteResponse Delete()
+ {
+ return new CommonDeleteResponse(0, MessageDeleteDelete, true);
+ }
+
+ internal static CommonDeleteResponse NotExist()
+ {
+ return new CommonDeleteResponse(0, MessageDeleteNotExist, false);
+ }
+ }
+}
|