use model::{AccessTokenString, RefreshTokenString}; use seed::fetch::{Header, Method, Request}; use crate::api::perform; pub async fn config() -> super::NetRes { perform(Request::new("/config").method(Method::Get)).await } pub async fn fetch_products() -> super::NetRes { perform(Request::new("/api/v1/products").method(Method::Get)).await } pub async fn fetch_product(product_id: model::ProductId) -> super::NetRes { perform(Request::new(format!("/api/v1/product/{}", product_id)).method(Method::Get)).await } pub async fn fetch_me(access_token: AccessTokenString) -> super::NetRes { perform( Request::new("/api/v1/me") .header(Header::bearer(access_token.as_str())) .method(Method::Get), ) .await } pub async fn sign_in(input: model::api::SignInInput) -> super::NetRes { perform( Request::new("/api/v1/sign-in") .method(Method::Post) .json(&input) .map_err(crate::api::NetRes::Http)?, ) .await } pub async fn verify_token(access_token: AccessTokenString) -> super::NetRes { perform( Request::new("/api/v1/token/verify") .method(Method::Post) .header(Header::bearer(access_token.as_str())), ) .await } pub async fn refresh_token( access_token: RefreshTokenString, ) -> super::NetRes { perform( Request::new("/api/v1/token/refresh") .method(Method::Post) .header(Header::bearer(access_token.as_str())), ) .await } pub async fn sign_up( input: model::api::CreateAccountInput, ) -> super::NetRes { perform( Request::new("/api/v1/register") .method(Method::Post) .json(&input) .map_err(crate::api::NetRes::Http)?, ) .await }