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
use super::*;

#[derive(Serialize)]
struct Request {
    email: Option<String>,
    password: Option<String>,
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        with = "::serde_with::rust::double_option"
    )]
    first_name: Option<Option<String>>,
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        with = "::serde_with::rust::double_option"
    )]
    last_name: Option<Option<String>>,
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        with = "::serde_with::rust::double_option"
    )]
    birthday: Option<Option<time::Date>>,
}

impl Client {
    pub async fn update_user(
        &self,
        user: i32,
        email: Option<String>,
        password: Option<String>,
        first_name: Option<Option<String>>,
        last_name: Option<Option<String>>,
        birthday: Option<Option<time::Date>>,
    ) -> Result<Option<()>, Box<dyn std::error::Error>> {
        let res = req()
            .put(self.endpoint("/v1/users/{}", vec![user.to_string()]))
            .json(&Request {
                email,
                password,
                first_name,
                last_name,
                birthday,
            })
            .send()
            .await?;

        match res.status() {
            StatusCode::NOT_FOUND => Ok(None),
            StatusCode::BAD_REQUEST => Err("Bad Request".into()),
            StatusCode::OK => Ok(Some(())),
            _ => Err("Unknown Response Status Code".into()),
        }
    }
}