use crate::response::home::GetHomeResponse;
use crate::ResponseError;
pub trait HomeHandlerTrait: Send + Sync {
fn handle_home(
&self,
) -> impl std::future::Future<Output = Result<Vec<u8>, ResponseError>> + Send;
}
#[derive(Clone)]
pub(crate) struct HomeHandler<T>(T)
where
T: HomeHandlerTrait;
impl<T> HomeHandler<T>
where
T: HomeHandlerTrait,
{
pub fn new(inner: T) -> Self {
Self(inner)
}
pub fn handle<'a>(
&'a self,
) -> impl std::future::Future<Output = Result<impl axum::response::IntoResponse, ResponseError>>
+ Send
+ 'a {
tracing::info!("get home: start to process");
async move {
let resp = self.0.handle_home().await?;
Ok(GetHomeResponse::new(resp))
}
}
}