summaryrefslogtreecommitdiff
path: root/server/src/models
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-08-23 18:19:06 +0200
committerSanto Cariotti <santo@dcariotti.me>2022-08-23 18:19:06 +0200
commitc0c45a3c581405d24c0a3051a3a13d102214556a (patch)
treef3cc608ffd9e063a18bfec70c3bf46a3cf1ffa5f /server/src/models
parenteedc536c23c3230c6ebeac8b495b2cfef0317830 (diff)
Endpoint to get user
Url /v1/users/:id
Diffstat (limited to 'server/src/models')
-rw-r--r--server/src/models/user.rs17
1 files changed, 17 insertions, 0 deletions
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<UserList, AppError> {
+ 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<Vec<UserList>, AppError> {
let pool = unsafe { get_client() };
let rows = sqlx::query_as!(UserList, r#"SELECT id, email, is_staff FROM users"#)