Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Aditya/base routes #6

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod parameters;
pub mod parameters;
2 changes: 1 addition & 1 deletion src/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod namespace_handler;
pub mod table_handler;
pub mod table_handler;
15 changes: 7 additions & 8 deletions src/handlers/namespace_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>> {
// Logic to list namespaces
let namespaces: Vec<String> = vec!["accounting".to_string(), "tax".to_string(), "paid".to_string()];
let namespaces: Vec<String> = vec![
"accounting".to_string(),
"tax".to_string(),
"paid".to_string(),
];
Json(namespaces)
}

Expand Down Expand Up @@ -69,6 +68,6 @@ pub async fn set_namespace_properties(Path(namespace): Path<String>) -> Json<Nam
let prop = NamespaceProperties {
data: "namespace properties".to_string(),
};

Json(prop)
}
23 changes: 14 additions & 9 deletions src/handlers/table_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use axum::{
response::IntoResponse,
};


pub async fn list_tables(Path(namespace): Path<String>) -> Json<Vec<String>> {
// Dummy response for demonstration
let tables: Vec<String> = vec!["accounting".to_string(), "tax".to_string(), "paid".to_string()];
let tables: Vec<String> = vec![
"accounting".to_string(),
"tax".to_string(),
"paid".to_string(),
];
Json(tables)

}

pub async fn create_table(Path(namespace): Path<String>) -> impl IntoResponse {
Expand All @@ -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 {
Expand All @@ -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
)
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod routes;
mod config;
mod dto;
mod handlers;
mod config;
mod routes;
mod tests;

use crate::config::parameters;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod namespace;
pub mod root;
pub mod table;
pub mod root;
27 changes: 21 additions & 6 deletions src/routes/namespace.rs
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 2 additions & 3 deletions src/routes/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
50 changes: 38 additions & 12 deletions src/routes/table.rs
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading