15c35c06cdea1711d13d2bf9060bc4610e4b22c2 / frogue / src / entities / attachments.rs
Raw
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "attachments")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
#[sea_orm(unique)]
pub uuid: Uuid,
/// The type of owner: "ticket", "comment", or "ap_note"
pub owner_kind: String,
/// The ID of the owner entity (ticket_id, comment_id, or ap_note_id)
pub owner_id: i64,
pub filename: String,
pub content_type: String,
pub size: i64,
/// Remote URL for federated attachments (None for local)
pub remote_url: Option<String>,
pub created_at: DateTimeWithTimeZone,
/// Foreign keys (only one should be set based on owner_kind)
pub ticket_id: Option<i64>,
pub comment_id: Option<i64>,
pub ap_note_id: Option<i64>,
pub ap_remote_note_id: Option<i64>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::tickets::Entity",
from = "Column::TicketId",
to = "super::tickets::Column::Id"
)]
Ticket,
#[sea_orm(
belongs_to = "super::comments::Entity",
from = "Column::CommentId",
to = "super::comments::Column::Id"
)]
Comment,
#[sea_orm(
belongs_to = "super::ap_notes::Entity",
from = "Column::ApNoteId",
to = "super::ap_notes::Column::Id"
)]
ApNote,
#[sea_orm(
belongs_to = "super::ap_remote_notes::Entity",
from = "Column::ApRemoteNoteId",
to = "super::ap_remote_notes::Column::Id"
)]
ApRemoteNote,
}
impl ActiveModelBehavior for ActiveModel {}