2022-05-08 09:47:05 +02:00
|
|
|
mod accounts;
|
|
|
|
mod photos;
|
|
|
|
mod product_photos;
|
|
|
|
mod products;
|
|
|
|
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
2022-05-06 16:02:38 +02:00
|
|
|
use actix::Actor;
|
|
|
|
use config::{AppConfig, UpdateConfig};
|
2022-05-08 09:47:05 +02:00
|
|
|
|
|
|
|
#[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<T> = std::result::Result<T, Error>;
|
2022-05-06 16:02:38 +02:00
|
|
|
|
|
|
|
pub struct Opts;
|
|
|
|
impl UpdateConfig for Opts {
|
|
|
|
fn update_config(&self, _config: &mut AppConfig) {}
|
|
|
|
}
|
|
|
|
|
2022-05-08 09:47:05 +02:00
|
|
|
#[derive(Default)]
|
|
|
|
pub(crate) struct DbSeed {
|
|
|
|
pub accounts: Vec<model::FullAccount>,
|
|
|
|
pub products: Vec<model::Product>,
|
|
|
|
pub photos: Vec<model::Photo>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) type SharedState = Arc<Mutex<DbSeed>>;
|
|
|
|
|
2022-05-06 16:02:38 +02:00
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() {
|
2022-05-08 09:47:05 +02:00
|
|
|
human_panic::setup_panic!();
|
|
|
|
|
2022-05-06 16:02:38 +02:00
|
|
|
dotenv::dotenv().ok();
|
|
|
|
std::env::set_var("RUST_LOG", "DEBUG");
|
2022-06-07 11:36:01 +02:00
|
|
|
tracing_subscriber::fmt::init();
|
2022-05-06 16:02:38 +02:00
|
|
|
|
2022-05-08 09:47:05 +02:00
|
|
|
let db_seed = Arc::new(Mutex::new(DbSeed::default()));
|
2022-05-06 16:02:38 +02:00
|
|
|
let config = config::default_load(&Opts);
|
2022-05-08 09:47:05 +02:00
|
|
|
|
|
|
|
let db = database_manager::Database::build(config.clone())
|
2022-05-06 16:02:38 +02:00
|
|
|
.await
|
|
|
|
.start();
|
|
|
|
|
2022-05-08 09:47:05 +02:00
|
|
|
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();
|
2022-05-06 16:02:38 +02:00
|
|
|
}
|