030e59e
zhenyi
refactor(lib): migrate storage and security tier to central lib/config (auth, cache, db, email, jwt, payment, queue, rate_limit, storage)
030e59e
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<OffsetDateTime>) -> Option<String> {
ts.map(fmt_ts)
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct CommentView {
pub id: Uuid,
pub issue_id: Option<Uuid>,
pub parent_id: Option<Uuid>,
pub poster_id: Uuid,
pub content: String,
pub created_at: String,
pub updated_at: Option<String>,
}
impl From<comment_entity::Model> 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<CommentView>,
pub total: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct CreateCommentOption {
pub content: String,
pub parent_id: Option<Uuid>,
}
#[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<Uuid>,
pub limit: Option<u64>,
pub offset: Option<u64>,
}