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 = "
|
||||
SELECT COALESCE(-1 * SUM(amount), 0) AS count
|
||||
FROM accounts
|
||||
WHERE security = ?
|
||||
AND account_type = ?
|
||||
WHERE security = ? AND account_type = ?
|
||||
";
|
||||
let params = params![sec, AccountType::SecurityEmitter.to_string()];
|
||||
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> {
|
||||
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 actix_web::{error, web, HttpRequest, Responder, Result};
|
||||
use serde::Serialize;
|
||||
use crate::db::external_id::SecurityId;
|
||||
|
||||
|
||||
struct ResponseData{
|
||||
@@ -19,7 +20,6 @@ pub async fn get_account_amount_history(
|
||||
|
||||
let conn = service_factory.get_connection()?;
|
||||
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 user_id = auth_service.get_login(&req).unwrap();
|
||||
let ac = account_service
|
||||
@@ -28,3 +28,21 @@ pub async fn get_account_amount_history(
|
||||
|
||||
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 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() {
|
||||
let maybe_user = authentication_service.get_login(&req);
|
||||
if maybe_user.is_none() {
|
||||
return Err(actix_web::error::ErrorForbidden(""))
|
||||
}
|
||||
let user = maybeUser.unwrap();
|
||||
let user = maybe_user.unwrap();
|
||||
let ctx = context! {
|
||||
event_type => event_type,
|
||||
securities => security_service.list_securities(),
|
||||
|
||||
Reference in new issue
Block a user