use actix::Addr; use config::SharedAppConfig; use database_manager::{query_db, Database}; use fake::{Fake, Faker}; use model::{ProductCategory, ProductName}; use crate::product_photos::create_product_photos; use crate::{Result, SharedState}; async fn create_product( db: Addr, seed: SharedState, name: &'static str, category: &'static str, short_desc: Option<&'static str>, long_desc: Option<&'static str>, ) -> crate::Result<()> { let seed = seed.clone(); let db = db.clone(); let product = query_db!( db, database_manager::CreateProduct { name: ProductName::from(String::from(name)), short_description: short_desc .map(|s| model::ProductShortDesc::new(s)) .unwrap_or_else(|| Faker.fake()), long_description: long_desc .map(|s| model::ProductLongDesc::new(s)) .unwrap_or_else(|| Faker.fake()), category: Some(ProductCategory::new(category)), price: Faker.fake(), deliver_days_flag: Faker.fake(), }, crate::Error::DbProduct ); seed.lock().unwrap().products.push(product); Ok(()) } pub(crate) async fn create_products( db: Addr, seed: SharedState, config: SharedAppConfig, ) -> Result<()> { crate::photos::create_photos(db.clone(), seed.clone(), config.clone()) .await .unwrap(); let products = query_db!(db, database_manager::AllProducts, default vec![]); if products.len() >= 10 { { seed.lock().unwrap().products = products; } if let Err(e) = create_product_photos(db.clone(), seed.clone(), config.clone()).await { log::error!("{e:?}"); } return Ok(()); } let results = tokio::join!( create_product( db.clone(), seed.clone(), "Nikon", model::Category::CAMERAS_NAME, None, None ), create_product( db.clone(), seed.clone(), "Bonoid CBD", model::Category::DRUGSTORE_NAME, None, None ), create_product( db.clone(), seed.clone(), "Casio Speaker", model::Category::SPEAKERS_NAME, None, None ), create_product( db.clone(), seed.clone(), "Eprism Studio", model::Category::DRUGSTORE_NAME, None, None ), create_product( db.clone(), seed.clone(), "Best Phones 2022", model::Category::PHONES_NAME, None, None ), create_product( db.clone(), seed.clone(), "Sweet cake", model::Category::SWEETS_NAME, None, Some("The packaging of a product can do so much to the brand awareness campaigns of any brand. With a good quality logo along with the color scheme of a brand added on those packaging, it can perfectly represent such brand wherever it may reach. Do you need a mockup to test your paper lock box packaging? If you do then this freebie will make you feel lucky. It features 2 paper lock boxes with the one top of the other. Apparently, each of the boxes comes with smart object layer for inserting your own branding. You can use this for bread, donuts and similar products.") ), create_product( db.clone(), seed.clone(), "Lexal 128G", model::Category::MEMORY_NAME, None, None ), create_product( db.clone(), seed.clone(), "Fujifilm X-T10", model::Category::CAMERAS_NAME, None, None ), create_product( db.clone(), seed.clone(), "Sweet Tower", model::Category::SWEETS_NAME, None, Some("If you’re currently designing a label for your product packaging using pouch, you can opt for this Plastic Pouch Product Mockup Free PSD. Before you finalize your designs, it would be best to have a product mockup to help you see the flaws and polish it well. This mockup will aid you with your label designs for soy sauce, tomato sauce, coffee or any pouch products. Apparently, this mockup lets you add a design for the surface of the pouch via smart object layer; change the color of the pouch to represent the kind of flavor of the product inside and the background color to match with your designs.") ), create_product( db.clone(), seed.clone(), "Nikon Lenses", model::Category::CAMERAS_NAME, None, None ), create_product( db.clone(), seed.clone(), "Venus HD Professional", model::Category::DRUGSTORE_NAME, None, Some("Cosmetic products have always been hot and in demand. That’s why many entrepreneurs in this line of business always seek for the best cosmetic products to meet the demands. Hence, cosmetic businesses need to craft their labels with keenness to for effective branding. If you’re a designer working with cosmetic products packaging, this free mockup is useful to you. It features a cosmetic pump bottle and a cream pot to showcase your logo, branding and marketing designs. You can easily add your own graphics into the scene via the smart object layer. With this mockup, you can impress a client with a photorealistic product packaging in no time!") ), create_product( db.clone(), seed.clone(), "Fancy Plate", model::Category::PLATES_NAME, None, None ) ); results.0.unwrap(); results.1.unwrap(); results.2.unwrap(); results.3.unwrap(); results.4.unwrap(); results.5.unwrap(); results.6.unwrap(); results.7.unwrap(); results.8.unwrap(); results.9.unwrap(); results.10.unwrap(); create_product_photos(db.clone(), seed.clone(), config.clone()).await }