feat(model): Post 新增 deleted_at 字段并用 try_get 兼容现有查询

This commit is contained in:
xfy 2026-06-16 12:29:37 +08:00
parent 959cc1fb0e
commit 054d7450f7
3 changed files with 7 additions and 0 deletions

View File

@ -50,6 +50,7 @@ pub(super) async fn row_to_post_list(
published_at: row.get("published_at"),
created_at: row.get("created_at"),
updated_at: row.get("updated_at"),
deleted_at: row.try_get("deleted_at").ok(),
tags,
cover_image: row.get("cover_image"),
reading_time: (word_count / 200).max(1),
@ -143,6 +144,7 @@ pub(super) async fn row_to_post_full(
published_at: row.get("published_at"),
created_at: row.get("created_at"),
updated_at: row.get("updated_at"),
deleted_at: row.try_get("deleted_at").ok(),
tags,
cover_image: row.get("cover_image"),
reading_time: (word_count / 200).max(1),

View File

@ -473,6 +473,7 @@ mod tests {
published_at: None,
created_at: chrono::Utc::now(),
updated_at: chrono::Utc::now(),
deleted_at: None,
tags: vec![],
cover_image: None,
reading_time: 1,
@ -520,6 +521,7 @@ mod tests {
published_at: None,
created_at: chrono::Utc::now(),
updated_at: chrono::Utc::now(),
deleted_at: None,
tags: vec![],
cover_image: None,
reading_time: 1,

View File

@ -61,6 +61,8 @@ pub struct Post {
pub created_at: DateTime<Utc>,
/// 最后更新时间。
pub updated_at: DateTime<Utc>,
/// 软删除时间None 表示未删除。仅回收站查询填充。
pub deleted_at: Option<DateTime<Utc>>,
/// 关联标签列表。
pub tags: Vec<String>,
/// 封面图片 URL。
@ -161,6 +163,7 @@ mod tests {
published_at: None,
created_at: Utc.with_ymd_and_hms(2024, 1, 15, 10, 0, 0).unwrap(),
updated_at: Utc.with_ymd_and_hms(2024, 1, 15, 10, 0, 0).unwrap(),
deleted_at: None,
tags: vec![],
cover_image: None,
reading_time: 1,