/
rorikstr
/
multiberry-backend
Обзор
Документация
Войти
/
rorikstr
/
multiberry-backend
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/api/accounts.rs
105 строк
4 KB
Rorik Star Platinum
finish 30% lol
09 ноя 2025, 21:03
09 ноя 2025, 21:03
ea863ad
Код
Авторство
О чём код?
// src/api/accounts.rs use super::{client::{BankClient, BankingError}, models::{ApiResponse, AccountData, BalanceResponse}}; use tracing::{info, error, debug}; impl BankClient { pub async fn get_accounts( &self, client_id: &str, consent_id: &str, ) -> Result<ApiResponse<AccountData>, BankingError> { info!("📋 Fetching accounts for client_id: {}", client_id); let token = self.get_token().await?; debug!("✅ Got bank token"); let response = self.http_client .get(self.base_url.join("/accounts")?) .bearer_auth(token) .header("x-consent-id", consent_id) .header("x-requesting-bank", self.client_id.as_str()) .query(&[("client_id", client_id)]) .send() .await?; let status = response.status(); debug!("📥 Response status: {}", status); match response.status().is_success() { true => { let text = response.text().await?; info!("✅ Accounts response received"); serde_json::from_str::<ApiResponse<AccountData>>(&text) .map_err(|e| { error!("❌ Failed to deserialize AccountData: {}", e); BankingError::ApiError { status: 500, body: format!("Deserialization error: {}", e), } }) }, false => { let error_body = response.text().await.unwrap_or_default(); error!("❌ Bank API error status {}: {}", status, error_body); Err(BankingError::ApiError { status: status.as_u16(), body: error_body, }) } } } pub async fn get_balances( &self, account_id: &str, consent_id: &str, ) -> Result<BalanceResponse, BankingError> { info!("📊 Fetching balances for account: {}", account_id); let token = self.get_token().await?; debug!("✅ Got bank token"); let url = self.base_url.join(&format!("/accounts/{}/balances", account_id))?; debug!("📍 Calling: {}", url); let response = self.http_client .get(url) .bearer_auth(token) .header("x-consent-id", consent_id) .header("x-requesting-bank", self.client_id.as_str()) .send() .await?; let status = response.status(); debug!("📥 Response status: {}", status); match response.status().is_success() { true => { let text = response.text().await?; info!("✅ Balance response received"); serde_json::from_str::<BalanceResponse>(&text) .map_err(|e| { error!("❌ Failed to deserialize BalanceResponse: {}", e); error!("Raw: {}", text); BankingError::ApiError { status: 500, body: format!("Deserialization error: {}", e), } }) }, false => { let error_body = response.text().await.unwrap_or_default(); error!("❌ Bank API error status {}: {}", status, error_body); Err(BankingError::ApiError { status: status.as_u16(), body: error_body, }) } } } }