use anyhow::Result;
use sqlx::PgPool;
use uuid::Uuid;
use backbone_orm::org_scope;
use crate::domain::entity::Bank;
pub const TABLE_NAME: &str = "banking.banks";
pub struct BankRepository(backbone_orm::GenericCrudRepository<Bank, backbone_orm::SoftDelete>);
impl std::ops::Deref for BankRepository {
type Target = backbone_orm::GenericCrudRepository<Bank, backbone_orm::SoftDelete>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl BankRepository {
pub fn new(pool: PgPool) -> Self {
Self(backbone_orm::GenericCrudRepository::new(pool, TABLE_NAME))
}
}
pub struct NewBankRow<'a> {
pub id: Uuid,
pub name: &'a str,
pub swift_bic: Option<&'a str>,
pub country: &'a str,
}
impl BankRepository {
pub async fn insert_bank(&self, pool: &PgPool, b: &NewBankRow<'_>) -> Result<(), sqlx::Error> {
org_scope::execute_scoped(
pool,
sqlx::query(
r#"INSERT INTO banking.banks (id, name, swift_bic, country, status)
VALUES ($1,$2,$3,$4,'active')"#,
)
.bind(b.id)
.bind(b.name)
.bind(b.swift_bic)
.bind(b.country),
)
.await?;
Ok(())
}
}
backbone_core::impl_crud_repository!(BankRepository, Bank, soft_delete);