From 6831a745b3e20aa77ae8195e13d264b1840ecb04 Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Thu, 23 Mar 2023 13:06:14 +0200 Subject: [PATCH] feat(shared): api call to get /api/user --- shared/src/api/user/mod.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/shared/src/api/user/mod.rs b/shared/src/api/user/mod.rs index b24f770..1db7531 100644 --- a/shared/src/api/user/mod.rs +++ b/shared/src/api/user/mod.rs @@ -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, -- 2.44.1