(feat) refactoring, migration, sqlx prepare
This commit is contained in:
parent
da3dfe40b0
commit
15b92ba3a4
17 changed files with 528 additions and 107 deletions
130
src/api/models.rs
Normal file
130
src/api/models.rs
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
// src/api/models.rs
|
||||
// This file contains all the data structures for the banking API.
|
||||
// These are the "nouns" of our API interaction.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use chrono::{DateTime, Utc, NaiveDate};
|
||||
|
||||
// --- Generic API Wrappers ---
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct ApiResponse<T> {
|
||||
pub data: T,
|
||||
pub links: Links,
|
||||
pub meta: Meta,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Links {
|
||||
#[serde(rename = "self")]
|
||||
pub self_link: String,
|
||||
pub next: Option<String>,
|
||||
pub prev: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Meta {
|
||||
pub total_pages: Option<i32>,
|
||||
pub total_records: Option<i32>,
|
||||
pub current_page: Option<i32>,
|
||||
pub page_size: Option<i32>,
|
||||
}
|
||||
|
||||
// --- Consent Models ---
|
||||
#[derive(Debug, Serialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ConsentRequestBody {
|
||||
pub client_id: String,
|
||||
pub permissions: Vec<String>,
|
||||
pub reason: String,
|
||||
pub requesting_bank: String,
|
||||
pub requesting_bank_name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub struct ConsentResponse {
|
||||
pub request_id: String,
|
||||
pub consent_id: String,
|
||||
pub status: String,
|
||||
pub message: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub auto_approved: bool,
|
||||
}
|
||||
|
||||
// --- Account & Transaction Models ---
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct AccountData {
|
||||
pub account: Vec<Account>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Account {
|
||||
pub account_id: String,
|
||||
pub status: Option<String>,
|
||||
pub currency: String,
|
||||
pub account_type: String,
|
||||
pub account_sub_type: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub nickname: String,
|
||||
pub opening_date: Option<NaiveDate>,
|
||||
pub account: Option<Vec<AccountIdentification>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AccountIdentification {
|
||||
pub scheme_name: String,
|
||||
pub identification: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct BalanceData {
|
||||
pub balance: Vec<Balance>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Balance {
|
||||
pub account_id: String,
|
||||
#[serde(rename = "type")]
|
||||
pub balance_type: String,
|
||||
pub date_time: DateTime<Utc>,
|
||||
pub amount: Amount,
|
||||
pub credit_debit_indicator: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TransactionData {
|
||||
pub transaction: Vec<Transaction>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Transaction {
|
||||
pub account_id: String,
|
||||
pub transaction_id: String,
|
||||
pub amount: Amount,
|
||||
pub credit_debit_indicator: String,
|
||||
pub status: String,
|
||||
pub booking_date_time: DateTime<Utc>,
|
||||
pub value_date_time: Option<DateTime<Utc>>,
|
||||
pub transaction_information: String,
|
||||
pub bank_transaction_code: Option<BankTransactionCode>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct Amount {
|
||||
pub amount: String,
|
||||
pub currency: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct BankTransactionCode {
|
||||
pub code: String,
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue