diff --git a/src/main.rs b/src/main.rs index deca252..5816dc4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use axum::{ - http::HeaderMap, http::StatusCode, routing::get, routing::post, routing::put, Json, Router, + extract::Path, http::HeaderMap, http::StatusCode, routing::get, routing::post, routing::put, + Json, Router, }; use serde::Deserialize; @@ -132,7 +133,25 @@ async fn update_progress(headers: HeaderMap, Json(payload): Json) -> S StatusCode::OK } -async fn get_progress() {} +async fn get_progress(headers: HeaderMap, Path(document): Path) -> StatusCode { + let username = headers["x-auth-user"].to_str().unwrap_or(""); + let password = headers["x-auth-key"].to_str().unwrap_or(""); + + if authorize(username, password) == false { + return StatusCode::UNAUTHORIZED; + } + + let client = redis::Client::open("redis://127.0.0.1/").unwrap(); + let mut con = client.get_connection().unwrap(); + + let doc_key = format!("user:{username}:document:{document}"); + + let values : Vec = con.hget(doc_key, &["progress", "percentage"]).unwrap(); + + println!("{values:?}"); + + StatusCode::OK +} async fn healthcheck() -> (StatusCode, String) { (StatusCode::OK, "{ \"state\" : \"OK\" }".to_owned())