diff options
Diffstat (limited to 'src/ui/handlers/invite.rs')
| -rw-r--r-- | src/ui/handlers/invite.rs | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/src/ui/handlers/invite.rs b/src/ui/handlers/invite.rs index edd6dc1..e552318 100644 --- a/src/ui/handlers/invite.rs +++ b/src/ui/handlers/invite.rs @@ -2,12 +2,15 @@ use axum::{ extract::{Path, State}, response::{self, IntoResponse}, }; +use axum_extra::TypedHeader; +use headers::IfNoneMatch; use crate::{ error::Internal, invite, invite::app::Invites, ui::{ + assets, assets::{Asset, Assets}, error::NotFound, }, @@ -16,38 +19,27 @@ use crate::{ pub async fn handler( State(invites): State<Invites>, Path(invite): Path<invite::Id>, -) -> Result<Asset, Error> { - invites - .get(&invite) - .await - .map_err(Error::internal)? - .ok_or(Error::NotFound)?; - - Assets::index().map_err(Error::Internal) -} - -#[derive(Debug, thiserror::Error)] -pub enum Error { - #[error("invite not found")] - NotFound, - #[error("{0}")] - Internal(Internal), + TypedHeader(if_none_match): TypedHeader<IfNoneMatch>, +) -> Result<Response, Internal> { + if invites.get(&invite).await?.is_some() { + let index = assets::Response::index(&if_none_match)?; + Ok(Response::Found(index)) + } else { + let index = Assets::index()?; + Ok(Response::NotFound(index)) + } } -impl Error { - fn internal(err: impl Into<Internal>) -> Self { - Self::Internal(err.into()) - } +pub enum Response { + Found(assets::Response), + NotFound(Asset), } -impl IntoResponse for Error { +impl IntoResponse for Response { fn into_response(self) -> response::Response { match self { - Self::NotFound => match Assets::index() { - Ok(asset) => NotFound(asset).into_response(), - Err(internal) => internal.into_response(), - }, - Self::Internal(error) => error.into_response(), + Self::Found(asset) => asset.into_response(), + Self::NotFound(asset) => NotFound(asset).into_response(), } } } |
