Started to implement market size history.
This commit is contained in:
1 parent
e76a521356
commit
9faf6638a3
5 files changed
+29
-6
No files matched your search
+1
-2
@@ -460,8 +460,7 @@ pub fn get_security_market_cap(tx: &Connection, sec: &SecurityId) -> CustomResul
|
|||||||
let q = "
|
let q = "
|
||||||
SELECT COALESCE(-1 * SUM(amount), 0) AS count
|
SELECT COALESCE(-1 * SUM(amount), 0) AS count
|
||||||
FROM accounts
|
FROM accounts
|
||||||
WHERE security = ?
|
WHERE security = ? AND account_type = ?
|
||||||
AND account_type = ?
|
|
||||||
";
|
";
|
||||||
let params = params![sec, AccountType::SecurityEmitter.to_string()];
|
let params = params![sec, AccountType::SecurityEmitter.to_string()];
|
||||||
tx.query_row(q, params, |row| row.get("count"))
|
tx.query_row(q, params, |row| row.get("count"))
|
||||||
|
|||||||
@@ -49,4 +49,9 @@ impl SecurityService<'_> {
|
|||||||
pub fn get_security_market_cap(&self, sec_id: &SecurityId)-> CustomResult<i64> {
|
pub fn get_security_market_cap(&self, sec_id: &SecurityId)-> CustomResult<i64> {
|
||||||
accounts::get_security_market_cap(self.conn, sec_id)
|
accounts::get_security_market_cap(self.conn, sec_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_security_market_cap_history(&self, sec_id: &SecurityId)-> CustomResult<i64> {
|
||||||
|
Ok(89)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+19
-1
@@ -3,6 +3,7 @@ use crate::webui::services::ServicesFactory;
|
|||||||
use crate::webui::templates::MiniJinjaRenderer;
|
use crate::webui::templates::MiniJinjaRenderer;
|
||||||
use actix_web::{error, web, HttpRequest, Responder, Result};
|
use actix_web::{error, web, HttpRequest, Responder, Result};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use crate::db::external_id::SecurityId;
|
||||||
|
|
||||||
|
|
||||||
struct ResponseData{
|
struct ResponseData{
|
||||||
@@ -19,7 +20,6 @@ pub async fn get_account_amount_history(
|
|||||||
|
|
||||||
let conn = service_factory.get_connection()?;
|
let conn = service_factory.get_connection()?;
|
||||||
let auth_service = service_factory.get_authentication_service(&conn)?;
|
let auth_service = service_factory.get_authentication_service(&conn)?;
|
||||||
let conn = service_factory.get_connection()?;
|
|
||||||
let account_service = service_factory.get_account_service(&conn)?;
|
let account_service = service_factory.get_account_service(&conn)?;
|
||||||
let user_id = auth_service.get_login(&req).unwrap();
|
let user_id = auth_service.get_login(&req).unwrap();
|
||||||
let ac = account_service
|
let ac = account_service
|
||||||
@@ -28,3 +28,21 @@ pub async fn get_account_amount_history(
|
|||||||
|
|
||||||
Ok(web::Json(ac))
|
Ok(web::Json(ac))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[actix_web::get("/data/securities/{sec}/market-cap-history.json")]
|
||||||
|
pub async fn get_security_market_cap_history(
|
||||||
|
sec: web::Path<String>,
|
||||||
|
req: HttpRequest,
|
||||||
|
service_factory: web::Data<ServicesFactory>,
|
||||||
|
) -> Result<impl Responder> {
|
||||||
|
let sec_id = SecurityId::from_string(&sec.to_string()).unwrap();
|
||||||
|
|
||||||
|
let conn = service_factory.get_connection()?;
|
||||||
|
let security_service = service_factory.get_security_service(&conn)?;
|
||||||
|
let ac = security_service
|
||||||
|
.get_security_market_cap_history(&sec_id)
|
||||||
|
.map_err(error::ErrorInternalServerError)?;
|
||||||
|
|
||||||
|
Ok(web::Json(ac))
|
||||||
|
}
|
||||||
+3
-3
@@ -158,11 +158,11 @@ pub async fn actions_partials(
|
|||||||
let security_service = service_factory.get_security_service(&conn)?;
|
let security_service = service_factory.get_security_service(&conn)?;
|
||||||
let account_service = service_factory.get_account_service(&conn)?;
|
let account_service = service_factory.get_account_service(&conn)?;
|
||||||
let authentication_service = service_factory.get_authentication_service(&conn)?;
|
let authentication_service = service_factory.get_authentication_service(&conn)?;
|
||||||
let maybeUser = authentication_service.get_login(&req);
|
let maybe_user = authentication_service.get_login(&req);
|
||||||
if maybeUser.is_none() {
|
if maybe_user.is_none() {
|
||||||
return Err(actix_web::error::ErrorForbidden(""))
|
return Err(actix_web::error::ErrorForbidden(""))
|
||||||
}
|
}
|
||||||
let user = maybeUser.unwrap();
|
let user = maybe_user.unwrap();
|
||||||
let ctx = context! {
|
let ctx = context! {
|
||||||
event_type => event_type,
|
event_type => event_type,
|
||||||
securities => security_service.list_securities(),
|
securities => security_service.list_securities(),
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
cargo run users new --name didier.amyot@gmail.com --public-key fooof
|
cargo run users new --name didier.amyot@gmail.com --public-key fooof
|
||||||
|
cargo run users new --name justin.trudeau@gmail.com --public-key heho
|
||||||
Reference in new issue
Block a user