use axum::{
routing::{delete, get, head, post},
Router,
};
use super::namespace::{
create_namespace, delete_namespace, get_namespace, list_namespaces, namespace_exists,
update_namespace_properties,
};
use super::search::search;
use super::table::{
commit_table, commit_transaction, create_table, drop_table, list_tables, load_table,
load_table_credentials, register_table, rename_table, report_metrics, table_exists,
};
use super::view::{
commit_view, create_view, drop_view, list_views, load_view, rename_view, view_exists,
};
use crate::app::AppState;
pub fn create_routes(app_state: AppState) -> Router {
Router::new()
.route("/search", get(search))
.route("/namespaces", get(list_namespaces))
.route("/namespaces", post(create_namespace))
.route("/namespaces/{namespace}", get(get_namespace))
.route("/namespaces/{namespace}", head(namespace_exists))
.route("/namespaces/{namespace}", delete(delete_namespace))
.route(
"/namespaces/{namespace}/properties",
post(update_namespace_properties),
)
.route("/namespaces/{namespace}/tables", get(list_tables))
.route("/namespaces/{namespace}/tables", post(create_table))
.route("/namespaces/{namespace}/register", post(register_table))
.route(
"/namespaces/{namespace}/tables/{table}",
get(load_table).post(commit_table),
)
.route("/namespaces/{namespace}/tables/{table}", head(table_exists))
.route("/namespaces/{namespace}/tables/{table}", delete(drop_table))
.route(
"/namespaces/{namespace}/tables/{table}/credentials",
get(load_table_credentials),
)
.route(
"/namespaces/{namespace}/tables/{table}/metrics",
post(report_metrics),
)
.route("/tables/rename", post(rename_table))
.route("/namespaces/{namespace}/views", get(list_views))
.route("/namespaces/{namespace}/views", post(create_view))
.route(
"/namespaces/{namespace}/views/{view}",
get(load_view).post(commit_view),
)
.route("/namespaces/{namespace}/views/{view}", head(view_exists))
.route("/namespaces/{namespace}/views/{view}", delete(drop_view))
.route("/views/rename", post(rename_view))
.route("/transactions/commit", post(commit_transaction))
.with_state(app_state)
}