Portfolio/entity/src/admin_session.rs
2023-01-15 16:20:46 +01:00

47 lines
1.1 KiB
Rust

//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
use sea_orm::entity::prelude::*;
use crate::session_trait::UserSession;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "admin_session")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub admin_id: i32,
pub ip_address: String,
pub created_at: DateTime,
pub expires_at: DateTime,
pub updated_at: DateTime,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::admin::Entity",
from = "Column::AdminId",
to = "super::admin::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Admin,
}
impl Related<super::admin::Entity> for Entity {
fn to() -> RelationDef {
Relation::Admin.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
#[async_trait::async_trait]
impl UserSession for Model {
async fn id(&self) -> Uuid {
self.id
}
async fn expires_at(&self) -> chrono::NaiveDateTime {
self.expires_at
}
}