Uses new IngredientListManager :)
This commit is contained in:
@@ -19,7 +19,10 @@
|
||||
<button @click="closeActiveView" class="button is-pulled-right">X close</button>
|
||||
<h4 class="title">{{ items[active_view].title }}</h4>
|
||||
<h6 class="subtitle">{{ categories[items[active_view].category].name }}</h6>
|
||||
<p><strong>{{ items[active_view].ingredients }}</strong></p>
|
||||
<p><strong>Ingredients : </strong></p>
|
||||
<ul>
|
||||
<li v-for="ing in items[active_view].ingredients.split('\n')">{{ ing }}</li>
|
||||
</ul>
|
||||
<button @click="deleteRecipe(items[active_view].id)" class="button is-danger is-pulled-right">DELETE !</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -25,8 +25,9 @@ mod api {
|
||||
#[database("cookbook_db")]
|
||||
pub struct CookbookDbConn(diesel::SqliteConnection);
|
||||
|
||||
/// A serializable wrapper for [`cookbook::recipes::Recipe`]
|
||||
#[derive(Serialize)]
|
||||
pub struct Recipe {
|
||||
pub struct RecipeObject {
|
||||
id: i32,
|
||||
title: String,
|
||||
category: i16,
|
||||
@@ -34,33 +35,34 @@ mod api {
|
||||
preparation: String,
|
||||
}
|
||||
|
||||
impl Recipe {
|
||||
fn from(rec: recipes::Recipe) -> Recipe {
|
||||
Recipe {
|
||||
impl RecipeObject {
|
||||
fn from(conn: &diesel::SqliteConnection, rec: recipes::Recipe) -> Self {
|
||||
Self {
|
||||
id: rec.id,
|
||||
title: rec.title,
|
||||
category: rec.category as i16,
|
||||
ingredients: rec.ingredients.as_string(),
|
||||
ingredients: rec.ingredients
|
||||
.into_manager(conn)
|
||||
.display_lines(),
|
||||
preparation: rec.preparation,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieves data from database and returns all recipes,
|
||||
/// transformed into a js friendly [`RecipeObject`].
|
||||
#[get("/list")]
|
||||
pub fn recipes_list(conn: CookbookDbConn) -> Json<Vec<Recipe>> {
|
||||
Json(
|
||||
recipes::load_all(&conn)
|
||||
.into_iter()
|
||||
.map(|r| Recipe::from(r))
|
||||
.collect()
|
||||
)
|
||||
pub fn recipes_list(conn: CookbookDbConn) -> Json<Vec<RecipeObject>> {
|
||||
Json( recipes::load_all(&conn)
|
||||
.into_iter()
|
||||
.map(|r| RecipeObject::from(&conn, r))
|
||||
.collect() )
|
||||
}
|
||||
|
||||
/// Delete a recipe given it's `id`
|
||||
#[get("/delete/<id>")]
|
||||
pub fn delete_recipe(conn: CookbookDbConn, id: i32) -> Json<bool> {
|
||||
Json(
|
||||
recipes::delete(&conn, id)
|
||||
)
|
||||
Json( recipes::delete(&conn, id) )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user