2.2 KiB · text History 3d71adc
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "posts")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: Uuid,
    pub topic_id: Uuid,
    pub user_id: Uuid,
    /// 1-based sequence within the topic (the topic's opening post is 1).
    pub post_number: i32,
    /// Raw markdown as authored.
    #[sea_orm(column_type = "Text")]
    pub raw: String,
    /// Rendered + sanitized HTML, cached at write time.
    #[sea_orm(column_type = "Text")]
    pub cooked: String,
    pub created_at: DateTimeWithTimeZone,
    pub updated_at: DateTimeWithTimeZone,
    /// When the post was last edited (None = never edited).
    pub edited_at: Option<DateTimeWithTimeZone>,
    /// Number of edits since creation (0 = original only).
    pub edit_count: i32,
    pub last_editor_id: Option<Uuid>,
    /// Soft-delete tombstone — set instead of removing the row so post numbers
    /// and `#post-N` references stay stable.
    pub deleted_at: Option<DateTimeWithTimeZone>,
    pub deleted_by_id: Option<Uuid>,
    /// Staff replaced the body with a moderation note (`raw`/`cooked` are
    /// the note); the author can no longer edit it.
    pub moderated_at: Option<DateTimeWithTimeZone>,
    pub moderated_by_id: Option<Uuid>,
    /// Hidden pending staff review: flags reached the threshold.
    pub hidden_at: Option<DateTimeWithTimeZone>,
}

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

impl Related<super::topics::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::Topics.def()
    }
}

impl Related<super::users::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::Users.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}