Moved accumulation calculations into DB triggers
This commit is contained in:
parent
e336292db4
commit
79ef859fbe
9 changed files with 50 additions and 281 deletions
|
|
@ -85,10 +85,6 @@ async fn main() {
|
|||
"/accounts/id/:id/transaction",
|
||||
get(routes::api::transactions::list),
|
||||
)
|
||||
.route(
|
||||
"/accounts/id/:id/update",
|
||||
post(routes::api::accounts::snapshot_update),
|
||||
)
|
||||
.route(
|
||||
"/accounts/id/:id/recategorize",
|
||||
post(routes::api::accounts::recategorize),
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use serde::Deserialize;
|
|||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::users::UserToken;
|
||||
use accounters::models::Account;
|
||||
use accounters::models::account::Account;
|
||||
|
||||
pub async fn account_get(
|
||||
State(db): State<Arc<SqlitePool>>,
|
||||
|
|
@ -51,22 +51,6 @@ pub async fn account_list(
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn snapshot_update(
|
||||
State(db): State<Arc<SqlitePool>>,
|
||||
uid: UserToken,
|
||||
Path(account): Path<i32>,
|
||||
) -> (StatusCode, String) {
|
||||
let account = Account::get_by_id(db.as_ref(), account).await.unwrap();
|
||||
if account.get_user() != uid.user_id {
|
||||
return (StatusCode::UNAUTHORIZED, String::new());
|
||||
}
|
||||
|
||||
match account.recalculate_snapshots(db.as_ref(), None).await {
|
||||
Ok(_) => (StatusCode::OK, String::new()),
|
||||
Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, format!("{e}")),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn recategorize(
|
||||
State(db): State<Arc<SqlitePool>>,
|
||||
uid: UserToken,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use hyper::StatusCode;
|
|||
use serde::Deserialize;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use accounters::models::{transaction::TxConflictResolutionMode, Transaction};
|
||||
use accounters::models::transaction::{Transaction, TxConflictResolutionMode};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct TransactionContent {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use sqlx::SqlitePool;
|
|||
use tera::{Context, Tera};
|
||||
|
||||
use crate::users::UserToken;
|
||||
use accounters::models::{Account, Transaction};
|
||||
use accounters::models::{account::Account, transaction::Transaction};
|
||||
|
||||
pub mod account;
|
||||
pub mod categories;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@ use sqlx::SqlitePool;
|
|||
use tera::{Context, Tera};
|
||||
|
||||
use crate::users::UserToken;
|
||||
use accounters::models::{transaction::TxConflictResolutionMode, Account, Transaction};
|
||||
use accounters::models::{
|
||||
account::Account,
|
||||
transaction::{Transaction, TxConflictResolutionMode},
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct AccountViewParams {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue