use actix_web::HttpResponse;
use serde_json::json;
use sqlx::{Pool, Postgres};
use super::super::catalog_errors::schema_internal_fetch_error;
use super::super::catalog_service_loader::load_schema_table_rows;
use super::super::presentation::schema_tables as build_schema_tables_payload;
pub(in super::super) async fn schema_tables_response(pool: &Pool<Postgres>) -> HttpResponse {
let relations = match load_schema_table_rows(pool).await {
Ok(rows) => rows,
Err(err) => return schema_internal_fetch_error("tables", &err),
};
HttpResponse::Ok().json(json!({ "tables": build_schema_tables_payload(relations) }))
}