WIP: get_progress

This commit is contained in:
Martin Brodbeck 2023-09-26 16:47:29 +02:00
parent 2fea6062f5
commit c8be7cdeee

View file

@ -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<Progress>) -> S
StatusCode::OK
}
async fn get_progress() {}
async fn get_progress(headers: HeaderMap, Path(document): Path<String>) -> 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<String> = con.hget(doc_key, &["progress", "percentage"]).unwrap();
println!("{values:?}");
StatusCode::OK
}
async fn healthcheck() -> (StatusCode, String) {
(StatusCode::OK, "{ \"state\" : \"OK\" }".to_owned())