Skip to content

Commit 93b1056

Browse files
committed
feat: add get_by_id to UserRepository
1 parent 654941b commit 93b1056

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/repository/user.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
use tracing::debug;
1616

17-
use crate::{database::Database, model::JsonWebKey, repository::Result};
17+
use crate::{
18+
database::Database,
19+
model::{JsonWebKey, UserModel},
20+
repository::Result,
21+
};
1822

1923
/// Repository for managing user-related operations in the database.
2024
pub struct UserRepository;
@@ -27,4 +31,14 @@ impl UserRepository {
2731
sqlx::query_as::<_, JsonWebKey>("SELECT * FROM jwks").fetch_all(db.pool()).await?;
2832
Ok(keys)
2933
}
34+
35+
/// Fetch a user by their ID.
36+
pub async fn get_by_id(db: &Database, id: &str) -> Result<UserModel> {
37+
let row = sqlx::query_as::<_, UserModel>(r#"SELECT * FROM users WHERE id = $1"#)
38+
.bind(id)
39+
.fetch_one(db.pool())
40+
.await?;
41+
42+
Ok(row)
43+
}
3044
}

0 commit comments

Comments
 (0)