bazzar/db-seed/src/products.rs

180 lines
7.5 KiB
Rust
Raw Normal View History

2022-05-08 09:47:05 +02:00
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<Database>,
seed: SharedState,
name: &'static str,
category: &'static str,
2022-05-12 22:10:17 +02:00
short_desc: Option<&'static str>,
long_desc: Option<&'static str>,
2022-05-08 09:47:05 +02:00
) -> crate::Result<()> {
let seed = seed.clone();
let db = db.clone();
let product = query_db!(
db,
database_manager::CreateProduct {
name: ProductName::from(String::from(name)),
2022-05-12 22:10:17 +02:00
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()),
2022-05-08 09:47:05 +02:00
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<Database>,
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 {
tracing::error!("{e:?}");
2022-05-08 09:47:05 +02:00
}
return Ok(());
}
let results = tokio::join!(
create_product(
db.clone(),
seed.clone(),
"Nikon",
model::Category::CAMERAS_NAME,
2022-05-12 22:10:17 +02:00
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Bonoid CBD",
model::Category::DRUGSTORE_NAME,
2022-05-12 22:10:17 +02:00
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Casio Speaker",
model::Category::SPEAKERS_NAME,
2022-05-12 22:10:17 +02:00
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Eprism Studio",
model::Category::DRUGSTORE_NAME,
2022-05-12 22:10:17 +02:00
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Best Phones 2022",
model::Category::PHONES_NAME,
2022-05-12 22:10:17 +02:00
None,
None
),
create_product(
db.clone(),
seed.clone(),
"Sweet cake",
model::Category::SWEETS_NAME,
2022-05-12 22:10:17 +02:00
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,
2022-05-12 22:10:17 +02:00
None,
2022-05-13 15:24:11 +02:00
Some(r#"Nothing beats a freshly pulled pint in your favourite pub—except maybe a freshly pulled pint in your very own home.
Never battle with crowds, struggle for a seat, or have to hang about outside on the pavement just to enjoy your favourite beer again! The Fizzics DraftPour gives you nitro-style draft beer from ANY can or bottle. Even the cheapest economy lager can be instantly transformed into a luxurious draft pint with just one pull of the lever.
The DraftPour may be a sleek piece of kit, but its deceptively high tech under the hood, applying sound waves to convert your beers natural carbonation into a smooth micro-foam. These diddy little bubbles create the optimal density for enhanced aroma, flavour, and a silky smooth mouth-feel.
Get a fruit machine and a few boxes of pork scratchings in and youve basically completely replicated your local pub. Sticky bar-top and ancient, dubiously-stained carpet not included."#)
),
create_product(
db.clone(),
seed.clone(),
"Fujifilm X-T10",
model::Category::CAMERAS_NAME,
2022-05-12 22:10:17 +02:00
None,
2022-05-13 15:24:11 +02:00
Some(r#"The Dauré family own one of the Roussillons top properties, the Château de Jau. Around the dinner table one Christmas they agreed it was time to spread their wings and look to new wine horizons. The womenfolk (Las Niñas) fancied Chile and won out in the end, achieving their dream when they established an estate in the Apalta Valley of Colchagua. The terroir is excellent and close neighbours of the Chilean star Montes winery."#)
),
create_product(
db.clone(),
seed.clone(),
"Sweet Tower",
model::Category::SWEETS_NAME,
2022-05-12 22:10:17 +02:00
None,
Some("If youre 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,
2022-05-12 22:10:17 +02:00
None,
None
),
2022-05-08 09:47:05 +02:00
create_product(
db.clone(),
seed.clone(),
"Venus HD Professional",
model::Category::DRUGSTORE_NAME,
2022-05-12 22:10:17 +02:00
None,
Some("Cosmetic products have always been hot and in demand. Thats 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 youre 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,
2022-05-12 22:10:17 +02:00
None,
None
2022-05-08 09:47:05 +02:00
)
);
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
}