From 0333b12fb3dd48cb793ed8ac61842dc8fa1cd82e Mon Sep 17 00:00:00 2001 From: structix Date: Thu, 2 Apr 2026 21:14:14 +0200 Subject: [PATCH] Add user route --- src/http_server.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/http_server.rs b/src/http_server.rs index f4157cc..f405df5 100644 --- a/src/http_server.rs +++ b/src/http_server.rs @@ -39,6 +39,7 @@ pub async fn http_serve(database: &Database, mpris_producer: Sender<(String, Str .route("/userid/{user_id}", get(add_userid)) .route("/usercard/{user_card}", get(add_userid_by_card)) .route("/{user_id}/{rating}", get(add_rating)) + .route("/adduser/{user_id}/{name}", get(add_user)) .with_state(shared_state); let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); @@ -63,7 +64,26 @@ async fn add_rating( .user_add_rating(user_id, &interpret, &track, rating) .await { - Ok(_) => (StatusCode::OK, "Done.").into_response(), + Ok(_) => { + eprintln!("ID: {user_id}, Rating: {rating}"); + (StatusCode::OK, "Done.").into_response() + } + Err(e) => { + eprintln!("HTTP error: {e}"); + (StatusCode::BAD_REQUEST, e.to_string()).into_response() + } + } +} + +async fn add_user( + Path((user_id, name)): Path<(i64, String)>, + State(shared): State, +) -> Response { + match shared.database.add_user_id(user_id, &name).await { + Ok(_) => { + eprintln!("ID: {user_id}, Name: {name}"); + (StatusCode::OK, "Done.").into_response() + } Err(e) => { eprintln!("HTTP error: {e}"); (StatusCode::BAD_REQUEST, e.to_string()).into_response()