use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum PostStatus { Draft, Published, } impl PostStatus { #[allow(dead_code)] pub fn as_str(&self) -> &'static str { match self { PostStatus::Draft => "draft", PostStatus::Published => "published", } } #[allow(dead_code)] pub fn from_str(s: &str) -> Option { match s { "draft" => Some(PostStatus::Draft), "published" => Some(PostStatus::Published), _ => None, } } } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Post { pub id: i32, pub author_id: i32, pub title: String, pub slug: String, pub summary: Option, pub content_md: String, pub content_html: Option, pub status: PostStatus, pub published_at: Option>, pub created_at: DateTime, pub updated_at: DateTime, pub tags: Vec, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Tag { pub id: i32, pub name: String, pub post_count: i64, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PostStats { pub total: i64, pub drafts: i64, pub published: i64, }