diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/database.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 2 |
3 files changed, 4 insertions, 4 deletions
@@ -14,7 +14,7 @@ Pings the server GET `/create_user/<name>` Creates a new user with name - Return type: JSON -- Returns: <user> +- Returns: <user_id> GET `/get_user/<id>` Gets a user from id diff --git a/src/database.rs b/src/database.rs index 8c26844..af7de68 100644 --- a/src/database.rs +++ b/src/database.rs @@ -165,7 +165,7 @@ impl Database { None } - pub fn create_user(&mut self, name: String) -> Result<(), &'static str> { + pub fn create_user(&mut self, name: String) -> Result<usize, &'static str> { let id = self.get_user_count(); let query = "INSERT INTO users (id, username) VALUES (:id, :name)"; @@ -184,7 +184,7 @@ impl Database { } } - Ok(()) + Ok(id) } pub fn get_user_count(&self) -> usize { diff --git a/src/main.rs b/src/main.rs index a9db22e..3e12e1f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,7 +96,7 @@ fn get_user_by_name(name: String, db: &State<SharedDB>) -> Json<Response<User, & } } #[get("/create_user/<name>")] -fn create_user(name: String, db: &State<SharedDB>) -> Json<Response<(), &'static str>> { +fn create_user(name: String, db: &State<SharedDB>) -> Json<Response<usize, &'static str>> { let mut lock = db.sdb.lock().unwrap(); Json(Response(lock.create_user(name))) |