implement meta api in client

This commit is contained in:
DSeeLP 2025-04-17 12:39:45 +02:00
parent 609f2bd001
commit f5b4c6211b

View File

@ -5,6 +5,7 @@ use bank_core::{
ApiError, NameOrUuid, TokenResponse, ApiError, NameOrUuid, TokenResponse,
account::{Account, UserAccountInfo}, account::{Account, UserAccountInfo},
chat::{Chat, ChatInfo, ChatMessage, SendMessage, StartChat}, chat::{Chat, ChatInfo, ChatMessage, SendMessage, StartChat},
meta::{Bank, Motd},
pagination::{Pagination, RequestPagination}, pagination::{Pagination, RequestPagination},
transaction::{Direction, Transaction}, transaction::{Direction, Transaction},
user::{User, UserAccounts, UserBalance}, user::{User, UserAccounts, UserBalance},
@ -162,10 +163,6 @@ pub async fn handle_response<T: DeserializeOwned>(
} }
} }
pub struct UsersApi<'a> {
api: &'a ApiClient,
}
macro_rules! request { macro_rules! request {
($api:expr, $method:ident, $path:expr) => {{ ($api:expr, $method:ident, $path:expr) => {{
let api = &$api; let api = &$api;
@ -173,6 +170,28 @@ macro_rules! request {
}}; }};
} }
pub struct MetaApi<'a> {
api: &'a ApiClient,
}
impl MetaApi<'_> {
pub async fn motd(&self) -> Result<Motd, ClientError> {
let response = request!(self.api, get, "/api/meta/motd").send().await?;
let body = handle_response(response).await?;
Ok(body)
}
pub async fn bank(&self) -> Result<Bank, ClientError> {
let response = request!(self.api, get, "/api/meta/bank").send().await?;
let body = handle_response(response).await?;
Ok(body)
}
}
pub struct UsersApi<'a> {
api: &'a ApiClient,
}
impl UsersApi<'_> { impl UsersApi<'_> {
pub async fn list(&self, limit: u64, offset: u64) -> Result<Pagination<User>, ClientError> { pub async fn list(&self, limit: u64, offset: u64) -> Result<Pagination<User>, ClientError> {
let response = request!( let response = request!(