Started to implement accounts in the UI.

This commit is contained in:
didier amyot committed 2023-04-01 09:16:38 -04:00
1 parent ce92916942
commit 76e1e8cb53
7 files changed
+172 -9

No files matched your search

+9 -1
View File
@@ -1,4 +1,4 @@
use crate::services::{SecurityService, SessionService, UserService};
use crate::services::{SecurityService, SessionService, UserService, AccountService};
use actix_web::{error, Result};
use r2d2::PooledConnection;
@@ -55,4 +55,12 @@ impl ServicesFactory {
) -> Result<SecurityService> {
Ok(SecurityService::new(conn))
}
pub fn get_account_service<'a>(
&'a self,
conn: &'a PooledConnection<SqliteConnectionManager>,
)-> Result<AccountService> {
Ok(AccountService::new(conn))
}
}
+11 -2
View File
@@ -5,6 +5,7 @@ use actix_web_lab::respond::Html;
use log::info;
use minijinja::context;
use rusqlite::params;
use serde::Deserialize;
use uuid::Uuid;
@@ -19,8 +20,16 @@ pub async fn actions(tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Resp
}
#[actix_web::get("/accounts")]
pub async fn accounts(tmpl_env: MiniJinjaRenderer) -> actix_web::Result<impl Responder> {
tmpl_env.render("accounts.html", ())
pub async fn accounts(tmpl_env: MiniJinjaRenderer,
req: HttpRequest,
service_factory: web::Data<ServicesFactory>) -> actix_web::Result<impl Responder> {
let conn = service_factory.get_connection()?;
let auth_service = service_factory.get_authentication_service()?;
let user = auth_service.get_login(&req);
let account_service = service_factory.get_account_service(& conn)?;
let accounts = account_service.get_user_accounts(user.unwrap())
.map_err(actix_web::error::ErrorInternalServerError)?;
tmpl_env.render("accounts.html", context!{accounts => accounts})
}
#[actix_web::get("/overview")]