Added nice security page.
This commit is contained in:
1 parent
18e7b0df1c
commit
509794f02d
12 files changed
+103
-25
No files matched your search
+20
-3
@@ -65,10 +65,27 @@ pub async fn securities(tmpl_env: MiniJinjaRenderer,
|
||||
}
|
||||
|
||||
#[actix_web::get("/securities/{sec_id}")]
|
||||
pub async fn security(tmpl_env: MiniJinjaRenderer,
|
||||
service_factory: web::Data<ServicesFactory>) -> actix_web::Result<impl Responder> {
|
||||
pub async fn security(req: HttpRequest,
|
||||
tmpl_env: MiniJinjaRenderer,
|
||||
service_factory: web::Data<ServicesFactory>) -> actix_web::Result<impl Responder> {
|
||||
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 sec_id = &req.match_info()
|
||||
.get("sec_id")
|
||||
.and_then(|param|SecurityId::from_string(¶m.to_string()))
|
||||
.ok_or(error::ErrorNotFound("Invalid sec-id parameters"))?;
|
||||
|
||||
let ctx = context!{};
|
||||
|
||||
let sec = security_service.get_security_by_id(sec_id).map_err(error::ErrorInternalServerError)?;
|
||||
if sec.is_none() {
|
||||
return Err(error::ErrorNotFound(format!("No security with id {:}", sec_id)))
|
||||
}
|
||||
let ctx = context!{
|
||||
security => sec.unwrap(),
|
||||
account_numbers => account_service.get_number_of_accounts(sec_id).map_err(error::ErrorInternalServerError)?,
|
||||
market_cap => security_service.get_security_market_cap(sec_id).map_err(error::ErrorInternalServerError)?,
|
||||
};
|
||||
tmpl_env.render("security.html", ctx)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user