aboutsummaryrefslogtreecommitdiffstats
path: root/src/handlers.rs
diff options
context:
space:
mode:
authoryigit sever2021-04-16 13:40:17 +0000
committeryigit sever2021-04-16 13:40:17 +0000
commite81b6af56436be291adf31f770c6ef7e8ddfdbd0 (patch)
treeb1d02cfccf1f3004f5a9e6bcc68dfef180c08150 /src/handlers.rs
parentc28b07a494ea39f91283601251061366a9f5e93e (diff)
parent204dbc1f887f42e4a5ea734895ef36c5c434890f (diff)
downloadgradecoin-e81b6af56436be291adf31f770c6ef7e8ddfdbd0.tar.gz
gradecoin-e81b6af56436be291adf31f770c6ef7e8ddfdbd0.tar.bz2
gradecoin-e81b6af56436be291adf31f770c6ef7e8ddfdbd0.zip
Merge pull request 'Add existing user get support' (#1) from usershow into main
Reviewed-on: https://git.yigitsever.com/yigit/gradecoin/pulls/1
Diffstat (limited to 'src/handlers.rs')
-rw-r--r--src/handlers.rs29
1 files changed, 20 insertions, 9 deletions
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<TokenData<Cla
712} 712}
713 713
714#[derive(Template)] 714#[derive(Template)]
715#[template(path = "welcome.html")] 715#[template(path = "list.html")]
716struct WelcomeTemplate<'a> { 716struct UserTemplate<'a> {
717 title: &'a str, 717 users: &'a Vec<DisplayUsers>,
718 body: &'a str,
719} 718}
720 719
721pub async fn welcome_handler() -> Result<impl warp::Reply, warp::Rejection> { 720struct DisplayUsers {
722 let template = WelcomeTemplate { 721 fingerprint: String,
723 title: "Welcome", 722 balance: i32,
724 body: "To The Bookstore!", 723}
725 }; 724
725pub async fn user_list_handler(db: Db) -> Result<impl warp::Reply, warp::Rejection> {
726 let users = db.users.read();
727 let mut sane_users = Vec::new();
728
729 for (fingerprint, user) in users.iter() {
730 sane_users.push(DisplayUsers {
731 fingerprint: fingerprint.to_owned(),
732 balance: user.balance,
733 });
734 }
735
736 let template = UserTemplate { users: &sane_users };
726 let res = template.render().unwrap(); 737 let res = template.render().unwrap();
727 Ok(warp::reply::html(res)) 738 Ok(warp::reply::html(res))
728} 739}