Isolate routes in their module
This commit is contained in:
parent
4d4fab60cb
commit
e459df69bf
2 changed files with 18 additions and 12 deletions
|
|
@ -3,7 +3,8 @@ use axum::{
|
||||||
extract::{FromRef, FromRequestParts, Path, State},
|
extract::{FromRef, FromRequestParts, Path, State},
|
||||||
http::request::Parts,
|
http::request::Parts,
|
||||||
response::Redirect,
|
response::Redirect,
|
||||||
Form,
|
routing::{get, post},
|
||||||
|
Form, Router,
|
||||||
};
|
};
|
||||||
use maud::{html, Markup};
|
use maud::{html, Markup};
|
||||||
use sea_orm::{prelude::*, ActiveValue, DatabaseTransaction, TransactionTrait};
|
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) struct CurrentHousehold(pub household::Model);
|
||||||
|
|
||||||
|
pub(super) fn routes() -> Router<AppState> {
|
||||||
|
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]
|
#[async_trait]
|
||||||
impl<S> FromRequestParts<S> for CurrentHousehold
|
impl<S> FromRequestParts<S> for CurrentHousehold
|
||||||
where
|
where
|
||||||
|
|
@ -105,7 +115,7 @@ fn new_household_modal() -> Markup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn household_selection(
|
async fn household_selection(
|
||||||
state: State<AppState>,
|
state: State<AppState>,
|
||||||
user: AuthenticatedUser,
|
user: AuthenticatedUser,
|
||||||
) -> Result<Markup, RouteError> {
|
) -> Result<Markup, RouteError> {
|
||||||
|
|
@ -132,11 +142,11 @@ pub(super) async fn household_selection(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub(super) struct HouseholdName {
|
struct HouseholdName {
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn rename(
|
async fn rename(
|
||||||
household: CurrentHousehold,
|
household: CurrentHousehold,
|
||||||
state: State<AppState>,
|
state: State<AppState>,
|
||||||
Form(form): Form<HouseholdName>,
|
Form(form): Form<HouseholdName>,
|
||||||
|
|
@ -150,7 +160,7 @@ pub(super) async fn rename(
|
||||||
Ok(Redirect::to("/"))
|
Ok(Redirect::to("/"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn create_household(
|
async fn create_household(
|
||||||
user: AuthenticatedUser,
|
user: AuthenticatedUser,
|
||||||
state: State<AppState>,
|
state: State<AppState>,
|
||||||
Form(form): Form<HouseholdName>,
|
Form(form): Form<HouseholdName>,
|
||||||
|
|
@ -172,7 +182,7 @@ pub(super) async fn create_household(
|
||||||
Ok(Redirect::to("/household/select"))
|
Ok(Redirect::to("/household/select"))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn select_household(
|
async fn select_household(
|
||||||
user: AuthenticatedUser,
|
user: AuthenticatedUser,
|
||||||
state: State<AppState>,
|
state: State<AppState>,
|
||||||
session: Session,
|
session: Session,
|
||||||
|
|
@ -207,7 +217,7 @@ async fn delete_household(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) async fn leave(
|
async fn leave(
|
||||||
household: CurrentHousehold,
|
household: CurrentHousehold,
|
||||||
user: AuthenticatedUser,
|
user: AuthenticatedUser,
|
||||||
session: Session,
|
session: Session,
|
||||||
|
|
|
||||||
|
|
@ -366,11 +366,7 @@ pub(crate) fn router() -> Router<AppState> {
|
||||||
.route("/", get(index))
|
.route("/", get(index))
|
||||||
.route("/login", get(oidc_login))
|
.route("/login", get(oidc_login))
|
||||||
.route("/logout", get(logout))
|
.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))
|
.route("/login/redirect/:id", get(oidc_login_finish))
|
||||||
|
.nest("/household", household::routes())
|
||||||
.fallback_service(ServeDir::new(public).fallback((|| async { not_found() }).into_service()))
|
.fallback_service(ServeDir::new(public).fallback((|| async { not_found() }).into_service()))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue