aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Models/Http/Common.cs
blob: 6f6dbc1e3a903f3fa91e204bcf7190e1fa2a5379 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
namespace Timeline.Models.Http
{
    public class CommonResponse
    {
        public static CommonResponse InvalidModel(string message)
        {
            return new CommonResponse(ErrorCodes.Http.Common.InvalidModel, message);
        }

        public static CommonResponse MissingContentType()
        {
            return new CommonResponse(ErrorCodes.Http.Common.Header.Missing_ContentType, "Header Content-Type is required.");
        }

        public static CommonResponse MissingContentLength()
        {
            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.Http.Common.Header.Zero_ContentLength, "Header Content-Length must not be 0.");
        }

        public static CommonResponse BadIfNonMatch()
        {
            return new CommonResponse(ErrorCodes.Http.Common.Header.BadFormat_IfNonMatch, "Header If-Non-Match is of bad format.");
        }

        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; }
    }

    public static class CommonPutResponse
    {
        public class ResponseData
        {
            public ResponseData(bool create)
            {
                Create = create;
            }

            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 class ResponseData
        {
            public ResponseData(bool delete)
            {
                Delete = delete;
            }

            public bool Delete { get; set; }
        }

        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));
    }
}