use db::issue::comment as comment_entity; use serde::{Deserialize, Serialize}; use time::OffsetDateTime; use time::format_description::well_known::Rfc3339; use utoipa::{IntoParams, ToSchema}; use uuid::Uuid; fn fmt_ts(ts: OffsetDateTime) -> String { ts.format(&Rfc3339).unwrap_or_default() } fn fmt_ts_opt(ts: Option) -> Option { ts.map(fmt_ts) } #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct CommentView { pub id: Uuid, pub issue_id: Option, pub parent_id: Option, pub poster_id: Uuid, pub content: String, pub created_at: String, pub updated_at: Option, } impl From for CommentView { fn from(m: comment_entity::Model) -> Self { Self { id: m.id, issue_id: m.issue_id, parent_id: m.parent_id, poster_id: m.poster_id, content: m.content, created_at: fmt_ts(m.created_at), updated_at: fmt_ts_opt(m.updated_at), } } } #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct CommentPage { pub items: Vec, pub total: i64, } #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct CreateCommentOption { pub content: String, pub parent_id: Option, } #[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] pub struct UpdateCommentOption { pub content: String, } #[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)] pub struct ListCommentQuery { pub parent_id: Option, pub limit: Option, pub offset: Option, }