Expose deletion in frontend
This commit is contained in:
parent
a07af2f2a9
commit
7100c29dd3
|
@ -21,7 +21,8 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
.service(add_item)
|
.service(add_item)
|
||||||
.service(add_item_post)
|
.service(add_item_post)
|
||||||
.service(edit_item)
|
.service(edit_item)
|
||||||
.service(edit_item_post);
|
.service(edit_item_post)
|
||||||
|
.service(delete_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/item/{id}")]
|
#[get("/item/{id}")]
|
||||||
|
@ -72,6 +73,12 @@ async fn show_item(
|
||||||
name: "Edit".to_string(),
|
name: "Edit".to_string(),
|
||||||
colour: Colour::Warning,
|
colour: Colour::Warning,
|
||||||
}),
|
}),
|
||||||
|
(PageAction {
|
||||||
|
method: PageActionMethod::Post,
|
||||||
|
target: format!("/item/{}/delete", item.id),
|
||||||
|
name: "Delete".to_string(),
|
||||||
|
colour: Colour::Danger,
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
user: Some(user),
|
user: Some(user),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -355,3 +362,18 @@ async fn edit_item_post(
|
||||||
|
|
||||||
Ok(web::Redirect::to("/item/".to_owned() + &item.id.to_string()).see_other())
|
Ok(web::Redirect::to("/item/".to_owned() + &item.id.to_string()).see_other())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[post("/item/{id}/delete")]
|
||||||
|
async fn delete_item(
|
||||||
|
pool: web::Data<PgPool>,
|
||||||
|
path: web::Path<Uuid>,
|
||||||
|
_user: Identity,
|
||||||
|
) -> actix_web::Result<impl Responder> {
|
||||||
|
let id = path.into_inner();
|
||||||
|
|
||||||
|
manage::item::delete(&pool, id)
|
||||||
|
.await
|
||||||
|
.map_err(error::ErrorInternalServerError)?;
|
||||||
|
|
||||||
|
Ok(web::Redirect::to("/items").see_other())
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,8 @@ pub fn config(cfg: &mut web::ServiceConfig) {
|
||||||
.service(add_item_class)
|
.service(add_item_class)
|
||||||
.service(add_item_class_post)
|
.service(add_item_class_post)
|
||||||
.service(edit_item_class)
|
.service(edit_item_class)
|
||||||
.service(edit_item_class_post);
|
.service(edit_item_class_post)
|
||||||
|
.service(delete_item_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/item-class/{id}")]
|
#[get("/item-class/{id}")]
|
||||||
|
@ -72,6 +73,12 @@ async fn show_item_class(
|
||||||
name: "Edit".to_string(),
|
name: "Edit".to_string(),
|
||||||
colour: Colour::Warning,
|
colour: Colour::Warning,
|
||||||
});
|
});
|
||||||
|
page_actions.push(PageAction {
|
||||||
|
method: PageActionMethod::Post,
|
||||||
|
target: format!("/item-class/{}/delete", item_class.id),
|
||||||
|
name: "Delete".to_string(),
|
||||||
|
colour: Colour::Danger,
|
||||||
|
});
|
||||||
|
|
||||||
Ok(templates::base(
|
Ok(templates::base(
|
||||||
TemplateConfig {
|
TemplateConfig {
|
||||||
|
@ -309,3 +316,18 @@ async fn edit_item_class_post(
|
||||||
|
|
||||||
Ok(web::Redirect::to("/item-class/".to_owned() + &item_class.id.to_string()).see_other())
|
Ok(web::Redirect::to("/item-class/".to_owned() + &item_class.id.to_string()).see_other())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[post("/item-class/{id}/delete")]
|
||||||
|
async fn delete_item_class(
|
||||||
|
pool: web::Data<PgPool>,
|
||||||
|
path: web::Path<Uuid>,
|
||||||
|
_user: Identity,
|
||||||
|
) -> actix_web::Result<impl Responder> {
|
||||||
|
let id = path.into_inner();
|
||||||
|
|
||||||
|
manage::item_class::delete(&pool, id)
|
||||||
|
.await
|
||||||
|
.map_err(error::ErrorInternalServerError)?;
|
||||||
|
|
||||||
|
Ok(web::Redirect::to("/item-classes").see_other())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue