diff --git a/src/app/household.rs b/src/app/household.rs index 95ae65a..c44fbaf 100644 --- a/src/app/household.rs +++ b/src/app/household.rs @@ -3,7 +3,8 @@ use axum::{ extract::{FromRef, FromRequestParts, Path, State}, http::request::Parts, response::Redirect, - Form, + routing::{get, post}, + Form, Router, }; use maud::{html, Markup}; use sea_orm::{prelude::*, ActiveValue, DatabaseTransaction, TransactionTrait}; @@ -17,6 +18,15 @@ use super::{base_page_with_head, AppState, AuthenticatedUser, RedirectOrError, R pub(super) struct CurrentHousehold(pub household::Model); +pub(super) fn routes() -> Router { + Router::new() + .route("/select", get(household_selection)) + .route("/select/:id", get(select_household)) + .route("/create", post(create_household)) + .route("/leave", post(leave)) + .route("/rename", post(rename)) +} + #[async_trait] impl FromRequestParts for CurrentHousehold where @@ -105,7 +115,7 @@ fn new_household_modal() -> Markup { } } -pub(super) async fn household_selection( +async fn household_selection( state: State, user: AuthenticatedUser, ) -> Result { @@ -132,11 +142,11 @@ pub(super) async fn household_selection( } #[derive(Serialize, Deserialize, Debug)] -pub(super) struct HouseholdName { +struct HouseholdName { name: String, } -pub(super) async fn rename( +async fn rename( household: CurrentHousehold, state: State, Form(form): Form, @@ -150,7 +160,7 @@ pub(super) async fn rename( Ok(Redirect::to("/")) } -pub(super) async fn create_household( +async fn create_household( user: AuthenticatedUser, state: State, Form(form): Form, @@ -172,7 +182,7 @@ pub(super) async fn create_household( Ok(Redirect::to("/household/select")) } -pub(super) async fn select_household( +async fn select_household( user: AuthenticatedUser, state: State, session: Session, @@ -207,7 +217,7 @@ async fn delete_household( Ok(()) } -pub(super) async fn leave( +async fn leave( household: CurrentHousehold, user: AuthenticatedUser, session: Session, diff --git a/src/app/mod.rs b/src/app/mod.rs index 7f96a0c..2f7ec4f 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -366,11 +366,7 @@ pub(crate) fn router() -> Router { .route("/", get(index)) .route("/login", get(oidc_login)) .route("/logout", get(logout)) - .route("/household/select", get(household::household_selection)) - .route("/household/select/:id", get(household::select_household)) - .route("/household/create", post(household::create_household)) - .route("/household/leave", post(household::leave)) - .route("/household/rename", post(household::rename)) .route("/login/redirect/:id", get(oidc_login_finish)) + .nest("/household", household::routes()) .fallback_service(ServeDir::new(public).fallback((|| async { not_found() }).into_service())) }