From 204dbc1f887f42e4a5ea734895ef36c5c434890f Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Fri, 16 Apr 2021 16:39:23 +0300 Subject: Add existing user get support --- src/handlers.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/handlers.rs') diff --git a/src/handlers.rs b/src/handlers.rs index ee0fbf0..c2c8aca 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -712,17 +712,28 @@ fn authorize_proposer(jwt_token: String, user_pem: &str) -> Result { - title: &'a str, - body: &'a str, +#[template(path = "list.html")] +struct UserTemplate<'a> { + users: &'a Vec, } -pub async fn welcome_handler() -> Result { - let template = WelcomeTemplate { - title: "Welcome", - body: "To The Bookstore!", - }; +struct DisplayUsers { + fingerprint: String, + balance: i32, +} + +pub async fn user_list_handler(db: Db) -> Result { + let users = db.users.read(); + let mut sane_users = Vec::new(); + + for (fingerprint, user) in users.iter() { + sane_users.push(DisplayUsers { + fingerprint: fingerprint.to_owned(), + balance: user.balance, + }); + } + + let template = UserTemplate { users: &sane_users }; let res = template.render().unwrap(); Ok(warp::reply::html(res)) } -- cgit v1.2.3-70-g09d2