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
pub struct OkHttpResponse<T> {
    status_code: usize,
    data: T,
}

pub struct ErrHttpResponse {
    status_code: usize,
    message: Option<String>
}

/// The status code enum
pub enum OkStatus {
    OK = 200,
    Created = 201,
    Accepted = 202,
    NoContent = 204,
}

pub enum ErrorStatus {
    BadRequest = 400,
    Unauthorized = 401,
    Forbidden = 403,
    NotFound = 404,
    InternalServerError = 500
}

impl<T> OkHttpResponse<T> {
    pub fn new(status: OkStatus, value: T) -> Self {
        Self {
            status_code: status as usize,
            data: value
        }
    }
}

impl ErrHttpResponse {
    pub fn new(status: ErrorStatus, message: Option<&str>) -> Self {
        Self {
            status_code: status as usize,
            message: match message {
                Some(m) => Some(m.to_owned()),
                None => None
            }
        }
    }
}