51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
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="Bal", as=entities::BAL)]
|
|
pub struct Model {
|
|
#[sea_orm(primary_key, auto_increment = true)]
|
|
pub id: u32,
|
|
pub user_id: u32,
|
|
pub name: String,
|
|
pub state: BalState,
|
|
pub start_timestamp: i64,
|
|
pub end_timestamp: i64
|
|
}
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize, utoipa::ToSchema)]
|
|
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(1))")]
|
|
pub enum BalState {
|
|
#[sea_orm(string_value = "P")]
|
|
Pending,
|
|
#[sea_orm(string_value = "O")]
|
|
Ongoing,
|
|
#[sea_orm(string_value = "E")]
|
|
Ended
|
|
}
|
|
|
|
#[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 {}
|