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

+57 -1
View File
@@ -8,6 +8,7 @@ use minijinja::context;
use rusqlite::params;
use serde::Deserialize;
use uuid::Uuid;
use crate::db::external_id::{Id, SecurityId};
use crate::events::Event;
@@ -32,6 +33,14 @@ pub async fn accounts(tmpl_env: MiniJinjaRenderer,
tmpl_env.render("accounts.html", context!{accounts => accounts})
}
#[actix_web::get("/accounts/{account_id}")]
pub async fn account(tmpl_env: MiniJinjaRenderer,
req: HttpRequest,
service_factory: web::Data<ServicesFactory>) -> actix_web::Result<impl Responder> {
tmpl_env.render("account.html", context!{})
}
#[actix_web::get("/securities")]
@@ -45,6 +54,14 @@ pub async fn securities(tmpl_env: MiniJinjaRenderer,
tmpl_env.render("securities.html", ctx)
}
#[actix_web::get("/securities/{sec_id}")]
pub async fn security(tmpl_env: MiniJinjaRenderer,
service_factory: web::Data<ServicesFactory>) -> actix_web::Result<impl Responder> {
let ctx = context!{};
tmpl_env.render("security.html", ctx)
}
#[actix_web::get("/overview")]
pub async fn overview(
tmpl_env: MiniJinjaRenderer,
@@ -71,6 +88,37 @@ pub async fn overview_submit_button(
tmpl_env.render("partials/overview/submit_button.html", ctx)
}
#[actix_web::get("/partials/actions/accounts-by-security-selectors")]
pub async fn get_accounts_by_security_selectors(
req: HttpRequest,
tmpl_env: MiniJinjaRenderer,
query: web::Query<HashMap<String, String>>,
service_factory: web::Data<ServicesFactory>,
) -> actix_web::Result<Html> {
let sec_id = query
.get("sec-id")
.and_then(SecurityId::from_string)
.ok_or(error::ErrorBadRequest("Invalid sec-id parameters"))?;
let conn = service_factory.get_connection()?;
let account_service = service_factory.get_account_service(&conn)?;
let authentication_service = service_factory.get_authentication_service(&conn)?;
let maybe_user = authentication_service.get_login(&req);
if maybe_user.is_none() {
return Err(error::ErrorForbidden(""))
}
let user_id = maybe_user.unwrap();
let ctx = context! {
sec_id => &sec_id,
user_id => &user_id,
accounts => account_service.get_checking_accounts_for_security(&sec_id).map_err(error::ErrorInternalServerError)?,
};
tmpl_env.render("partials/actions/accounts-by-security-selectors.html", ctx)
}
#[actix_web::get("/partials/actions/action-form")]
pub async fn actions_partials(
req: HttpRequest,
@@ -84,11 +132,19 @@ pub async fn actions_partials(
.to_string();
let conn = service_factory.get_connection()?;
let security_service = service_factory.get_security_service(&conn)?;
let account_service = service_factory.get_account_service(&conn)?;
let authentication_service = service_factory.get_authentication_service(&conn)?;
let maybeUser = authentication_service.get_login(&req);
if maybeUser.is_none() {
return Err(actix_web::error::ErrorForbidden(""))
}
let user = maybeUser.unwrap();
let ctx = context! {
event_type => event_type,
securities => security_service.list_securities(),
user => authentication_service.get_logged_in_user(&req).map_err(actix_web::error::ErrorInternalServerError)?,
emitter_accounts => account_service.get_user_emitter_accounts(&user).map_err(error::ErrorInternalServerError)?,
accounts => account_service.get_user_emitter_accounts(&user).map_err(error::ErrorInternalServerError)?,
user => authentication_service.get_logged_in_user(&req).map_err(error::ErrorInternalServerError)?,
};
let template_location = format!("partials/actions/{:}.html", event_type);
info!("Getting template at: {:?}", template_location);