Skip to content
Clone
a06673b
46 lines 1.4 KB Rust
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use uuid::Uuid;
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Default, EnumIter, DeriveActiveEnum, Serialize, Deserialize,
)]
#[sea_orm(rs_type = "i32", db_type = "SmallInteger")]
pub enum PostStatus {
#[default]
Open = 0,
Closed = 1,
Archived = 2,
Locked = 3,
}
#[sea_orm::model]
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "post")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
#[sea_orm(unique_key = "collection_number")]
pub collection_id: Uuid,
#[sea_orm(unique_key = "collection_number")]
pub autoincrement_id: i32,
pub author_id: Uuid,
pub title: String,
pub body: String,
pub status: PostStatus,
pub is_pinned: bool,
pub reply_count: i32,
pub last_reply_at: Option<OffsetDateTime>,
pub last_reply_by: Option<Uuid>,
pub created_at: OffsetDateTime,
pub updated_at: Option<OffsetDateTime>,
pub closed_at: Option<OffsetDateTime>,
pub archived_at: Option<OffsetDateTime>,
#[sea_orm(belongs_to, from = "collection_id", to = "id")]
pub collection: BelongsTo<super::posts::Entity>,
#[sea_orm(belongs_to, from = "author_id", to = "uid")]
pub author: BelongsTo<super::super::user::users::Entity>,
}
impl ActiveModelBehavior for ActiveModel {}