use axum::{ extract::{Json, Path, State}, http::StatusCode, response::{self, IntoResponse}, }; use crate::{ clock::RequestedAt, conversation::{self, app, app::Conversations, handlers::PathInfo}, error::{Internal, NotFound}, token::extract::Identity, }; #[cfg(test)] mod test; pub async fn handler( State(conversations): State, Path(conversation): Path, RequestedAt(deleted_at): RequestedAt, _: Identity, ) -> Result { conversations.delete(&conversation, &deleted_at).await?; Ok(Response { id: conversation }) } #[derive(Debug, serde::Serialize)] pub struct Response { pub id: conversation::Id, } impl IntoResponse for Response { fn into_response(self) -> response::Response { (StatusCode::ACCEPTED, Json(self)).into_response() } } #[derive(Debug, thiserror::Error)] #[error(transparent)] pub struct Error(#[from] pub app::DeleteError); impl IntoResponse for Error { fn into_response(self) -> response::Response { let Self(error) = self; match error { app::DeleteError::NotFound(_) | app::DeleteError::Deleted(_) => { NotFound(error).into_response() } app::DeleteError::NotEmpty(_) => { (StatusCode::CONFLICT, error.to_string()).into_response() } app::DeleteError::Name(_) | app::DeleteError::Database(_) => { Internal::from(error).into_response() } } } }