Update to Axum 0.8
This commit is contained in:
parent
975d1ceee2
commit
e355800f98
20 changed files with 1377 additions and 1199 deletions
|
|
@ -1,14 +1,16 @@
|
|||
use axum::{
|
||||
debug_handler,
|
||||
extract::{Extension, Path, State},
|
||||
response::{IntoResponse, Redirect, Response, Result},
|
||||
response::{Html, IntoResponse, Redirect, Response},
|
||||
};
|
||||
use rinja::Template;
|
||||
// use tracing::{event, Level};
|
||||
|
||||
use crate::{
|
||||
data::{db, model},
|
||||
html_templates::*,
|
||||
translation::{self, Sentence},
|
||||
Result,
|
||||
};
|
||||
|
||||
#[debug_handler]
|
||||
|
|
@ -21,7 +23,7 @@ pub async fn create(
|
|||
let recipe_id = connection.create_recipe(user.id).await?;
|
||||
Ok(Redirect::to(&format!("/recipe/edit/{}", recipe_id)).into_response())
|
||||
} else {
|
||||
Ok(MessageTemplate::new(tr.t(Sentence::NotLoggedIn), tr).into_response())
|
||||
Ok(Html(MessageTemplate::new(tr.t(Sentence::NotLoggedIn), tr).render()?).into_response())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,24 +47,33 @@ pub async fn edit_recipe(
|
|||
current_id: Some(recipe_id),
|
||||
};
|
||||
|
||||
Ok(RecipeEditTemplate {
|
||||
user: Some(user),
|
||||
tr,
|
||||
recipes,
|
||||
recipe,
|
||||
}
|
||||
Ok(Html(
|
||||
RecipeEditTemplate {
|
||||
user: Some(user),
|
||||
tr,
|
||||
recipes,
|
||||
recipe,
|
||||
}
|
||||
.render()?,
|
||||
)
|
||||
.into_response())
|
||||
} else {
|
||||
Ok(
|
||||
MessageTemplate::new(tr.t(Sentence::RecipeNotAllowedToEdit), tr)
|
||||
.into_response(),
|
||||
Html(
|
||||
MessageTemplate::new(tr.t(Sentence::RecipeNotAllowedToEdit), tr)
|
||||
.render()?,
|
||||
)
|
||||
.into_response(),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Ok(MessageTemplate::new(tr.t(Sentence::RecipeNotFound), tr).into_response())
|
||||
Ok(
|
||||
Html(MessageTemplate::new(tr.t(Sentence::RecipeNotFound), tr).render()?)
|
||||
.into_response(),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Ok(MessageTemplate::new(tr.t(Sentence::NotLoggedIn), tr).into_response())
|
||||
Ok(Html(MessageTemplate::new(tr.t(Sentence::NotLoggedIn), tr).render()?).into_response())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -78,10 +89,13 @@ pub async fn view(
|
|||
if !recipe.is_published
|
||||
&& (user.is_none() || recipe.user_id != user.as_ref().unwrap().id)
|
||||
{
|
||||
return Ok(MessageTemplate::new_with_user(
|
||||
&tr.tp(Sentence::RecipeNotAllowedToView, &[Box::new(recipe_id)]),
|
||||
tr,
|
||||
user,
|
||||
return Ok(Html(
|
||||
MessageTemplate::new_with_user(
|
||||
&tr.tp(Sentence::RecipeNotAllowedToView, &[Box::new(recipe_id)]),
|
||||
tr,
|
||||
user,
|
||||
)
|
||||
.render()?,
|
||||
)
|
||||
.into_response());
|
||||
}
|
||||
|
|
@ -103,17 +117,20 @@ pub async fn view(
|
|||
current_id: Some(recipe_id),
|
||||
};
|
||||
|
||||
Ok(RecipeViewTemplate {
|
||||
user,
|
||||
tr,
|
||||
recipes,
|
||||
recipe,
|
||||
}
|
||||
Ok(Html(
|
||||
RecipeViewTemplate {
|
||||
user,
|
||||
tr,
|
||||
recipes,
|
||||
recipe,
|
||||
}
|
||||
.render()?,
|
||||
)
|
||||
.into_response())
|
||||
}
|
||||
None => Ok(
|
||||
MessageTemplate::new_with_user(tr.t(Sentence::RecipeNotFound), tr, user)
|
||||
.into_response(),
|
||||
),
|
||||
None => Ok(Html(
|
||||
MessageTemplate::new_with_user(tr.t(Sentence::RecipeNotFound), tr, user).render()?,
|
||||
)
|
||||
.into_response()),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue