updated axum

This commit is contained in:
2025-07-02 00:16:48 -04:00
parent 0a12cfcd57
commit 7ada37f005
7 changed files with 97 additions and 52 deletions

View File

@ -121,20 +121,11 @@ async fn main() {
// build our application with some routes
let app = Router::new()
.nest("/", routes::root::RootRoute::routes())
.nest("/posts", routes::posts::PostsRoute::routes(&app_state))
.nest(
"/comments",
routes::comments::CommentsRoute::routes(&app_state),
)
.nest(
"/authors",
routes::authors::AuthorsRoute::routes(&app_state),
)
.nest(
"/projects",
routes::projects::ProjectsRoute::routes(&app_state),
)
.merge(routes::root::RootRoute::routes())
.merge(routes::posts::PostsRoute::routes(&app_state))
.merge(routes::comments::CommentsRoute::routes(&app_state))
.merge(routes::authors::AuthorsRoute::routes(&app_state))
.merge(routes::projects::ProjectsRoute::routes(&app_state))
.layer(CorsLayer::permissive())
.layer(
TraceLayer::new_for_http()

View File

@ -30,9 +30,9 @@ pub struct AuthorsRoute;
impl AuthorsRoute {
pub fn routes(app_state: &AppState) -> axum::Router {
axum::Router::new()
.route("/", get(AuthorsRoute::get_all))
.route("/:id", get(AuthorsRoute::get_one))
.route("/:id/posts", get(AuthorsRoute::get_authors_posts))
.route("/authors", get(AuthorsRoute::get_all))
.route("/authors/{id}", get(AuthorsRoute::get_one))
.route("/authors/{id}/posts", get(AuthorsRoute::get_authors_posts))
.with_state(app_state.clone())
}

View File

@ -43,9 +43,9 @@ impl CommentsRoute {
pub fn routes(app_state: &AppState) -> axum::Router {
// add more comment routes here!
axum::Router::new()
.route("/post/:id", get(CommentsRoute::get_post_comments))
.route("/add", post(CommentsRoute::insert_comment))
.route("/index", get(CommentsRoute::get_comments_index))
.route("/comments/post/{id}", get(CommentsRoute::get_post_comments))
.route("/comments/add", post(CommentsRoute::insert_comment))
.route("/comments/index", get(CommentsRoute::get_comments_index))
.with_state(app_state.clone())
}

View File

@ -57,14 +57,14 @@ impl PostsRoute {
pub fn routes(app_state: &AppState) -> Router {
// add more post routes here!
Router::new()
.route("/all", get(PostsRoute::get_all))
.route("/:id", get(PostsRoute::get_one))
.route("/recent", get(PostsRoute::get_recent_posts))
.route("/popular", get(PostsRoute::get_popular_posts))
.route("/hot", get(PostsRoute::get_hot_posts))
.route("/featured", get(PostsRoute::get_featured_posts))
.route("/rss", get(PostsRoute::get_rss_posts))
.route("/sitemap", get(PostsRoute::get_sitemap))
.route("/posts/all", get(PostsRoute::get_all))
.route("/posts/{id}", get(PostsRoute::get_one))
.route("/posts/recent", get(PostsRoute::get_recent_posts))
.route("/posts/popular", get(PostsRoute::get_popular_posts))
.route("/posts/hot", get(PostsRoute::get_hot_posts))
.route("/posts/featured", get(PostsRoute::get_featured_posts))
.route("/posts/rss", get(PostsRoute::get_rss_posts))
.route("/posts/sitemap", get(PostsRoute::get_sitemap))
.with_state(app_state.clone())
}

View File

@ -21,7 +21,7 @@ pub struct ProjectsRoute;
impl ProjectsRoute {
pub fn routes(app_state: &AppState) -> Router {
Router::new()
.route("/", get(ProjectsRoute::get_all))
.route("/projects", get(ProjectsRoute::get_all))
.with_state(app_state.clone())
}