feat(api) update /api/get/post_list

This commit is contained in:
lumither committed 2024-05-04 00:35:47 +08:00
1 parent 5d82152932
commit b17e8a19eb
1 file changed
+8 -3
+8 -3
View File
@@ -14,19 +14,24 @@ pub async fn get_post_list(
.unwrap(); .unwrap();
let mut res = Map::new(); let mut res = Map::new();
for post in post_list { let posts: Vec<Value> = post_list
.into_iter()
.map(|post| {
let mut tmp = Map::new(); let mut tmp = Map::new();
let post_id: Uuid = post.get("post_id"); let post_id: Uuid = post.get("post_id");
let title: String = post.get("title"); let title: String = post.get("title");
let summary: String = post.get("summary"); let summary: String = post.get("summary");
let last_update: NaiveDateTime = post.get("last_update"); let last_update: NaiveDateTime = post.get("last_update");
tmp.insert("post_id".to_string(), json!(post_id.to_string()));
tmp.insert("title".to_string(), json!(title)); tmp.insert("title".to_string(), json!(title));
tmp.insert("summary".to_string(), json!(summary)); tmp.insert("summary".to_string(), json!(summary));
tmp.insert("last_update".to_string(), json!(last_update)); tmp.insert("last_update".to_string(), json!(last_update));
res.insert(post_id.to_string(), Value::from(tmp)); Value::from(tmp)
} })
.collect();
res.insert("posts".to_string(), Value::from(posts));
Ok(Json::from(Value::from(res))) Ok(Json::from(Value::from(res)))
} }