sfr-server 0.1.1

The server implementation for a Slack App.
Documentation
//! The trait representing the interface that returns home page.

use crate::response::home::GetHomeResponse;
use crate::ResponseError;
use axum::async_trait;

/// The trait representing the interface that returns home page.
#[async_trait]
pub trait HomeHandlerTrait: Send + Sync {
    /// Handles the request to get home page.
    async fn handle_home(&self) -> Result<Vec<u8>, ResponseError>;
}

/// The new type to wrap [`HomeHandlerTrait`].
#[derive(Clone)]
pub(crate) struct HomeHandler<T>(T)
where
    T: HomeHandlerTrait;

impl<T> HomeHandler<T>
where
    T: HomeHandlerTrait,
{
    /// The constructor.
    pub fn new(inner: T) -> Self {
        Self(inner)
    }

    /// Handles the request to get home page.
    pub async fn handle(&self) -> Result<impl axum::response::IntoResponse, ResponseError> {
        tracing::info!("get home: start to process");

        let resp = self.0.handle_home().await?;

        Ok(GetHomeResponse::new(resp))
    }
}