Translation (WIP)
This commit is contained in:
parent
9b0fcec5e2
commit
e9873c1943
29 changed files with 586 additions and 285 deletions
|
|
@ -9,20 +9,20 @@ use crate::{
|
|||
consts,
|
||||
data::{db, model},
|
||||
html_templates::*,
|
||||
translation,
|
||||
};
|
||||
|
||||
///// RECIPE /////
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn create(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(tr): Extension<translation::Tr>,
|
||||
) -> Result<Response> {
|
||||
if let Some(user) = user {
|
||||
let recipe_id = connection.create_recipe(user.id).await?;
|
||||
Ok(Redirect::to(&format!("/recipe/edit/{}", recipe_id)).into_response())
|
||||
} else {
|
||||
Ok(MessageTemplate::new("Not logged in").into_response())
|
||||
Ok(MessageTemplate::new("Not logged in", tr).into_response())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -30,10 +30,11 @@ pub async fn create(
|
|||
pub async fn edit_recipe(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(tr): Extension<translation::Tr>,
|
||||
Path(recipe_id): Path<i64>,
|
||||
) -> Result<Response> {
|
||||
if let Some(user) = user {
|
||||
if let Some(recipe) = connection.get_recipe(recipe_id).await? {
|
||||
if let Some(recipe) = connection.get_recipe(recipe_id, false).await? {
|
||||
if recipe.user_id == user.id {
|
||||
let recipes = Recipes {
|
||||
published: connection.get_all_published_recipe_titles().await?,
|
||||
|
|
@ -45,19 +46,20 @@ pub async fn edit_recipe(
|
|||
|
||||
Ok(RecipeEditTemplate {
|
||||
user: Some(user),
|
||||
tr,
|
||||
recipes,
|
||||
recipe,
|
||||
languages: *consts::LANGUAGES,
|
||||
}
|
||||
.into_response())
|
||||
} else {
|
||||
Ok(MessageTemplate::new("Not allowed to edit this recipe").into_response())
|
||||
Ok(MessageTemplate::new("Not allowed to edit this recipe", tr).into_response())
|
||||
}
|
||||
} else {
|
||||
Ok(MessageTemplate::new("Recipe not found").into_response())
|
||||
Ok(MessageTemplate::new("Recipe not found", tr).into_response())
|
||||
}
|
||||
} else {
|
||||
Ok(MessageTemplate::new("Not logged in").into_response())
|
||||
Ok(MessageTemplate::new("Not logged in", tr).into_response())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,15 +67,17 @@ pub async fn edit_recipe(
|
|||
pub async fn view(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
Extension(tr): Extension<translation::Tr>,
|
||||
Path(recipe_id): Path<i64>,
|
||||
) -> Result<Response> {
|
||||
match connection.get_recipe(recipe_id).await? {
|
||||
match connection.get_recipe(recipe_id, true).await? {
|
||||
Some(recipe) => {
|
||||
if !recipe.is_published
|
||||
&& (user.is_none() || recipe.user_id != user.as_ref().unwrap().id)
|
||||
{
|
||||
return Ok(MessageTemplate::new_with_user(
|
||||
&format!("Not allowed the view the recipe {}", recipe_id),
|
||||
tr,
|
||||
user,
|
||||
)
|
||||
.into_response());
|
||||
|
|
@ -93,6 +97,7 @@ pub async fn view(
|
|||
|
||||
Ok(RecipeViewTemplate {
|
||||
user,
|
||||
tr,
|
||||
recipes,
|
||||
recipe,
|
||||
}
|
||||
|
|
@ -100,6 +105,7 @@ pub async fn view(
|
|||
}
|
||||
None => Ok(MessageTemplate::new_with_user(
|
||||
&format!("Cannot find the recipe {}", recipe_id),
|
||||
tr,
|
||||
user,
|
||||
)
|
||||
.into_response()),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue