user-service 0.4.1

A user management microservice.
Documentation
use super::*;

#[derive(Serialize)]
struct Request {
    token: String,
    password: String,
}

#[derive(Deserialize)]
struct Response {
    id: i32,
    email: String,
}

#[derive(Debug)]
pub enum Returns {
    InvalidToken,
    Valid((i32, String)),
}

impl Client {
    // Returns ID of user and email
    pub async fn reset_password_set(
        &self,
        token: String,
        password: String,
    ) -> Result<Returns, Box<dyn std::error::Error>> {
        let res = req()
            .put(self.endpoint("/v1/users/reset", vec![]))
            .json(&Request { token, password })
            .send()
            .await?;

        match res.status() {
            StatusCode::NOT_FOUND => Ok(Returns::InvalidToken),
            StatusCode::BAD_REQUEST => Err("Bad Request".into()),
            StatusCode::OK => {
                let parsed = res.json::<Response>().await?;

                Ok(Returns::Valid((parsed.id, parsed.email)))
            }
            _ => Err("Unknown Response Status Code".into()),
        }
    }
}