forge
Explore
Log in

Don't you dare go Hollow

project_note

Clone
★ 0

0 watching0 forksRust3.6 MiBc49f5e7Tahinli1 month ago2 commits

note_id.rs35 lines, 1009 bytesHistoryRawDownload
1use std::sync::Arc;
2
3use topcoat::{
4 Result,
5 context::{Cx, app_context},
6 router::{
7 error::{RouterErrorExt, SeeOther, bad_request, see_other},
8 module_param, path_param, route,
9 },
10};
11
12use crate::hub::Hub;
13use crate::store::Store;
14
15module_param!(note_id);
16
17/// POST /trash/{note_id}/delete: deletes a trashed note for good. A note that is not in
18/// the trash cannot be deleted from here.
19#[route(POST "./delete")]
20async fn delete_forever(cx: &Cx) -> Result<SeeOther> {
21 let store = app_context::<Arc<Store>>(cx);
22 let hub = app_context::<Arc<Hub>>(cx);
23 let id = path_param::<NoteId>(cx).to_owned();
24 let meta = store
25 .get_note(&id)
26 .await
27 .map_err(topcoat::Error::from_anyhow)?
28 .ok_or_not_found()?;
29 if meta.trashed_at.is_none() {
30 return Err(bad_request("the note is not in the trash").into());
31 }
32 store.delete_note(&id).await.map_err(topcoat::Error::from_anyhow)?;
33 hub.forget(&id);
34 Ok(see_other("/trash"))
35}