added nested routes, added separate config struct, among other items
This commit is contained in:
@ -1,2 +1,32 @@
|
||||
use crate::{datasources::posts::PostsDatasource, AppState};
|
||||
use axum::{extract::State, routing::get, Json, Router};
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub struct PostsRoute;
|
||||
impl PostsRoute {}
|
||||
impl PostsRoute {
|
||||
pub fn routes(app_state: &AppState) -> Router {
|
||||
// add more post routes here!
|
||||
Router::new()
|
||||
.route("/", get(PostsRoute::get_all))
|
||||
.route("/:id", get(PostsRoute::get_one))
|
||||
.with_state(app_state.db)
|
||||
}
|
||||
|
||||
// get all posts
|
||||
async fn get_all(State(pool): State<PgPool>) -> Json<()> {
|
||||
let results = PostsDatasource::get_all(pool).await;
|
||||
Json {}
|
||||
}
|
||||
|
||||
// get one post
|
||||
async fn get_one(State(pool): State<PgPool>) -> Json<()> {
|
||||
let results = PostsDatasource::get_one(pool).await;
|
||||
Json {}
|
||||
}
|
||||
|
||||
// get the top three posts with the highest view count
|
||||
async fn get_popular_posts(State(pool): State<PgPool>) -> Json<()> {}
|
||||
|
||||
// get the top three posts with the most comments
|
||||
async fn get_hot_posts(State(pool): State<PgPool>) -> Json<()> {}
|
||||
}
|
||||
|
Reference in New Issue
Block a user