added hot posts datasource, added respective route, added view_count updating

This commit is contained in:
2024-09-26 23:53:39 -04:00
parent b427311742
commit c303e6aaee
2 changed files with 19 additions and 3 deletions

View File

@ -34,6 +34,7 @@ impl PostsRoute {
.route("/all", get(PostsRoute::get_all))
.route("/:id", get(PostsRoute::get_one))
.route("/popular", get(PostsRoute::get_popular_posts))
.route("/hot", get(PostsRoute::get_hot_posts))
.with_state(app_state.db.clone())
}
@ -65,7 +66,12 @@ impl PostsRoute {
}
// get the top three posts with the highest view count
// async fn get_hot_posts(State(pool): State<PgPool>) {}
async fn get_hot_posts(State(pool): State<Pool<Postgres>>) -> impl IntoResponse {
match PostsDatasource::get_hot(&pool).await {
Ok(posts) => Ok(Json(posts)),
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
}
fn serialize_datetime<S>(