From 2e8d3d27018600b337fc17ef3c664c23c912f278 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Tue, 26 Sep 2023 12:48:53 +0200 Subject: [PATCH] refix --- src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2133644..32bfe72 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,7 @@ async fn root() -> &'static str { "KOreader sync server" } -async fn create_user(Json(payload): Json) -> StatusCode { +async fn create_user(Json(payload): Json) -> (StatusCode, String) { let client = redis::Client::open("redis://127.0.0.1/").unwrap(); let mut con = client.get_connection().unwrap(); @@ -50,10 +50,13 @@ async fn create_user(Json(payload): Json) -> StatusCode { if does_exist == false { let _: () = con.set(&user_key, password).unwrap(); } else { - return StatusCode::PAYMENT_REQUIRED; + return ( + StatusCode::PAYMENT_REQUIRED, + "Username is already registered.".to_owned(), + ); } - StatusCode::CREATED + (StatusCode::CREATED, format!("username = {username}")) } async fn auth_user(headers: HeaderMap) -> StatusCode {