1.4 KiB · text History 7ce364f
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

/// A rich link staff attached to a post ([`crate::link_cards`]).
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "post_links")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub id: Uuid,
    pub post_id: Uuid,
    /// Normalised: http(s), unique per post.
    pub url: String,
    pub position: i32,
    /// `pending`, `ok` or `failed`.
    pub status: String,
    pub title: Option<String>,
    pub description: Option<String>,
    pub site_name: Option<String>,
    /// The card picture, copied in (never hotlinked).
    #[serde(skip)]
    pub image_data: Option<Vec<u8>>,
    pub image_content_type: Option<String>,
    pub fetched_at: Option<DateTimeWithTimeZone>,
    pub created_by_id: Option<Uuid>,
    pub created_at: DateTimeWithTimeZone,
    pub updated_at: DateTimeWithTimeZone,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::posts::Entity",
        from = "Column::PostId",
        to = "super::posts::Column::Id",
        on_update = "Cascade",
        on_delete = "Cascade"
    )]
    Posts,
}

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

impl ActiveModelBehavior for ActiveModel {}