mod accounts; mod photos; mod product_photos; mod products; use std::sync::{Arc, Mutex}; use actix::Actor; use config::{AppConfig, UpdateConfig}; #[derive(Debug, thiserror::Error)] pub enum Error { #[error("Photo with name {0:?} was not found")] PhotoNotFound(String), #[error("Failed to create product record in database")] DbProduct, #[error("Failed to attach photo {1:?} to product {0:?} in database")] DbProductPhoto(model::ProductId, model::PhotoId), #[error("Product with name {0:?} does not exists")] NoProduct(String), #[error("Failed to create photo record for file {0:?}")] WritePhoto(String), } pub type Result = std::result::Result; pub struct Opts; impl UpdateConfig for Opts { fn update_config(&self, _config: &mut AppConfig) {} } #[derive(Default)] pub(crate) struct DbSeed { pub accounts: Vec, pub products: Vec, pub photos: Vec, } pub(crate) type SharedState = Arc>; #[actix_web::main] async fn main() { human_panic::setup_panic!(); dotenv::dotenv().ok(); std::env::set_var("RUST_LOG", "DEBUG"); pretty_env_logger::init(); let db_seed = Arc::new(Mutex::new(DbSeed::default())); let config = config::default_load(&Opts); let db = database_manager::Database::build(config.clone()) .await .start(); let res = tokio::join!( accounts::create_accounts(db.clone(), db_seed.clone(), config.clone()), products::create_products(db.clone(), db_seed.clone(), config.clone()) ); res.0.unwrap(); res.1.unwrap(); }