Add user route
This commit is contained in:
@@ -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<SharedState>,
|
||||
) -> 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()
|
||||
|
||||
Reference in New Issue
Block a user