diff options
author | Yigit Sever | 2021-04-16 16:39:23 +0300 |
---|---|---|
committer | Yigit Sever | 2021-04-16 16:39:23 +0300 |
commit | 204dbc1f887f42e4a5ea734895ef36c5c434890f (patch) | |
tree | 5fc3f838de25513c8f0b0eaf068a0b24b6f89619 /src | |
parent | a4667e5b15273bea2e5eb2f1b417b35e0de12e5e (diff) | |
download | gradecoin-204dbc1f887f42e4a5ea734895ef36c5c434890f.tar.gz gradecoin-204dbc1f887f42e4a5ea734895ef36c5c434890f.tar.bz2 gradecoin-204dbc1f887f42e4a5ea734895ef36c5c434890f.zip |
Add existing user get support
Diffstat (limited to 'src')
-rw-r--r-- | src/handlers.rs | 29 | ||||
-rw-r--r-- | src/routes.rs | 9 |
2 files changed, 29 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")] |
716 | struct WelcomeTemplate<'a> { | 716 | struct UserTemplate<'a> { |
717 | title: &'a str, | 717 | users: &'a Vec<DisplayUsers>, |
718 | body: &'a str, | ||
719 | } | 718 | } |
720 | 719 | ||
721 | pub async fn welcome_handler() -> Result<impl warp::Reply, warp::Rejection> { | 720 | struct DisplayUsers { |
722 | let template = WelcomeTemplate { | 721 | fingerprint: String, |
723 | title: "Welcome", | 722 | balance: i32, |
724 | body: "To The Bookstore!", | 723 | } |
725 | }; | 724 | |
725 | pub 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 | } |
diff --git a/src/routes.rs b/src/routes.rs index 52d357a..211f832 100644 --- a/src/routes.rs +++ b/src/routes.rs | |||
@@ -18,10 +18,19 @@ pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rej | |||
18 | .or(register_user(db.clone())) | 18 | .or(register_user(db.clone())) |
19 | .or(auth_transaction_propose(db.clone())) | 19 | .or(auth_transaction_propose(db.clone())) |
20 | .or(auth_block_propose(db.clone())) | 20 | .or(auth_block_propose(db.clone())) |
21 | .or(list_users(db.clone())) | ||
21 | .or(block_list(db)) | 22 | .or(block_list(db)) |
22 | .or(static_route) | 23 | .or(static_route) |
23 | } | 24 | } |
24 | 25 | ||
26 | /// GET /user warp route | ||
27 | pub fn list_users(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | ||
28 | warp::path!("user") | ||
29 | .and(warp::get()) | ||
30 | .and(custom_filters::with_db(db)) | ||
31 | .and_then(handlers::user_list_handler) | ||
32 | } | ||
33 | |||
25 | /// POST /register warp route | 34 | /// POST /register warp route |
26 | pub fn register_user(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { | 35 | pub fn register_user(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { |
27 | warp::path!("register") | 36 | warp::path!("register") |