From 033a21f733f0b868a6599573b85fb89c16176d71 Mon Sep 17 00:00:00 2001 From: Awiteb Date: Wed, 10 Jul 2024 20:16:55 +0300 Subject: [PATCH] chore: Function to return user by its public key Signed-off-by: Awiteb --- crates/oxidetalis/src/database/user.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/oxidetalis/src/database/user.rs b/crates/oxidetalis/src/database/user.rs index 7f52764..3230aa3 100644 --- a/crates/oxidetalis/src/database/user.rs +++ b/crates/oxidetalis/src/database/user.rs @@ -28,6 +28,8 @@ pub trait UserTableExt { async fn users_exists_in_database(&self) -> ApiResult; /// Register new user async fn register_user(&self, public_key: &PublicKey, is_admin: bool) -> ApiResult<()>; + /// Returns user by its public key + async fn get_user_by_pubk(&self, public_key: &PublicKey) -> ApiResult>; } impl UserTableExt for DatabaseConnection { @@ -57,4 +59,13 @@ impl UserTableExt for DatabaseConnection { Ok(()) } + + #[logcall] + async fn get_user_by_pubk(&self, public_key: &PublicKey) -> ApiResult> { + UserEntity::find() + .filter(UserColumn::PublicKey.eq(public_key.to_string())) + .one(self) + .await + .map_err(ApiError::SeaOrm) + } }