Going somewhere.

This commit is contained in:
didier amyot committed 2023-04-03 11:55:34 -04:00
1 parent 0d0337a6aa
commit f140b50be4
17 files changed
+211 -20

No files matched your search

+20 -4
View File
@@ -1,9 +1,12 @@
use rusqlite::Connection;
use crate::db::accounts::{Account, list_user_accounts};
use crate::db::external_id::{Id, UserId};
use crate::db::accounts::{Account, AccountType, get_checking_accounts_for_sec_id, list_user_accounts};
use crate::db::external_id::{Id, SecurityId, UserId};
use crate::util::{CustomResult, Error};
use serde::Deserialize;
use serde::Serialize;
use crate::db::securities::Security;
use crate::services::_securities::SecurityDTO;
pub struct AccountService<'a> {
conn: &'a Connection,
}
@@ -14,7 +17,7 @@ pub struct AccountDTO {
pub amount: i64,
pub account_type: String,
pub last_update: i64,
pub security_symbol: String,
pub security: SecurityDTO,
}
impl AccountDTO {
@@ -24,7 +27,7 @@ impl AccountDTO {
amount: account.amount(),
account_type: account.account_type().to_string(),
last_update: account.timestamp(),
security_symbol: account.security().symbol()
security: SecurityDTO::from_entity(account.security())
}
}
}
@@ -43,4 +46,17 @@ impl AccountService<'_> {
Ok(ret.iter().map(AccountDTO::from_entity).collect())
}
pub fn get_user_emitter_accounts(& self, user_id: &UserId) -> CustomResult<Vec<AccountDTO>> {
let accounts = self.get_user_accounts(user_id)?;
let ret = accounts.into_iter()
.filter(|acc| acc.account_type == AccountType::SecurityEmitter.to_string())
.collect();
Ok(ret)
}
pub fn get_checking_accounts_for_security(& self, sec_id: & SecurityId) -> CustomResult<Vec<AccountDTO>>{
let ret = get_checking_accounts_for_sec_id(self.conn, sec_id)?;
Ok(ret.iter().map(AccountDTO::from_entity).collect())
}
}