1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
pub mod delete {
use axum::{
extract::{Path, State},
http::StatusCode,
response::{IntoResponse, Response},
};
use crate::{
app::App,
clock::RequestedAt,
error::{Internal, NotFound},
login::Login,
message::{self, app::DeleteError},
};
pub async fn handler(
State(app): State<App>,
Path(message): Path<message::Id>,
RequestedAt(deleted_at): RequestedAt,
_: Login,
) -> Result<StatusCode, Error> {
app.messages().delete(&message, &deleted_at).await?;
Ok(StatusCode::ACCEPTED)
}
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct Error(#[from] pub DeleteError);
impl IntoResponse for Error {
fn into_response(self) -> Response {
let Self(error) = self;
#[allow(clippy::match_wildcard_for_single_variants)]
match error {
DeleteError::ChannelNotFound(_)
| DeleteError::NotFound(_)
| DeleteError::Deleted(_) => NotFound(error).into_response(),
other => Internal::from(other).into_response(),
}
}
}
}
|