feat: bal and user permission checks
This commit is contained in:
parent
e3f954679a
commit
e078bffc25
13 changed files with 207 additions and 19 deletions
37
src/entities/bal.rs
Normal file
37
src/entities/bal.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, utoipa::ToSchema)]
|
||||
#[sea_orm(table_name = "BAL")]
|
||||
#[schema(title="Book", as=entities::BAL)]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = true)]
|
||||
pub id: u32,
|
||||
pub user_id: u32,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::book_instance::Entity")]
|
||||
BookInstance,
|
||||
}
|
||||
|
||||
impl Related<super::book_instance::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::BookInstance.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Entity {
|
||||
pub async fn get_by_id<C>(db_conn: &C, id: u32) -> Option<Model>
|
||||
where C: ConnectionTrait,
|
||||
{
|
||||
match Self::find_by_id(id).one(db_conn).await {
|
||||
Ok(res) => res,
|
||||
Err(_) => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
Reference in a new issue