X-Git-Url: http://git.euphorik.ch/?p=recipes.git;a=blobdiff_plain;f=backend%2Fsrc%2Fservices%2Fapi.rs;fp=backend%2Fsrc%2Fservices%2Fapi.rs;h=fa126c59dfb11153129d67ef143265217b3156d2;hp=aa160fce16a83ad930eb3a1fe12d4262280ab789;hb=cbe276fc0601041b13087a6ffd80c5b126dfbe59;hpb=642dd8a80ce2e1212b8e30c1edabb32bdb416cfc diff --git a/backend/src/services/api.rs b/backend/src/services/api.rs index aa160fc..fa126c5 100644 --- a/backend/src/services/api.rs +++ b/backend/src/services/api.rs @@ -1,6 +1,8 @@ -use actix_web::{http::{header, header::ContentType, StatusCode}, get, post, put, web, Responder, HttpRequest, HttpResponse, cookie::Cookie}; +use actix_web::{http::{header, header::ContentType, StatusCode}, get, post, put, web, Responder, HttpRequest, HttpResponse, cookie::Cookie, HttpMessage}; use chrono::Duration; +use futures::TryFutureExt; use serde::Deserialize; +use ron::de::from_bytes; use log::{debug, error, log_enabled, info, Level}; use super::Result; @@ -11,17 +13,16 @@ use crate::user::User; use crate::model; use crate::data::{db, asynchronous}; -#[put("/ron-api/set-title")] -pub async fn set_title(req: HttpRequest, connection: web::Data) -> Result { - //req.app_config() - let id = 1; - let title = "XYZ".to_string(); +#[put("/ron-api/recipe/set-title")] +pub async fn set_recipe_title(req: HttpRequest, body: web::Bytes, connection: web::Data) -> Result { + let ron_req: common::ron_api::SetRecipeTitle = from_bytes(&body)?; + connection.set_recipe_title_async(ron_req.recipe_id, &ron_req.title).await?; + Ok(HttpResponse::Ok().finish()) +} - //let recipes = connection.set_recipe_title_async(id, title).await?; - - Ok( - HttpResponse::Ok() - .content_type("application/ron") - .body("DATA") - ) +#[put("/ron-api/recipe/set-description")] +pub async fn set_recipe_description(req: HttpRequest, body: web::Bytes, connection: web::Data) -> Result { + let ron_req: common::ron_api::SetRecipeDescription = from_bytes(&body)?; + connection.set_recipe_description_async(ron_req.recipe_id, &ron_req.description).await?; + Ok(HttpResponse::Ok().finish()) } \ No newline at end of file