refactor
This commit is contained in:
@@ -7,7 +7,7 @@ pub mod crud {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Create: Sized {
|
pub trait Create: Sized {
|
||||||
type Id: Sized + Send + Sync + 'static;
|
type Id: Sized + Send + Sync + Copy + 'static;
|
||||||
type Filter: Sized + Send + Sync + 'static;
|
type Filter: Sized + Send + Sync + 'static;
|
||||||
type Info: Sized + Send + Sync + 'static;
|
type Info: Sized + Send + Sync + 'static;
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ pub mod crud {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Read: Sized {
|
pub trait Read: Sized {
|
||||||
type Filter;
|
type Filter;
|
||||||
type Id;
|
type Id: Copy;
|
||||||
|
|
||||||
async fn findall(
|
async fn findall(
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
@@ -40,7 +40,7 @@ pub mod crud {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Update: Sized {
|
pub trait Update: Sized {
|
||||||
type Id;
|
type Id: Copy;
|
||||||
type Filter;
|
type Filter;
|
||||||
type UpdateElement;
|
type UpdateElement;
|
||||||
|
|
||||||
@@ -99,6 +99,20 @@ pub mod crud {
|
|||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait Toggle: Sized {
|
||||||
|
type Id: Sized + Send + Sync + Copy + 'static;
|
||||||
|
type Filter: Sized + Send + Sync + 'static;
|
||||||
|
|
||||||
|
async fn set(
|
||||||
|
ctx: &Context,
|
||||||
|
pool: &sqlite::Pool,
|
||||||
|
filter: Self::Filter,
|
||||||
|
id: Self::Id,
|
||||||
|
value: bool,
|
||||||
|
) -> Result<(), crate::Error>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod view {
|
pub mod view {
|
||||||
@@ -192,8 +206,8 @@ pub mod route {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait ToggleFallback: Send + Sync + Sized + 'static {
|
pub trait ToggleFallback: super::crud::Toggle {
|
||||||
type UrlParams: Clone + Copy + Send + Sync + Sized + 'static;
|
type UrlParams: Send + Sync + 'static;
|
||||||
|
|
||||||
const URL_TRUE: &'static str;
|
const URL_TRUE: &'static str;
|
||||||
const URL_FALSE: &'static str;
|
const URL_FALSE: &'static str;
|
||||||
@@ -212,7 +226,7 @@ pub mod route {
|
|||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
Path(path): Path<Self::UrlParams>,
|
Path(path): Path<Self::UrlParams>,
|
||||||
) -> Result<Response<BoxBody>, crate::Error> {
|
) -> Result<Response<BoxBody>, crate::Error> {
|
||||||
Self::set(user, state, headers, path, true).await
|
<Self as ToggleFallback>::set(user, state, headers, path, true).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn set_false(
|
async fn set_false(
|
||||||
@@ -221,7 +235,7 @@ pub mod route {
|
|||||||
headers: HeaderMap,
|
headers: HeaderMap,
|
||||||
Path(path): Path<Self::UrlParams>,
|
Path(path): Path<Self::UrlParams>,
|
||||||
) -> Result<Response<BoxBody>, crate::Error> {
|
) -> Result<Response<BoxBody>, crate::Error> {
|
||||||
Self::set(user, state, headers, path, false).await
|
<Self as ToggleFallback>::set(user, state, headers, path, false).await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn router<B>() -> axum::Router<AppState, B>
|
fn router<B>() -> axum::Router<AppState, B>
|
||||||
@@ -232,7 +246,9 @@ pub mod route {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait ToggleHtmx {
|
pub trait ToggleHtmx: super::crud::Toggle {
|
||||||
|
type Id: Send + Sync + Copy + 'static + From<Self::UrlParams>;
|
||||||
|
type Filter: Send + Sync + 'static + From<Self::UrlParams>;
|
||||||
type UrlParams: Send + Sync + 'static;
|
type UrlParams: Send + Sync + 'static;
|
||||||
|
|
||||||
const URL_TRUE: &'static str;
|
const URL_TRUE: &'static str;
|
||||||
@@ -243,22 +259,33 @@ pub mod route {
|
|||||||
state: AppState,
|
state: AppState,
|
||||||
params: Self::UrlParams,
|
params: Self::UrlParams,
|
||||||
value: bool,
|
value: bool,
|
||||||
|
) -> Result<(crate::Context, AppState, Self::UrlParams, bool), crate::Error>;
|
||||||
|
|
||||||
|
async fn response(
|
||||||
|
ctx: &crate::Context,
|
||||||
|
state: AppState,
|
||||||
|
params: Self::UrlParams,
|
||||||
|
value: bool,
|
||||||
) -> Result<Response<BoxBody>, crate::Error>;
|
) -> Result<Response<BoxBody>, crate::Error>;
|
||||||
|
|
||||||
async fn set_true(
|
async fn on(
|
||||||
Extension(user): Extension<User>,
|
Extension(user): Extension<User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path(path): Path<Self::UrlParams>,
|
Path(path): Path<Self::UrlParams>,
|
||||||
) -> Result<Response<BoxBody>, crate::Error> {
|
) -> Result<Response<BoxBody>, crate::Error> {
|
||||||
Self::set(user, state, path, true).await
|
let (ctx, state, params, value) =
|
||||||
|
<Self as ToggleHtmx>::set(user, state, path, true).await?;
|
||||||
|
<Self as ToggleHtmx>::response(&ctx, state, params, value).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn set_false(
|
async fn off(
|
||||||
Extension(user): Extension<User>,
|
Extension(user): Extension<User>,
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Path(path): Path<Self::UrlParams>,
|
Path(path): Path<Self::UrlParams>,
|
||||||
) -> Result<Response<BoxBody>, crate::Error> {
|
) -> Result<Response<BoxBody>, crate::Error> {
|
||||||
Self::set(user, state, path, false).await
|
let (ctx, state, params, value) =
|
||||||
|
<Self as ToggleHtmx>::set(user, state, path, false).await?;
|
||||||
|
<Self as ToggleHtmx>::response(&ctx, state, params, value).await
|
||||||
}
|
}
|
||||||
|
|
||||||
fn router<B>() -> axum::Router<AppState, B>
|
fn router<B>() -> axum::Router<AppState, B>
|
||||||
@@ -296,7 +323,7 @@ pub mod route {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait Router: Create + Delete {
|
pub trait Router: Create + Delete {
|
||||||
fn get<B>() -> axum::Router<AppState, B>
|
fn router<B>() -> axum::Router<AppState, B>
|
||||||
where
|
where
|
||||||
B: HttpBody + Send + 'static,
|
B: HttpBody + Send + 'static,
|
||||||
<B as HttpBody>::Data: Send,
|
<B as HttpBody>::Data: Send,
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ use uuid::Uuid;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
components::{
|
components::{
|
||||||
|
self,
|
||||||
crud::{self, Read, Update},
|
crud::{self, Read, Update},
|
||||||
route,
|
route::{self, Toggle},
|
||||||
view::{self, View},
|
view::{self, View},
|
||||||
},
|
},
|
||||||
htmx,
|
htmx,
|
||||||
@@ -86,6 +87,27 @@ pub struct Filter {
|
|||||||
pub trip_id: Uuid,
|
pub trip_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<(Uuid, Uuid)> for Filter {
|
||||||
|
fn from((trip_id, _todo_id): (Uuid, Uuid)) -> Self {
|
||||||
|
Self { trip_id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct Id(pub Uuid);
|
||||||
|
|
||||||
|
impl std::fmt::Display for Id {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<(Uuid, Uuid)> for Id {
|
||||||
|
fn from((_trip_id, todo_id): (Uuid, Uuid)) -> Self {
|
||||||
|
Self(todo_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Todo {
|
impl Todo {
|
||||||
pub fn is_done(&self) -> bool {
|
pub fn is_done(&self) -> bool {
|
||||||
self.state == State::Done
|
self.state == State::Done
|
||||||
@@ -95,7 +117,7 @@ impl Todo {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl crud::Read for Todo {
|
impl crud::Read for Todo {
|
||||||
type Filter = Filter;
|
type Filter = Filter;
|
||||||
type Id = Uuid;
|
type Id = Id;
|
||||||
|
|
||||||
async fn findall(
|
async fn findall(
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
@@ -138,10 +160,10 @@ impl crud::Read for Todo {
|
|||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
pool: &sqlite::Pool,
|
pool: &sqlite::Pool,
|
||||||
filter: Filter,
|
filter: Filter,
|
||||||
todo_id: Uuid,
|
todo_id: Id,
|
||||||
) -> Result<Option<Self>, Error> {
|
) -> Result<Option<Self>, Error> {
|
||||||
let trip_id_param = filter.trip_id.to_string();
|
let trip_id_param = filter.trip_id.to_string();
|
||||||
let todo_id_param = todo_id.to_string();
|
let todo_id_param = todo_id.0.to_string();
|
||||||
let user_id = ctx.user.id.to_string();
|
let user_id = ctx.user.id.to_string();
|
||||||
crate::query_one!(
|
crate::query_one!(
|
||||||
&sqlite::QueryClassification {
|
&sqlite::QueryClassification {
|
||||||
@@ -178,7 +200,7 @@ pub struct TodoNew {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl crud::Create for Todo {
|
impl crud::Create for Todo {
|
||||||
type Id = Uuid;
|
type Id = Id;
|
||||||
type Filter = Filter;
|
type Filter = Filter;
|
||||||
type Info = TodoNew;
|
type Info = TodoNew;
|
||||||
|
|
||||||
@@ -215,7 +237,7 @@ impl crud::Create for Todo {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(id)
|
Ok(components::trips::todos::Id(id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +277,7 @@ pub enum UpdateElement {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl crud::Update for Todo {
|
impl crud::Update for Todo {
|
||||||
type Id = Uuid;
|
type Id = Id;
|
||||||
type Filter = Filter;
|
type Filter = Filter;
|
||||||
type UpdateElement = UpdateElement;
|
type UpdateElement = UpdateElement;
|
||||||
|
|
||||||
@@ -344,15 +366,15 @@ impl crud::Update for Todo {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl crud::Delete for Todo {
|
impl crud::Delete for Todo {
|
||||||
type Id = Uuid;
|
type Id = Id;
|
||||||
type Filter = Filter;
|
type Filter = Filter;
|
||||||
|
|
||||||
#[tracing::instrument]
|
#[tracing::instrument]
|
||||||
async fn delete<'c, T>(ctx: &Context, db: T, filter: &Filter, id: Uuid) -> Result<bool, Error>
|
async fn delete<'c, T>(ctx: &Context, db: T, filter: &Filter, id: Id) -> Result<bool, Error>
|
||||||
where
|
where
|
||||||
T: sqlx::Acquire<'c, Database = sqlx::Sqlite> + Send + std::fmt::Debug,
|
T: sqlx::Acquire<'c, Database = sqlx::Sqlite> + Send + std::fmt::Debug,
|
||||||
{
|
{
|
||||||
let id_param = id.to_string();
|
let id_param = id.0.to_string();
|
||||||
let user_id = ctx.user.id.to_string();
|
let user_id = ctx.user.id.to_string();
|
||||||
let trip_id_param = filter.trip_id.to_string();
|
let trip_id_param = filter.trip_id.to_string();
|
||||||
|
|
||||||
@@ -663,7 +685,7 @@ impl route::Delete for Todo {
|
|||||||
&ctx,
|
&ctx,
|
||||||
&state.database_pool,
|
&state.database_pool,
|
||||||
&Filter { trip_id },
|
&Filter { trip_id },
|
||||||
todo_id,
|
components::trips::todos::Id(todo_id),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -692,7 +714,7 @@ impl route::Delete for Todo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl route::Router for Todo {
|
impl route::Router for Todo {
|
||||||
fn get<B>() -> axum::Router<AppState, B>
|
fn router<B>() -> axum::Router<AppState, B>
|
||||||
where
|
where
|
||||||
B: HttpBody + Send + 'static,
|
B: HttpBody + Send + 'static,
|
||||||
<B as HttpBody>::Data: Send,
|
<B as HttpBody>::Data: Send,
|
||||||
@@ -704,6 +726,7 @@ impl route::Router for Todo {
|
|||||||
"/:id/delete",
|
"/:id/delete",
|
||||||
axum::routing::post(<Self as route::Delete>::delete),
|
axum::routing::post(<Self as route::Delete>::delete),
|
||||||
)
|
)
|
||||||
|
.merge(StateUpdate::router())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -719,7 +742,7 @@ pub async fn trip_todo_done(
|
|||||||
&ctx,
|
&ctx,
|
||||||
&state.database_pool,
|
&state.database_pool,
|
||||||
Filter { trip_id },
|
Filter { trip_id },
|
||||||
todo_id,
|
Id(todo_id),
|
||||||
UpdateElement::State(State::Done.into()),
|
UpdateElement::State(State::Done.into()),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -738,12 +761,12 @@ pub async fn trip_todo_undone_htmx(
|
|||||||
&ctx,
|
&ctx,
|
||||||
&state.database_pool,
|
&state.database_pool,
|
||||||
Filter { trip_id },
|
Filter { trip_id },
|
||||||
todo_id,
|
Id(todo_id),
|
||||||
UpdateElement::State(State::Todo.into()),
|
UpdateElement::State(State::Todo.into()),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let todo_item = Todo::find(&ctx, &state.database_pool, Filter { trip_id }, todo_id)
|
let todo_item = Todo::find(&ctx, &state.database_pool, Filter { trip_id }, Id(todo_id))
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
crate::Error::Request(RequestError::NotFound {
|
crate::Error::Request(RequestError::NotFound {
|
||||||
@@ -769,7 +792,7 @@ pub async fn trip_todo_undone(
|
|||||||
&ctx,
|
&ctx,
|
||||||
&state.database_pool,
|
&state.database_pool,
|
||||||
Filter { trip_id },
|
Filter { trip_id },
|
||||||
todo_id,
|
Id(todo_id),
|
||||||
UpdateElement::State(State::Todo.into()),
|
UpdateElement::State(State::Todo.into()),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -792,7 +815,7 @@ pub async fn trip_todo_edit(
|
|||||||
Path((trip_id, todo_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, todo_id)): Path<(Uuid, Uuid)>,
|
||||||
) -> Result<impl IntoResponse, crate::Error> {
|
) -> Result<impl IntoResponse, crate::Error> {
|
||||||
let ctx = Context::build(current_user);
|
let ctx = Context::build(current_user);
|
||||||
let todo_item = Todo::find(&ctx, &state.database_pool, Filter { trip_id }, todo_id).await?;
|
let todo_item = Todo::find(&ctx, &state.database_pool, Filter { trip_id }, Id(todo_id)).await?;
|
||||||
|
|
||||||
match todo_item {
|
match todo_item {
|
||||||
None => Err(crate::Error::Request(RequestError::NotFound {
|
None => Err(crate::Error::Request(RequestError::NotFound {
|
||||||
@@ -820,7 +843,7 @@ pub async fn trip_todo_edit_save(
|
|||||||
&ctx,
|
&ctx,
|
||||||
&state.database_pool,
|
&state.database_pool,
|
||||||
Filter { trip_id },
|
Filter { trip_id },
|
||||||
todo_id,
|
Id(todo_id),
|
||||||
UpdateElement::Description(form.description.into()),
|
UpdateElement::Description(form.description.into()),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -852,7 +875,7 @@ pub async fn trip_todo_edit_cancel(
|
|||||||
Path((trip_id, todo_id)): Path<(Uuid, Uuid)>,
|
Path((trip_id, todo_id)): Path<(Uuid, Uuid)>,
|
||||||
) -> Result<impl IntoResponse, crate::Error> {
|
) -> Result<impl IntoResponse, crate::Error> {
|
||||||
let ctx = Context::build(current_user);
|
let ctx = Context::build(current_user);
|
||||||
let todo_item = Todo::find(&ctx, &state.database_pool, Filter { trip_id }, todo_id).await?;
|
let todo_item = Todo::find(&ctx, &state.database_pool, Filter { trip_id }, Id(todo_id)).await?;
|
||||||
|
|
||||||
match todo_item {
|
match todo_item {
|
||||||
None => Err(crate::Error::Request(RequestError::NotFound {
|
None => Err(crate::Error::Request(RequestError::NotFound {
|
||||||
@@ -867,6 +890,23 @@ pub async fn trip_todo_edit_cancel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl crud::Toggle for StateUpdate {
|
||||||
|
type Id = Id;
|
||||||
|
type Filter = Filter;
|
||||||
|
|
||||||
|
async fn set(
|
||||||
|
ctx: &Context,
|
||||||
|
pool: &sqlite::Pool,
|
||||||
|
filter: Self::Filter,
|
||||||
|
id: Self::Id,
|
||||||
|
value: bool,
|
||||||
|
) -> Result<(), crate::Error> {
|
||||||
|
Todo::update(&ctx, &pool, filter, id, UpdateElement::State(value.into())).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl route::ToggleFallback for StateUpdate {
|
impl route::ToggleFallback for StateUpdate {
|
||||||
type UrlParams = (Uuid, Uuid);
|
type UrlParams = (Uuid, Uuid);
|
||||||
@@ -882,12 +922,12 @@ impl route::ToggleFallback for StateUpdate {
|
|||||||
value: bool,
|
value: bool,
|
||||||
) -> Result<Response<BoxBody>, crate::Error> {
|
) -> Result<Response<BoxBody>, crate::Error> {
|
||||||
let ctx = Context::build(current_user);
|
let ctx = Context::build(current_user);
|
||||||
Todo::update(
|
<Self as crud::Toggle>::set(
|
||||||
&ctx,
|
&ctx,
|
||||||
&state.database_pool,
|
&state.database_pool,
|
||||||
Filter { trip_id },
|
Filter { trip_id },
|
||||||
todo_id,
|
Id(todo_id),
|
||||||
UpdateElement::State(value.into()),
|
value,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@@ -908,6 +948,8 @@ impl route::ToggleFallback for StateUpdate {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl route::ToggleHtmx for StateUpdate {
|
impl route::ToggleHtmx for StateUpdate {
|
||||||
|
type Id = Id;
|
||||||
|
type Filter = Filter;
|
||||||
type UrlParams = (Uuid, Uuid);
|
type UrlParams = (Uuid, Uuid);
|
||||||
|
|
||||||
const URL_TRUE: &'static str = "/:id/done/htmx/true";
|
const URL_TRUE: &'static str = "/:id/done/htmx/true";
|
||||||
@@ -916,20 +958,29 @@ impl route::ToggleHtmx for StateUpdate {
|
|||||||
async fn set(
|
async fn set(
|
||||||
current_user: User,
|
current_user: User,
|
||||||
state: AppState,
|
state: AppState,
|
||||||
(trip_id, todo_id): (Uuid, Uuid),
|
params: Self::UrlParams,
|
||||||
value: bool,
|
value: bool,
|
||||||
) -> Result<Response<BoxBody>, crate::Error> {
|
) -> Result<(crate::Context, AppState, Self::UrlParams, bool), crate::Error> {
|
||||||
let ctx = Context::build(current_user);
|
let ctx = Context::build(current_user);
|
||||||
Todo::update(
|
<Self as crud::Toggle>::set(
|
||||||
&ctx,
|
&ctx,
|
||||||
&state.database_pool,
|
&state.database_pool,
|
||||||
Filter { trip_id },
|
params.into(),
|
||||||
todo_id,
|
params.into(),
|
||||||
UpdateElement::State(value.into()),
|
value,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let todo_item = Todo::find(&ctx, &state.database_pool, Filter { trip_id }, todo_id)
|
Ok((ctx, state, params, value))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn response(
|
||||||
|
ctx: &Context,
|
||||||
|
state: AppState,
|
||||||
|
(trip_id, todo_id): (Uuid, Uuid),
|
||||||
|
value: bool,
|
||||||
|
) -> Result<Response<BoxBody>, crate::Error> {
|
||||||
|
let todo_item = Todo::find(&ctx, &state.database_pool, Filter { trip_id }, Id(todo_id))
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
crate::Error::Request(RequestError::NotFound {
|
crate::Error::Request(RequestError::NotFound {
|
||||||
@@ -952,8 +1003,8 @@ impl route::ToggleHtmx for StateUpdate {
|
|||||||
<B as HttpBody>::Error: std::error::Error + Sync + Send,
|
<B as HttpBody>::Error: std::error::Error + Sync + Send,
|
||||||
{
|
{
|
||||||
axum::Router::new()
|
axum::Router::new()
|
||||||
.route(Self::URL_TRUE, post(Self::set_true))
|
.route(Self::URL_TRUE, post(Self::on))
|
||||||
.route(Self::URL_FALSE, post(Self::set_false))
|
.route(Self::URL_FALSE, post(Self::off))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ use std::{fmt, time::Duration};
|
|||||||
use tower::{timeout::TimeoutLayer, ServiceBuilder};
|
use tower::{timeout::TimeoutLayer, ServiceBuilder};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
components::{
|
components::{self, route::Router as _},
|
||||||
self,
|
|
||||||
route::{Router as _, Toggle},
|
|
||||||
},
|
|
||||||
AppState, Error, RequestError, TopLevelPage,
|
AppState, Error, RequestError, TopLevelPage,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -168,11 +165,7 @@ pub fn router(state: AppState) -> Router {
|
|||||||
"/:id/todo/:id/edit/cancel",
|
"/:id/todo/:id/edit/cancel",
|
||||||
post(components::trips::todos::trip_todo_edit_cancel),
|
post(components::trips::todos::trip_todo_edit_cancel),
|
||||||
)
|
)
|
||||||
.nest(
|
.nest("/:id/todo/", components::trips::todos::Todo::router()),
|
||||||
"/:id/todo/",
|
|
||||||
components::trips::todos::Todo::get()
|
|
||||||
.merge(<components::trips::todos::StateUpdate as Toggle>::router()),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.nest(
|
.nest(
|
||||||
(&TopLevelPage::Inventory.path()).into(),
|
(&TopLevelPage::Inventory.path()).into(),
|
||||||
|
|||||||
@@ -441,7 +441,7 @@ pub async fn trip(
|
|||||||
&ctx,
|
&ctx,
|
||||||
&state.database_pool,
|
&state.database_pool,
|
||||||
&todos::Filter { trip_id: id },
|
&todos::Filter { trip_id: id },
|
||||||
delete_todo,
|
components::trips::todos::Id(delete_todo),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user