From c0c45a3c581405d24c0a3051a3a13d102214556a Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 23 Aug 2022 18:19:06 +0200 Subject: Endpoint to get user Url /v1/users/:id --- server/src/models/user.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'server/src/models') diff --git a/server/src/models/user.rs b/server/src/models/user.rs index 38ec121..dd96f90 100644 --- a/server/src/models/user.rs +++ b/server/src/models/user.rs @@ -81,6 +81,23 @@ impl User { Ok(rec) } + pub async fn find_by_id(user_id: i32) -> Result { + let pool = unsafe { get_client() }; + + let rec = sqlx::query_as!( + UserList, + r#" + SELECT id, email, is_staff FROM "users" + WHERE id = $1 + "#, + user_id + ) + .fetch_one(pool) + .await?; + + Ok(rec) + } + pub async fn list() -> Result, AppError> { let pool = unsafe { get_client() }; let rows = sqlx::query_as!(UserList, r#"SELECT id, email, is_staff FROM users"#) -- cgit v1.2.3-18-g5258