feat(backend/api/get/post_list) add first_update field

This commit is contained in:
lumither committed 2024-05-04 14:02:54 +08:00
1 parent 7e3687c4c9
commit 4e71a1ccf0
1 file changed
+7 -4
+7 -4
View File
@@ -8,10 +8,11 @@ use uuid::Uuid;
pub async fn get_post_list( pub async fn get_post_list(
State(db_connection): State<PgPool>, State(db_connection): State<PgPool>,
) -> Result<Json<Value>, Json<Value>> { ) -> Result<Json<Value>, Json<Value>> {
let post_list = sqlx::query("select post_id, title, summary, last_update from post") let post_list =
.fetch_all(&db_connection) sqlx::query("select post_id, title, summary, last_update, first_update from post")
.await .fetch_all(&db_connection)
.unwrap(); .await
.unwrap();
let mut res = Map::new(); let mut res = Map::new();
let posts: Vec<Value> = post_list let posts: Vec<Value> = post_list
@@ -22,11 +23,13 @@ pub async fn get_post_list(
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");
let first_update: NaiveDateTime = post.get("first_update");
tmp.insert("post_id".to_string(), json!(post_id.to_string())); 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));
tmp.insert("first_update".to_string(), json!(first_update));
Value::from(tmp) Value::from(tmp)
}) })