use std::sync::Arc; use topcoat::{ Result, context::{Cx, app_context}, router::{ error::{RouterErrorExt, SeeOther, bad_request, see_other}, module_param, path_param, route, }, }; use crate::hub::Hub; use crate::store::Store; module_param!(note_id); /// POST /trash/{note_id}/delete: deletes a trashed note for good. A note that is not in /// the trash cannot be deleted from here. #[route(POST "./delete")] async fn delete_forever(cx: &Cx) -> Result { let store = app_context::>(cx); let hub = app_context::>(cx); let id = path_param::(cx).to_owned(); let meta = store .get_note(&id) .await .map_err(topcoat::Error::from_anyhow)? .ok_or_not_found()?; if meta.trashed_at.is_none() { return Err(bad_request("the note is not in the trash").into()); } store.delete_note(&id).await.map_err(topcoat::Error::from_anyhow)?; hub.forget(&id); Ok(see_other("/trash")) }