Beginning of frontend + recipe editing
(it's a mess)
This commit is contained in:
parent
642dd8a80c
commit
cbe276fc06
16 changed files with 203 additions and 63 deletions
|
|
@ -94,6 +94,15 @@ impl From<actix_web::error::BlockingError> for ServiceError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<ron::error::SpannedError> 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<User>,
|
||||
recipes: Vec<(i64, String)>,
|
||||
current_recipe_id: Option<i64>,
|
||||
current_recipe: model::Recipe,
|
||||
}
|
||||
|
||||
#[get("/recipe/edit/{id}")]
|
||||
pub async fn edit_recipe(req: HttpRequest, path: web::Path<(i64,)>, connection: web::Data<db::Connection>) -> Result<HttpResponse> {
|
||||
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)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue