DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

6831a745b3e20aa77ae8195e13d264b1840ecb04 — Jonni Liljamo 1 year, 9 months ago dadf456
feat(shared): api call to get /api/user
1 files changed, 24 insertions(+), 0 deletions(-)

M shared/src/api/user/mod.rs
M shared/src/api/user/mod.rs => shared/src/api/user/mod.rs +24 -0
@@ 13,6 13,30 @@ use crate::{error::api::APIError, types::user::UserPub};

use super::macros::extract_cookie;

#[derive(Deserialize)]
#[serde(untagged)]
pub enum ResponseInfo {
    Error(APIError),
    Ok(UserPub),
}

#[derive(Deserialize)]
pub struct ResponseInfoWrapper {
    pub response: ResponseInfo,
    pub cookie: String,
}

pub fn info(api_address: &str, user_id: &str) -> ResponseInfoWrapper {
    let client = reqwest::blocking::Client::new();

    let resp = client.get(&format!("{}/user", api_address)).send().unwrap();

    ResponseInfoWrapper {
        cookie: extract_cookie!(resp),
        response: resp.json().unwrap(),
    }
}

#[derive(Serialize)]
pub struct PostLogin {
    pub email: String,