change computer.
This commit is contained in:
1 parent
fe32c526eb
commit
358fb19076
10 files changed
+96
-12
No files matched your search
Generated
+1
@@ -1343,6 +1343,7 @@ dependencies = [
|
||||
"memo-map",
|
||||
"self_cell",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ tempfile = "3.3.0"
|
||||
fraction = "0.13.0"
|
||||
actix-web = "4.3.0"
|
||||
tokio = { version = "1.24.2", features = ["full"] }
|
||||
minijinja = { version = "0.30.2", features = ["source"] }
|
||||
minijinja = { version = "0.30.2", features = ["source", "builtins", "json"] }
|
||||
actix-utils = "3.0.1"
|
||||
actix-web-lab = "0.18.9"
|
||||
minijinja-autoreload = "0.30.2"
|
||||
|
||||
@@ -4,7 +4,18 @@
|
||||
|
||||
{% block body %}
|
||||
|
||||
<h1>Account!</h1>
|
||||
|
||||
<table class="uk-table uk-table-divider uk-table-striped uk-table-hover uk-table-small">
|
||||
<caption>Summary</caption>
|
||||
<tr><th>ID</th><td>{{ account.id }}</td></tr>
|
||||
<tr><th>Label</th><td>{{ account.label }}</td></tr>
|
||||
<tr><th>Amount</th><td>{{ account.amount }}</td></tr>
|
||||
<tr><th>Account Type</th><td>{{ account.account_type | replace("_", " ") | lower}}</td></tr>
|
||||
<tr><th>Last Update</th><td>{{ account.last_update }}</td></tr>
|
||||
<tr><th>Security</th><td>{{ account.security.symbol }}</td></tr>
|
||||
</table>
|
||||
|
||||
|
||||
<pre> {{ "hello" | tojson }}</pre>
|
||||
|
||||
{% endblock %}
|
||||
@@ -1,4 +1,9 @@
|
||||
|
||||
<input type="hidden"
|
||||
name="event.CreateWireTransfer.id"
|
||||
value="897898">
|
||||
|
||||
|
||||
<input type="hidden"
|
||||
name="event.CreateWireTransfer.drawer_user_id"
|
||||
value="{{ user.id }}">
|
||||
@@ -7,12 +12,12 @@
|
||||
<div class="uk-margin">
|
||||
<label class="uk-form-label"> Drawer Account
|
||||
<select class="uk-select"
|
||||
name="event.CreateWireTransfer.emitter_account"
|
||||
id="event.CreateWireTransfer.emitter_account"
|
||||
name="event.CreateWireTransfer.drawer_account_id"
|
||||
id="event.CreateWireTransfer.drawer_account_id"
|
||||
hx-get="/partials/actions/accounts-by-security-selectors"
|
||||
hx-trigger="change,load"
|
||||
hx-target="#onetwothree"
|
||||
hx-vals="js:{'sec-id': document.getElementById('event.CreateWireTransfer.emitter_account').options[document.getElementById('event.CreateWireTransfer.emitter_account').selectedIndex].getAttribute('data-sec-id')}"
|
||||
hx-vals="js:{'sec-id': document.getElementById('event.CreateWireTransfer.drawer_account_id').options[document.getElementById('event.CreateWireTransfer.drawer_account_id').selectedIndex].getAttribute('data-sec-id')}"
|
||||
hx-swap="innerHtml">
|
||||
{% for account in emitter_accounts %}
|
||||
<option value="{{ account.id }}" data-sec-id="{{ account.security.id }}">
|
||||
@@ -27,7 +32,7 @@
|
||||
<div class="uk-margin">
|
||||
<label class="uk-form-label"> Payee Accounts
|
||||
<select class="uk-select"
|
||||
name="event.CreateWireTransfer.payee_account"
|
||||
name="event.CreateWireTransfer.payee_account_id"
|
||||
id="onetwothree">
|
||||
</select>
|
||||
</label>
|
||||
|
||||
+14
-2
@@ -1,11 +1,11 @@
|
||||
use rusqlite::{Connection, Transaction};
|
||||
use crate::db::accounts;
|
||||
use crate::db::accounts::{AccountType, create_checking_account, create_security_emitter_account};
|
||||
use crate::db::accounts::{AccountType, create_checking_account, create_security_emitter_account, get_account_by_id};
|
||||
use crate::db::cheques::{Drawer, WireTransferRequest};
|
||||
|
||||
use crate::db::securities::create_security;
|
||||
use crate::db::users::create_user;
|
||||
use crate::events::{CreateNewAccount, CreateNewSecurity, CreateNewUser, EmitSecurities, Event};
|
||||
use crate::events::{CreateNewAccount, CreateNewSecurity, CreateNewUser, CreateWireTransfer, EmitSecurities, Event};
|
||||
use crate::services::cash_wire_transfer_request;
|
||||
use crate::util::{CustomResult, Error};
|
||||
|
||||
@@ -49,6 +49,17 @@ fn process_emit_securities_event(tx: &mut Transaction, event: EmitSecurities) ->
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process_create_wire_transfer(tx: &mut Transaction, event: CreateWireTransfer) -> CustomResult<()> {
|
||||
let sec_id = get_account_by_id(tx, &event.payee_account_id)?.security().id();
|
||||
let wire_transfer = WireTransferRequest::new(
|
||||
(event.drawer_user_id, event.drawer_account_id, sec_id),
|
||||
&event.payee_account_id,
|
||||
event.amount,
|
||||
event.id
|
||||
);
|
||||
cash_wire_transfer_request(tx, &wire_transfer)
|
||||
}
|
||||
|
||||
pub fn process_event(conn: &mut Connection, event: Event) -> CustomResult<()> {
|
||||
let mut tx = conn.transaction().map_err(Error::SqlError)?;
|
||||
let ret = match event {
|
||||
@@ -56,6 +67,7 @@ pub fn process_event(conn: &mut Connection, event: Event) -> CustomResult<()> {
|
||||
Event::CreateNewUser(e) => process_create_new_user_event(&mut tx, e),
|
||||
Event::CreateNewAccount(e) => process_create_new_account_event(&mut tx, e),
|
||||
Event::EmitSecurities(e) => process_emit_securities_event(&mut tx, e),
|
||||
Event::CreateWireTransfer(e) => process_create_wire_transfer(&mut tx, e),
|
||||
};
|
||||
match ret {
|
||||
Err(_) => {
|
||||
|
||||
+11
-1
@@ -1,5 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::db::external_id::{AccountId, SecurityId, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::db::securities::{NewSecurity, SecurityType};
|
||||
|
||||
@@ -54,12 +54,22 @@ pub struct EmitSecurities {
|
||||
pub payee_accounts: Vec<AccountId>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct CreateWireTransfer {
|
||||
pub id: i64,
|
||||
pub amount: i64,
|
||||
pub drawer_user_id: UserId,
|
||||
pub drawer_account_id: AccountId,
|
||||
pub payee_account_id: AccountId,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub enum Event {
|
||||
CreateNewSecurity(CreateNewSecurity),
|
||||
CreateNewUser(CreateNewUser),
|
||||
CreateNewAccount(CreateNewAccount),
|
||||
EmitSecurities(EmitSecurities),
|
||||
CreateWireTransfer(CreateWireTransfer),
|
||||
}
|
||||
|
||||
impl Event {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use rusqlite::Connection;
|
||||
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::db::external_id::{AccountId, Id, SecurityId, UserId};
|
||||
use crate::util::{CustomResult, Error};
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use crate::db::accounts;
|
||||
use crate::db::securities::Security;
|
||||
use crate::services::_securities::SecurityDTO;
|
||||
|
||||
@@ -59,6 +60,10 @@ impl AccountService<'_> {
|
||||
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())
|
||||
}
|
||||
|
||||
pub fn get_account_by_id(&self, account_id: &AccountId, user_id: &UserId) -> CustomResult<AccountDTO> {
|
||||
let ret = &accounts::get_account_by_id(self.conn, account_id)?;
|
||||
Ok(AccountDTO::from_entity(ret))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
use regex::Regex;
|
||||
//
|
||||
// fn is_number(value: String) -> bool{
|
||||
// true
|
||||
// }
|
||||
//
|
||||
// fn pretty_number(value: String) -> String {
|
||||
// let re = Regex::new(r"\d+").unwrap();
|
||||
// let cap = re.captures(&value);
|
||||
// if cap.is_none() {
|
||||
// return value;
|
||||
// }
|
||||
// let mut ret = "".to_string();
|
||||
// for (idx, letter) in value.as_bytes().iter().enumerate() {
|
||||
// ret.push(letter);
|
||||
// }
|
||||
// "foo".to_string()
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// #[cfg(test)]
|
||||
// pub mod test_minininja_utils {
|
||||
// use super::*;
|
||||
//
|
||||
// #[test]
|
||||
// fn test_pretty_number() {
|
||||
// assert_eq!(pretty_number("foo".to_string()), "foo");
|
||||
// }
|
||||
// }
|
||||
@@ -27,6 +27,7 @@ mod services;
|
||||
mod templates;
|
||||
mod views;
|
||||
mod worker;
|
||||
mod minininja_utils;
|
||||
|
||||
struct ProductionEventProcessor;
|
||||
|
||||
|
||||
+11
-2
@@ -8,7 +8,7 @@ use minijinja::context;
|
||||
use rusqlite::params;
|
||||
use serde::Deserialize;
|
||||
use uuid::Uuid;
|
||||
use crate::db::external_id::{Id, SecurityId};
|
||||
use crate::db::external_id::{AccountId, Id, SecurityId};
|
||||
|
||||
use crate::events::Event;
|
||||
|
||||
@@ -37,8 +37,17 @@ pub async fn accounts(tmpl_env: MiniJinjaRenderer,
|
||||
pub async fn account(tmpl_env: MiniJinjaRenderer,
|
||||
req: HttpRequest,
|
||||
service_factory: web::Data<ServicesFactory>) -> actix_web::Result<impl Responder> {
|
||||
let path_event_type = req.match_info().get("account_id").unwrap();
|
||||
let account_id = AccountId::from_string(&path_event_type.to_string()).unwrap();
|
||||
let conn = service_factory.get_connection()?;
|
||||
let auth_service = service_factory.get_authentication_service(&conn)?;
|
||||
let account_service = service_factory.get_account_service(& conn)?;
|
||||
let user_id = auth_service.get_login(&req).unwrap();
|
||||
|
||||
tmpl_env.render("account.html", context!{})
|
||||
let ctx = context!{
|
||||
account => account_service.get_account_by_id(&account_id, &user_id).map_err(error::ErrorInternalServerError)?
|
||||
};
|
||||
tmpl_env.render("account.html", ctx)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user