admin panel change into subsequent pages
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -288,9 +288,10 @@ async fn get_admin(
|
||||
if !authorised {
|
||||
return get_page(req, "/unauthorised", db).await;
|
||||
}
|
||||
match path {
|
||||
"/admin" => get_page(req, path, db).await,
|
||||
"/admin/users" => {
|
||||
if path.starts_with("/admin/data") {
|
||||
let path = path.strip_prefix("/admin/data").unwrap();
|
||||
match path {
|
||||
"/users" => {
|
||||
let pool = db.clone().lock().unwrap().clone();
|
||||
let users = sqlx::query!(r#"SELECT id, username, permissions FROM users"#)
|
||||
.fetch_all(&pool)
|
||||
@@ -303,7 +304,7 @@ async fn get_admin(
|
||||
let stringed = serde_json::to_string(&users).unwrap_or("".to_string());
|
||||
Ok(Response::builder().body(Body::new(stringed)).unwrap())
|
||||
}
|
||||
"/admin/players" => {
|
||||
"/players" => {
|
||||
let pool = db.clone().lock().unwrap().clone();
|
||||
let players = sqlx::query_as!(Player, r#"SELECT id, name FROM players"#)
|
||||
.fetch_all(&pool)
|
||||
@@ -312,7 +313,7 @@ async fn get_admin(
|
||||
let stringed = serde_json::to_string(&players).unwrap_or("".to_string());
|
||||
Ok(Response::builder().body(Body::new(stringed)).unwrap())
|
||||
}
|
||||
"/admin/votes" => {
|
||||
"/votes" => {
|
||||
let pool = db.clone().lock().unwrap().clone();
|
||||
let votes = sqlx::query_as!(Vote, r#"SELECT * FROM votes"#)
|
||||
.fetch_all(&pool)
|
||||
@@ -322,7 +323,9 @@ async fn get_admin(
|
||||
Ok(Response::builder().body(Body::new(stringed)).unwrap())
|
||||
}
|
||||
_ => not_found().await,
|
||||
}
|
||||
}}
|
||||
else if path.starts_with("/admin") {get_page(req, path, db).await}
|
||||
else {not_found().await}
|
||||
}
|
||||
|
||||
async fn post(req: Request<Incoming>, db: Arc<Mutex<SqlitePool>>) -> Result<Response<Body>, Error> {
|
||||
|
||||
Reference in New Issue
Block a user