resource.rs
47 lignes · 1438 octets
use chrono::{DateTime, Utc}; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; use uuid::Uuid; /// Generic resource registry. /// /// Tracks any application-defined resource (document, project, invoice...) /// so the framework can manage ownership and sharing without knowing /// the concrete resource type. #[derive(Clone, Debug, Serialize, Deserialize, DeriveEntityModel)] #[sea_orm(table_name = "resources")] pub struct Model { /// Primary key. #[sea_orm(primary_key)] pub id: Uuid, /// Application-defined type key (e.g. "document", "project") pub resource_type: String, /// ID of the concrete entity in the application table pub resource_id: Uuid, /// User who created / owns the resource pub owner_id: Uuid, /// Whether the resource is publicly visible to all authenticated users pub is_public: bool, /// Timestamp when this resource was registered. pub created_at: DateTime<Utc>, } /// SeaORM relations for the Resource entity. #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { /// The user who owns this resource. #[sea_orm( belongs_to = "super::user::Entity", from = "Column::OwnerId", to = "super::user::Column::Id" )] Owner, } impl Related<super::user::Entity> for Entity { fn to() -> RelationDef { Relation::Owner.def() } } impl ActiveModelBehavior for ActiveModel {}
GitRust