Skip to content
Clone
d5939db
60 lines 1.6 KB Rust
use sea_orm::entity::prelude::*;
use time::OffsetDateTime;
use uuid::Uuid;
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
EnumIter,
DeriveActiveEnum,
serde::Serialize,
serde::Deserialize,
)]
#[serde(rename_all = "snake_case")]
#[sea_orm(rs_type = "String", db_type = "String(StringLen::N(16))")]
pub enum NotificationType {
#[sea_orm(string_value = "mention")]
Mention,
#[sea_orm(string_value = "reply")]
Reply,
#[sea_orm(string_value = "follow")]
Follow,
#[sea_orm(string_value = "invite")]
Invite,
#[sea_orm(string_value = "assignment")]
Assignment,
#[sea_orm(string_value = "system")]
System,
}
#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "user_notifications")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub user_id: Uuid,
#[sea_orm(belongs_to, from = "user_id", to = "uid")]
pub user: BelongsTo<crate::user::users::Entity>,
pub notification_type: NotificationType,
pub title: String,
pub body: Option<String>,
#[sea_orm(column_name = "data")]
pub data_json: Option<String>,
pub actor_uid: Option<Uuid>,
#[sea_orm(belongs_to, relation_enum = "Actor", from = "actor_uid", to = "uid")]
pub actor: BelongsTo<Option<crate::user::users::Entity>>,
pub read_at: Option<OffsetDateTime>,
pub created_at: OffsetDateTime,
}
impl ActiveModelBehavior for ActiveModel {}
impl Related<crate::user::users::Entity> for Entity {
fn to() -> RelationDef {
Relation::Users.def()
}
}