diff --git a/src/main.rs b/src/main.rs index e445b86..815237d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,10 @@ -use std::sync::Mutex; - use axum::{ response::IntoResponse, routing::{delete, get, put}, Extension, Router, }; use polars::prelude::*; -use tokio_postgres::NoTls; +use std::sync::Mutex; // Generetes a bunch of random data in the db async fn generate_random_data( @@ -198,30 +196,30 @@ async fn get_data( async fn accounts(Extension(state): Extension>) -> impl IntoResponse { let accounts = state.accounts_dataframe.lock().unwrap(); - if accounts.is_some() { - let df = accounts.as_ref().unwrap().clone(); - let to_send = df.select(vec![col("uuid"), col("name")]).collect().unwrap(); - return format!("{}", to_send); + if accounts.is_none() { + return "Injest Data First".into(); } - return "Injest Data First".into(); + let df = accounts.as_ref().unwrap().clone(); + let to_send = df.select(vec![col("uuid"), col("name")]).collect().unwrap(); + return format!("{}", to_send); } async fn transactions(Extension(state): Extension>) -> impl IntoResponse { let transactions = state.transactions_dataframe.lock().unwrap(); - if transactions.is_some() { - let df = transactions.as_ref().unwrap().clone(); - let to_send = df - .select(vec![ - col("uuid"), - col("source"), - col("target"), - col("amount"), - ]) - .collect() - .unwrap(); - return format!("{}", to_send); + if transactions.is_none() { + return "Injest Data First".into(); } - return "Injest Data First".into(); + let df = transactions.as_ref().unwrap().clone(); + let to_send = df + .select(vec![ + col("uuid"), + col("source"), + col("target"), + col("amount"), + ]) + .collect() + .unwrap(); + return format!("{}", to_send); } struct State { @@ -246,7 +244,7 @@ async fn main() { } let psql_conn = psql_conn.unwrap(); - let (client, connection) = tokio_postgres::connect(psql_conn.as_str(), NoTls) + let (client, connection) = tokio_postgres::connect(psql_conn.as_str(), tokio_postgres::NoTls) .await .unwrap();