2022-05-10 16:20:37 +02:00
|
|
|
use model::{AccessTokenString, RefreshTokenString};
|
2022-05-15 10:30:15 +02:00
|
|
|
use seed::fetch::{Header, Method, Request};
|
2022-05-09 16:17:27 +02:00
|
|
|
|
2022-05-15 10:30:15 +02:00
|
|
|
use crate::api::perform;
|
|
|
|
|
|
|
|
pub async fn fetch_products() -> super::NetRes<model::api::Products> {
|
|
|
|
perform(Request::new("/api/v1/products").method(Method::Get)).await
|
2022-05-09 16:17:27 +02:00
|
|
|
}
|
2022-05-10 16:20:37 +02:00
|
|
|
|
2022-05-15 10:30:15 +02:00
|
|
|
pub async fn fetch_product(product_id: model::ProductId) -> super::NetRes<model::api::Product> {
|
|
|
|
perform(Request::new(format!("/api/v1/product/{}", product_id)).method(Method::Get)).await
|
2022-05-11 15:56:41 +02:00
|
|
|
}
|
|
|
|
|
2022-05-15 10:30:15 +02:00
|
|
|
pub async fn fetch_me(access_token: AccessTokenString) -> super::NetRes<model::Account> {
|
|
|
|
perform(
|
|
|
|
Request::new("/api/v1/me")
|
|
|
|
.header(Header::bearer(access_token.as_str()))
|
|
|
|
.method(Method::Get),
|
|
|
|
)
|
|
|
|
.await
|
2022-05-10 16:20:37 +02:00
|
|
|
}
|
|
|
|
|
2022-05-15 10:30:15 +02:00
|
|
|
pub async fn sign_in(input: model::api::SignInInput) -> super::NetRes<model::api::SessionOutput> {
|
|
|
|
perform(
|
|
|
|
Request::new("/api/v1/sign-in")
|
|
|
|
.method(Method::Post)
|
|
|
|
.json(&input)
|
|
|
|
.map_err(crate::api::NetRes::Http)?,
|
|
|
|
)
|
|
|
|
.await
|
2022-05-10 16:20:37 +02:00
|
|
|
}
|
|
|
|
|
2022-05-15 10:30:15 +02:00
|
|
|
pub async fn verify_token(access_token: AccessTokenString) -> super::NetRes<String> {
|
|
|
|
perform(
|
|
|
|
Request::new("/api/v1/token/verify")
|
|
|
|
.method(Method::Post)
|
|
|
|
.header(Header::bearer(access_token.as_str())),
|
|
|
|
)
|
|
|
|
.await
|
2022-05-10 16:20:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn refresh_token(
|
|
|
|
access_token: RefreshTokenString,
|
2022-05-15 10:30:15 +02:00
|
|
|
) -> super::NetRes<model::api::SessionOutput> {
|
|
|
|
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<model::api::SessionOutput> {
|
|
|
|
perform(
|
|
|
|
Request::new("/api/v1/register")
|
|
|
|
.method(Method::Post)
|
|
|
|
.json(&input)
|
|
|
|
.map_err(crate::api::NetRes::Http)?,
|
|
|
|
)
|
|
|
|
.await
|
2022-05-10 16:20:37 +02:00
|
|
|
}
|