Skip to content

Commit

Permalink
Revamp nest (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
kigawas authored Aug 1, 2024
1 parent d516231 commit 035d501
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"codegen",
"dotenv",
"dotenvy",
"Iden",
"nonblocking",
"oneshot",
"openapi",
Expand Down
38 changes: 19 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions api/src/routers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use user::create_user_router;

pub fn create_router(state: AppState) -> Router {
Router::new()
.nest("/users", create_user_router(state.clone()))
.nest("/", create_root_router(state))
.nest("/users", create_user_router())
.nest("/", create_root_router())
.with_state(state)
}
6 changes: 3 additions & 3 deletions api/src/routers/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::error::ApiError;
(status = 200, description = "Hello world", body = String)
)
)]
async fn root(state: State<AppState>) -> Result<String, ApiError> {
async fn root_get(state: State<AppState>) -> Result<String, ApiError> {
let result = state
.conn
.query_one(Statement::from_string(
Expand All @@ -25,6 +25,6 @@ async fn root(state: State<AppState>) -> Result<String, ApiError> {
result.unwrap().try_get_by(0).map_err(|e| e.into())
}

pub fn create_root_router(state: AppState) -> Router {
Router::new().route("/", get(root)).with_state(state)
pub fn create_root_router() -> Router<AppState> {
Router::new().route("/", get(root_get))
}
3 changes: 1 addition & 2 deletions api/src/routers/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ async fn users_id_get(
.ok_or_else(|| UserError::NotFound.into())
}

pub fn create_user_router(state: AppState) -> Router {
pub fn create_user_router() -> Router<AppState> {
Router::new()
.route("/", post(users_post).get(users_get))
.route("/:id", get(users_id_get))
.with_state(state)
}
2 changes: 1 addition & 1 deletion doc/src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use utoipa::OpenApi;
use api::routers::root::*;

#[derive(OpenApi)]
#[openapi(paths(root))]
#[openapi(paths(root_get))]
pub(super) struct RootApi;

0 comments on commit 035d501

Please sign in to comment.