added hot posts datasource, added respective route, added view_count updating
This commit is contained in:
@ -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>(
|
||||
|
Reference in New Issue
Block a user