Recipe edit (WIP): add API to set some recipe values
This commit is contained in:
parent
c6dfff065c
commit
dd05a673d9
20 changed files with 690 additions and 2189 deletions
|
|
@ -35,18 +35,23 @@ pub async fn edit_recipe(
|
|||
if let Some(user) = user {
|
||||
let recipe = connection.get_recipe(recipe_id).await?.unwrap();
|
||||
if recipe.user_id == user.id {
|
||||
let recipes = Recipes {
|
||||
published: connection.get_all_published_recipe_titles().await?,
|
||||
unpublished: connection
|
||||
.get_all_unpublished_recipe_titles(user.id)
|
||||
.await?,
|
||||
current_id: Some(recipe_id),
|
||||
};
|
||||
|
||||
Ok(RecipeEditTemplate {
|
||||
user: Some(user),
|
||||
recipes: Recipes {
|
||||
list: connection.get_all_recipe_titles().await?,
|
||||
current_id: Some(recipe_id),
|
||||
},
|
||||
recipes,
|
||||
recipe,
|
||||
languages: consts::LANGUAGES,
|
||||
}
|
||||
.into_response())
|
||||
} else {
|
||||
Ok(MessageTemplate::new("Unable to edit this recipe").into_response())
|
||||
Ok(MessageTemplate::new("Not allowed to edit this recipe").into_response())
|
||||
}
|
||||
} else {
|
||||
Ok(MessageTemplate::new("Not logged in").into_response())
|
||||
|
|
@ -59,17 +64,37 @@ pub async fn view(
|
|||
Extension(user): Extension<Option<model::User>>,
|
||||
Path(recipe_id): Path<i64>,
|
||||
) -> Result<Response> {
|
||||
let recipes = connection.get_all_recipe_titles().await?;
|
||||
match connection.get_recipe(recipe_id).await? {
|
||||
Some(recipe) => Ok(RecipeViewTemplate {
|
||||
user,
|
||||
recipes: Recipes {
|
||||
list: recipes,
|
||||
current_id: Some(recipe.id),
|
||||
},
|
||||
recipe,
|
||||
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),
|
||||
user,
|
||||
)
|
||||
.into_response());
|
||||
}
|
||||
|
||||
let recipes = Recipes {
|
||||
published: connection.get_all_published_recipe_titles().await?,
|
||||
unpublished: if let Some(user) = user.as_ref() {
|
||||
connection
|
||||
.get_all_unpublished_recipe_titles(user.id)
|
||||
.await?
|
||||
} else {
|
||||
vec![]
|
||||
},
|
||||
current_id: Some(recipe_id),
|
||||
};
|
||||
|
||||
Ok(RecipeViewTemplate {
|
||||
user,
|
||||
recipes,
|
||||
recipe,
|
||||
}
|
||||
.into_response())
|
||||
}
|
||||
.into_response()),
|
||||
None => Ok(MessageTemplate::new_with_user(
|
||||
&format!("Cannot find the recipe {}", recipe_id),
|
||||
user,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue