use crate::err_not_found;
use crate::response::response_error::ResponseError;
use axum::extract::{Extension, Path};
use axum::response::IntoResponse;
use axum::Json;
use dialtone_sqlx::db::site_info::fetch_site;
use sqlx::{Pool, Postgres};
pub async fn get_site_handler(
Path(host_name): Path<String>,
Extension(pool): Extension<Pool<Postgres>>,
) -> Result<impl IntoResponse, ResponseError> {
let site_info = fetch_site(&pool, &host_name).await?;
site_info.map_or_else(|| err_not_found!(), |v| Ok(Json(v.site_data.public)))
}