ef0b83a
use sea_orm::entity::Set;
use sea_orm::entity::prelude::*;
use uuid::Uuid;
#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "space_join_requests")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
#[sea_orm(indexed)]
pub organization_id: Uuid,
#[sea_orm(indexed)]
pub user_id: i64,
pub status: super::SpaceJoinRequestState,
#[sea_orm(column_type = "Text")]
pub note: Option<String>,
pub decided_by: Option<i64>,
pub decided_at: Option<DateTimeUtc>,
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub created_at: DateTimeUtc,
#[sea_orm(default_expr = "Expr::current_timestamp()")]
pub updated_at: DateTimeUtc,
#[sea_orm(belongs_to, from = "organization_id", to = "id", on_delete = "Cascade")]
pub organization: BelongsTo<super::spaces::Entity>,
}
#[async_trait::async_trait]
impl ActiveModelBehavior for ActiveModel {
async fn before_save<C>(mut self, _db: &C, insert: bool) -> Result<Self, DbErr>
where
C: ConnectionTrait,
{
if insert && self.id.is_not_set() {
self.id = Set(Uuid::now_v7());
}
self.updated_at = Set(chrono::Utc::now());
Ok(self)
}
}