aboutsummaryrefslogtreecommitdiff
path: root/src/app/store/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/store/mod.rs')
-rw-r--r--src/app/store/mod.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/app/store/mod.rs b/src/app/store/mod.rs
index cd4b859..870e402 100644
--- a/src/app/store/mod.rs
+++ b/src/app/store/mod.rs
@@ -33,6 +33,18 @@ impl Default for Context {
}
}
+impl std::fmt::Display for Context {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(
+ f,
+ "{}",
+ match self {
+ Self::SQLite(_) => "SQLite",
+ }
+ )
+ }
+}
+
pub struct AppContext {
context: Context,
accounts: Vec<FiduciaryAccount>,
@@ -94,6 +106,12 @@ impl AppContext {
pub fn init_context(&mut self) -> Result<(), ContextError> {
self.unwrap_store().0.init()?;
+ tracing::event!(
+ tracing::Level::DEBUG,
+ context = self.context.to_string(),
+ "Store initialized."
+ );
+
self.accounts = self.get_store().get_accounts()?;
self.symbols = self.get_store().get_symbols()?;
self.events = self.get_store().get_events()?;
@@ -116,6 +134,11 @@ impl AppContext {
pub fn add_account(&mut self, account: FiduciaryAccount) -> Result<(), ContextError> {
let (store, accounts, ..) = self.unwrap_store();
let acc = accounts.push_mut(account);
+ tracing::event!(
+ tracing::Level::TRACE,
+ fiduciary_account_id = acc.fiduciary_account_id,
+ "Added account to context."
+ );
store.add_account(acc)?;
Ok(())
@@ -124,6 +147,11 @@ impl AppContext {
pub fn add_symbol(&mut self, symbol: EquitySymbol) -> Result<(), ContextError> {
let (store, _, symbols, ..) = self.unwrap_store();
let sym = symbols.push_mut(symbol);
+ tracing::event!(
+ tracing::Level::TRACE,
+ equity_symbol_id = sym.equity_symbol_id,
+ "Added symbol to context."
+ );
store.add_symbol(sym)?;
Ok(())
@@ -132,6 +160,11 @@ impl AppContext {
pub fn add_event(&mut self, event: EquityChangeEvent) -> Result<(), ContextError> {
let (store, .., events) = self.unwrap_store();
let ev = events.push_mut(event);
+ tracing::event!(
+ tracing::Level::TRACE,
+ equity_change_event_id = ev.equity_change_event_id,
+ "Added event to context."
+ );
store.add_event(ev)?;
Ok(())