dialtone_axum 0.1.0

Dialtone Axum Back-end
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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)))
}