From e0471ad1ad8db253d3431be20b34a7a49adaee8c Mon Sep 17 00:00:00 2001 From: Aditya-06 Date: Thu, 14 Mar 2024 17:09:31 -0400 Subject: [PATCH] chore/format all files --- src/config/mod.rs | 2 +- src/handlers/mod.rs | 2 +- src/handlers/namespace_handler.rs | 15 +++++----- src/handlers/table_handler.rs | 23 ++++++++------ src/main.rs | 4 +-- src/routes/mod.rs | 2 +- src/routes/namespace.rs | 27 +++++++++++++---- src/routes/root.rs | 5 ++-- src/routes/table.rs | 50 +++++++++++++++++++++++-------- src/tests/mod.rs | 1 + 10 files changed, 88 insertions(+), 43 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 78d6859..24e32ea 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1 +1 @@ -pub mod parameters; \ No newline at end of file +pub mod parameters; diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index ee0c763..d291cb8 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -1,2 +1,2 @@ pub mod namespace_handler; -pub mod table_handler; \ No newline at end of file +pub mod table_handler; diff --git a/src/handlers/namespace_handler.rs b/src/handlers/namespace_handler.rs index 127dabd..1e5e1b3 100644 --- a/src/handlers/namespace_handler.rs +++ b/src/handlers/namespace_handler.rs @@ -4,17 +4,16 @@ use axum::{ response::IntoResponse, }; - - #[derive(Debug, serde::Serialize, serde::Deserialize)] -pub struct Namespace { - -} - +pub struct Namespace {} pub async fn list_namespaces() -> Json> { // Logic to list namespaces - let namespaces: Vec = vec!["accounting".to_string(), "tax".to_string(), "paid".to_string()]; + let namespaces: Vec = vec![ + "accounting".to_string(), + "tax".to_string(), + "paid".to_string(), + ]; Json(namespaces) } @@ -69,6 +68,6 @@ pub async fn set_namespace_properties(Path(namespace): Path) -> Json) -> Json> { // Dummy response for demonstration - let tables: Vec = vec!["accounting".to_string(), "tax".to_string(), "paid".to_string()]; + let tables: Vec = vec![ + "accounting".to_string(), + "tax".to_string(), + "paid".to_string(), + ]; Json(tables) - } pub async fn create_table(Path(namespace): Path) -> impl IntoResponse { @@ -34,13 +36,11 @@ pub async fn delete_table(Path((namespace, table)): Path<(String, String)>) -> i pub async fn table_exists(Path((namespace, table)): Path<(String, String)>) -> impl IntoResponse { // Logic to check if a table exists within a given namespace - StatusCode::OK + StatusCode::OK } #[derive(Debug, serde::Serialize, serde::Deserialize)] -pub struct MetricsReport { - -} +pub struct MetricsReport {} // Handler functions pub async fn rename_table(table_rename: String) -> impl IntoResponse { @@ -53,7 +53,12 @@ pub async fn report_metrics(Path((namespace, table)): Path<(String, String)>) -> Json(table) } -pub async fn find_tuple_location(Path((namespace, table, tuple_id)): Path<(String, String, String)>) -> impl IntoResponse { +pub async fn find_tuple_location( + Path((namespace, table, tuple_id)): Path<(String, String, String)>, +) -> impl IntoResponse { // Logic to return the physical file location for a given tuple ID - format!("Physical file location for tuple ID {} of table {} in namespace {}.", tuple_id, table, namespace) + format!( + "Physical file location for tuple ID {} of table {} in namespace {}.", + tuple_id, table, namespace + ) } diff --git a/src/main.rs b/src/main.rs index 11b2b1c..10a4616 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ -mod routes; +mod config; mod dto; mod handlers; -mod config; +mod routes; mod tests; use crate::config::parameters; diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 136fb5a..5b0dfd6 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -1,3 +1,3 @@ pub mod namespace; +pub mod root; pub mod table; -pub mod root; \ No newline at end of file diff --git a/src/routes/namespace.rs b/src/routes/namespace.rs index 34e2e46..4ffb281 100644 --- a/src/routes/namespace.rs +++ b/src/routes/namespace.rs @@ -1,13 +1,28 @@ -use axum::{ routing::{get, post, head, delete}, Router}; use crate::handlers::namespace_handler; +use axum::{ + routing::{delete, get, head, post}, + Router, +}; -pub fn routes() -> Router<> { +pub fn routes() -> Router { let router = Router::new() .route("/namespaces", get(namespace_handler::list_namespaces)) .route("/namespaces", post(namespace_handler::create_namespace)) - .route("/namespace/:namespace", get(namespace_handler::load_namespace_metadata)) - .route("/namespace/:namespace", head(namespace_handler::namespace_exists)) - .route("/namespace/:namespace", delete(namespace_handler::drop_namespace)) - .route("/namespace/:namespace/properties", post(namespace_handler::set_namespace_properties)); + .route( + "/namespace/:namespace", + get(namespace_handler::load_namespace_metadata), + ) + .route( + "/namespace/:namespace", + head(namespace_handler::namespace_exists), + ) + .route( + "/namespace/:namespace", + delete(namespace_handler::drop_namespace), + ) + .route( + "/namespace/:namespace/properties", + post(namespace_handler::set_namespace_properties), + ); return router; } diff --git a/src/routes/root.rs b/src/routes/root.rs index 34e10c1..9ebd46c 100644 --- a/src/routes/root.rs +++ b/src/routes/root.rs @@ -4,11 +4,10 @@ use axum::Router; use tower_http::trace::TraceLayer; pub fn routes() -> Router { - // merge the 2 routes let app_router = Router::new() - .nest("/", table::routes()) - .nest("/", namespace::routes()); + .nest("/", table::routes()) + .nest("/", namespace::routes()); app_router } diff --git a/src/routes/table.rs b/src/routes/table.rs index a3ba5ef..586a18e 100644 --- a/src/routes/table.rs +++ b/src/routes/table.rs @@ -1,18 +1,44 @@ -use axum::{ routing::{get, post, head, delete}, Router}; use crate::handlers::table_handler; +use axum::{ + routing::{delete, get, head, post}, + Router, +}; - -pub fn routes() -> Router<> { +pub fn routes() -> Router { let router = Router::new() - .route("/namespaces/:namespace/tables", get(table_handler::list_tables)) - .route("/namespaces/:namespace/tables", post(table_handler::create_table)) - .route("/namespaces/:namespace/register", post(table_handler::register_table)) - .route("/namespaces/:namespace/tables/:table", get(table_handler::load_table)) - .route("/namespaces/:namespace/tables/:table", delete(table_handler::delete_table)) - .route("/namespaces/:namespace/tables/:table", head(table_handler::table_exists)) + .route( + "/namespaces/:namespace/tables", + get(table_handler::list_tables), + ) + .route( + "/namespaces/:namespace/tables", + post(table_handler::create_table), + ) + .route( + "/namespaces/:namespace/register", + post(table_handler::register_table), + ) + .route( + "/namespaces/:namespace/tables/:table", + get(table_handler::load_table), + ) + .route( + "/namespaces/:namespace/tables/:table", + delete(table_handler::delete_table), + ) + .route( + "/namespaces/:namespace/tables/:table", + head(table_handler::table_exists), + ) .route("/tables/rename", post(table_handler::rename_table)) - .route("/namespaces/:namespace/tables/:table/metrics", post(table_handler::report_metrics)) - .route("/namespaces/:namespace/tables/:table/find/:tuple_id", get(table_handler::find_tuple_location)); - + .route( + "/namespaces/:namespace/tables/:table/metrics", + post(table_handler::report_metrics), + ) + .route( + "/namespaces/:namespace/tables/:table/find/:tuple_id", + get(table_handler::find_tuple_location), + ); + return router; } diff --git a/src/tests/mod.rs b/src/tests/mod.rs index e69de29..8b13789 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -0,0 +1 @@ +