use axum::{ extract::{Json, Path, State}, response::{IntoResponse, Response}, }; use crate::{ error::{Internal, NotFound}, invite::{Id, Summary, app::Invites, handlers::PathInfo}, }; #[cfg(test)] mod test; pub async fn handler( State(invites): State, Path(invite): Path, ) -> Result, Error> { invites .get(&invite) .await? .map(Json) .ok_or_else(move || Error::NotFound(invite)) } #[derive(Debug, thiserror::Error)] pub enum Error { #[error("invite not found: {0}")] NotFound(Id), #[error(transparent)] Database(#[from] sqlx::Error), } impl IntoResponse for Error { fn into_response(self) -> Response { match self { Self::NotFound(_) => NotFound(self).into_response(), Self::Database(_) => Internal::from(self).into_response(), } } }