(feat) refactoring, migration, sqlx prepare
This commit is contained in:
parent
da3dfe40b0
commit
15b92ba3a4
17 changed files with 528 additions and 107 deletions
38
src/api/consents.rs
Normal file
38
src/api/consents.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// src/api/consents.rs
|
||||
// Consent request and retrieval logic
|
||||
|
||||
use super::{client::{BankClient, BankingError}, models::{ConsentRequestBody, ConsentResponse}};
|
||||
|
||||
impl BankClient {
|
||||
pub async fn request_consent(&self, client_id: &str) -> Result<ConsentResponse, BankingError> {
|
||||
let token = self.get_token().await?;
|
||||
|
||||
let body = ConsentRequestBody {
|
||||
client_id: client_id.to_string(),
|
||||
permissions: vec![
|
||||
"ReadAccountsDetail".to_string(),
|
||||
"ReadBalances".to_string(),
|
||||
"ReadTransactionsDetail".to_string(),
|
||||
],
|
||||
reason: "Account aggregation for Multiberry app".to_string(),
|
||||
requesting_bank: self.client_id.clone(),
|
||||
requesting_bank_name: "Multiberry Backend".to_string(),
|
||||
};
|
||||
|
||||
let response = self.http_client
|
||||
.post(self.base_url.join("/account-consents/request")?)
|
||||
.bearer_auth(token)
|
||||
.header("x-requesting-bank", self.client_id.as_str())
|
||||
.json(&body)
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
match response.status().is_success() {
|
||||
true => response.json().await.map_err(Into::into),
|
||||
false => Err(BankingError::ApiError {
|
||||
status: response.status().as_u16(),
|
||||
body: response.text().await.unwrap_or_default(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue