sharenet/backend/crates/sharenet-tui-postgres/src/main.rs

43 lines
1.5 KiB
Rust

use anyhow::Result;
use postgres::{PostgresUserService, PostgresProductService};
use tui::run_tui;
#[tokio::main]
async fn main() -> Result<()> {
// Debug: Print current working directory
println!("Current working directory: {:?}", std::env::current_dir()?);
// Try multiple possible paths for the environment file
let env_paths = [
"config/tui-postgres.env",
"../config/tui-postgres.env",
"../../config/tui-postgres.env",
];
let mut env_loaded = false;
for path in &env_paths {
println!("Trying to load environment from: {}", path);
if dotenvy::from_path(path).is_ok() {
println!("Successfully loaded environment from: {}", path);
env_loaded = true;
break;
} else {
println!("Failed to load environment from: {}", path);
}
}
if !env_loaded {
eprintln!("Warning: Could not load environment file from any of the expected paths");
}
// Debug: Print DATABASE_URL if it exists
match std::env::var("DATABASE_URL") {
Ok(url) => println!("DATABASE_URL found: {}", url),
Err(e) => println!("DATABASE_URL not found: {}", e),
}
let pool = sqlx::PgPool::connect(&std::env::var("DATABASE_URL")?).await?;
let user_service = PostgresUserService::new(postgres::PostgresUserRepository::new(pool.clone()));
let product_service = PostgresProductService::new(postgres::PostgresProductRepository::new(pool));
run_tui(user_service, product_service).await
}