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, pub notification_type: NotificationType, pub title: String, pub body: Option, #[sea_orm(column_name = "data")] pub data_json: Option, pub actor_uid: Option, #[sea_orm(belongs_to, relation_enum = "Actor", from = "actor_uid", to = "uid")] pub actor: BelongsTo>, pub read_at: Option, pub created_at: OffsetDateTime, } impl ActiveModelBehavior for ActiveModel {} impl Related for Entity { fn to() -> RelationDef { Relation::Users.def() } }