Adds simple delete api
This commit is contained in:
@@ -9,10 +9,11 @@
|
||||
<h1>Cook Assistant</h1>
|
||||
<!-- Details View -->
|
||||
<section v-if="active_view > -1">
|
||||
<button @click="setActiveView(-1)">X close</button>
|
||||
<button @click="closeActiveView">X close</button>
|
||||
<h4>{{ items[active_view].title }}</h4>
|
||||
<h6>{{ categories[items[active_view].category].name }}</h6>
|
||||
<p><strong>{{ items[active_view].ingredients }}</strong></p>
|
||||
<button @click="deleteRecipe(active_view + 1)">DELETE !</button>
|
||||
</section>
|
||||
<!-- Category List View -->
|
||||
<section v-else>
|
||||
@@ -57,6 +58,16 @@
|
||||
setActiveView: function(id) {
|
||||
this.active_view = id - 1;
|
||||
},
|
||||
closeActiveView: function() {
|
||||
this.active_view = -1;
|
||||
},
|
||||
deleteRecipe: function(id) {
|
||||
fetch("/api/delete/" + id)
|
||||
.then((res) => res.json())
|
||||
.then((data) => console.log("Deleted :" + data))
|
||||
.catch((err) => console.error(err));
|
||||
this.closeActiveView();
|
||||
},
|
||||
fetchRecipesList: function() {
|
||||
fetch("/api/list")
|
||||
.then((res) => res.json())
|
||||
|
||||
@@ -55,11 +55,18 @@ mod api {
|
||||
.collect()
|
||||
)
|
||||
}
|
||||
|
||||
#[get("/delete/<id>")]
|
||||
pub fn delete_recipe(conn: CookbookDbConn, id: i32) -> Json<bool> {
|
||||
Json(
|
||||
recipes::delete(&conn, id)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
rocket::ignite()
|
||||
.attach(api::CookbookDbConn::fairing())
|
||||
.mount("/", routes![index])
|
||||
.mount("/api", routes![api::recipes_list]).launch();
|
||||
.mount("/api", routes![api::recipes_list, api::delete_recipe]).launch();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user