This repository has been archived on 2025-08-25. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Alexandria/src/entities/bal.rs
Ninjdai c667608fbb
All checks were successful
/ test (push) Successful in 16m18s
feat: bal state
2025-08-11 11:15:27 +02:00

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 {}