X-Git-Url: http://git.euphorik.ch/?p=recipes.git;a=blobdiff_plain;f=backend%2Fsrc%2Fservices.rs;fp=backend%2Fsrc%2Fservices.rs;h=b4d39f9e6ca7f303606c855435f7037148e1b3e9;hp=2d69cc5fafdf31d843c0370697768bb50f3c760c;hb=cbe276fc0601041b13087a6ffd80c5b126dfbe59;hpb=642dd8a80ce2e1212b8e30c1edabb32bdb416cfc diff --git a/backend/src/services.rs b/backend/src/services.rs index 2d69cc5..b4d39f9 100644 --- a/backend/src/services.rs +++ b/backend/src/services.rs @@ -94,6 +94,15 @@ impl From for ServiceError { } } +impl From for ServiceError { + fn from(error: ron::error::SpannedError) -> Self { + ServiceError { + status_code: StatusCode::INTERNAL_SERVER_ERROR, + message: Some(format!("{:?}", error)), + } + } +} + impl std::fmt::Display for ServiceError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> { if let Some(ref m) = self.message { @@ -159,6 +168,32 @@ pub async fn view_recipe(req: HttpRequest, path: web::Path<(i64,)>, connection: }.to_response()) } +///// EDIT RECIPE ///// + +#[derive(Template)] +#[template(path = "edit_recipe.html")] +struct EditRecipeTemplate { + user: Option, + recipes: Vec<(i64, String)>, + current_recipe_id: Option, + current_recipe: model::Recipe, +} + +#[get("/recipe/edit/{id}")] +pub async fn edit_recipe(req: HttpRequest, path: web::Path<(i64,)>, connection: web::Data) -> Result { + let (id,)= path.into_inner(); + let user = get_current_user(&req, connection.clone()).await; + let recipes = connection.get_all_recipe_titles_async().await?; + let recipe = connection.get_recipe_async(id).await?; + + Ok(EditRecipeTemplate { + user, + current_recipe_id: Some(recipe.id), + recipes, + current_recipe: recipe, + }.to_response()) +} + ///// MESSAGE ///// #[derive(Template)]