diff --git a/src/database/access_context.rs b/src/database/access_context.rs index 2345861..12a48d4 100644 --- a/src/database/access_context.rs +++ b/src/database/access_context.rs @@ -3,16 +3,39 @@ use crate::database::entity_context::EntityContextTrait; use crate::entities::access; use sea_orm::prelude::async_trait::async_trait; use sea_orm::ActiveValue::{Set, Unchanged}; -use sea_orm::{ActiveModelTrait, DbErr, EntityTrait}; +use sea_orm::{ActiveModelTrait, ColumnTrait, Condition, DbErr, EntityTrait, QueryFilter}; use std::sync::Arc; pub struct AccessContext { db_context: Arc, } -pub trait AccessContextTrait: EntityContextTrait {} +#[async_trait] +pub trait AccessContextTrait: EntityContextTrait { + async fn get_access_by_uid_and_model_id( + &self, + uid: i32, + model_id: i32, + ) -> Result, DbErr>; +} -impl AccessContextTrait for AccessContext {} +#[async_trait] +impl AccessContextTrait for AccessContext { + async fn get_access_by_uid_and_model_id( + &self, + uid: i32, + model_id: i32, + ) -> Result, DbErr> { + access::Entity::find() + .filter( + Condition::all() + .add(access::Column::UserId.eq(uid)) + .add(access::Column::ModelId.eq(model_id)), + ) + .one(&self.db_context.get_connection()) + .await + } +} impl AccessContext { pub fn new(db_context: Arc) -> AccessContext {