1.1 KiB · text History 263b40b
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "notifications")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: Uuid,
    /// Recipient.
    pub user_id: Uuid,
    /// e.g. "new_topic" (and later "reaction").
    pub kind: String,
    /// Who triggered it (None if that user was deleted).
    pub actor_id: Option<Uuid>,
    pub topic_id: Option<Uuid>,
    pub post_id: Option<Uuid>,
    pub is_read: bool,
    pub created_at: DateTimeWithTimeZone,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(belongs_to = "super::users::Entity", from = "Column::UserId", to = "super::users::Column::Id", on_update = "Cascade", on_delete = "Cascade")]
    Users,
    #[sea_orm(belongs_to = "super::topics::Entity", from = "Column::TopicId", to = "super::topics::Column::Id", on_update = "Cascade", on_delete = "Cascade")]
    Topics,
}

impl ActiveModelBehavior for ActiveModel {}