Product seeding completed
This commit is contained in:
@@ -65,8 +65,19 @@ public class ProductsSeederService(ProductService productService, AuthorService
|
||||
"Unlocking Creative Flow Under Pressure"
|
||||
);
|
||||
|
||||
// Defensive Length Processing to avoid Entity Framework / Postgres string truncation crashes
|
||||
var rawTitle = $"{faker.Company.CatchPhrase()} with {bookTopic}";
|
||||
// Dynamic raw title generation formulas executed via random function picker
|
||||
var titlePatterns = new Func<string>[]
|
||||
{
|
||||
() => $"{faker.Company.CatchPhrase()} with {bookTopic}",
|
||||
() => $"The {faker.Commerce.ProductAdjective()} Guide to {bookTopic}",
|
||||
() => $"Mastering {bookTopic}: A {faker.Company.Bs()} Blueprint",
|
||||
() => $"{bookTopic} for the Modern {faker.Name.JobTitle()}",
|
||||
() => $"Advanced {bookTopic}: Demystifying the {faker.Company.CatchPhrase()}",
|
||||
() => $"{faker.Random.Replace("###")} Blueprints for {bookTopic}"
|
||||
};
|
||||
|
||||
// Pick a format template and resolve it down to raw string text
|
||||
var rawTitle = faker.PickRandom(titlePatterns)();
|
||||
var bookTitle = rawTitle.Length > 255 ? rawTitle[..252] + "..." : rawTitle;
|
||||
|
||||
var rawSummary = $"A comprehensive guide to mastering {bookTopic}. Learn modern implementation techniques through real-world software engineering paradigms.";
|
||||
@@ -80,6 +91,21 @@ public class ProductsSeederService(ProductService productService, AuthorService
|
||||
var authorLastName = faker.Name.LastName();
|
||||
var publisherCompany = faker.Company.CompanyName();
|
||||
|
||||
// Safe bounded random picking for book thumbnails
|
||||
string? pickedBookThumbnail = null;
|
||||
string? pickedBookThumbnail1 = null;
|
||||
string? pickedBookThumbnail2 = null;
|
||||
string? pickedBookThumbnail3 = null;
|
||||
string? pickedBookThumbnail4 = null;
|
||||
if (cdnSettings.BookThumbnails is not null && cdnSettings.BookThumbnails.Length > 0)
|
||||
{
|
||||
pickedBookThumbnail = $"{cdnSettings.BaseCdn}{faker.PickRandom(cdnSettings.BookThumbnails)}";
|
||||
pickedBookThumbnail1 = $"{cdnSettings.BaseCdn}{faker.PickRandom(cdnSettings.BookThumbnails)}";
|
||||
pickedBookThumbnail2 = $"{cdnSettings.BaseCdn}{faker.PickRandom(cdnSettings.BookThumbnails)}";
|
||||
pickedBookThumbnail3 = $"{cdnSettings.BaseCdn}{faker.PickRandom(cdnSettings.BookThumbnails)}";
|
||||
pickedBookThumbnail4 = $"{cdnSettings.BaseCdn}{faker.PickRandom(cdnSettings.BookThumbnails)}";
|
||||
}
|
||||
|
||||
// Step 1: Add Product
|
||||
var productCreateResult = await productService.CreateProductAsync(new Products.Models.CreateProduct
|
||||
{
|
||||
@@ -95,7 +121,8 @@ public class ProductsSeederService(ProductService productService, AuthorService
|
||||
Manufacturer = $"{authorFirstName} {authorLastName} / {publisherCompany}",
|
||||
SerialNumber = faker.Phone.PhoneNumber("978-##########")
|
||||
},
|
||||
Categories = ["Coding", "Computers", "IT"]
|
||||
Categories = ["Coding", "Computers", "IT"],
|
||||
ThumbnailUrls = pickedBookThumbnail is not null ? [pickedBookThumbnail, pickedBookThumbnail1!, pickedBookThumbnail2!, pickedBookThumbnail3!, pickedBookThumbnail4!] : null
|
||||
}, stoppingToken);
|
||||
|
||||
if (productCreateResult.IsFailed)
|
||||
@@ -116,7 +143,6 @@ public class ProductsSeederService(ProductService productService, AuthorService
|
||||
// Step 3: Create Product Price
|
||||
var productPriceCreateResult = await productService.CreateProductPriceAsync(productId: productCreateResult.Value, request: new Products.Models.CreateProductPrice
|
||||
{
|
||||
// Generates fair, dynamic prices in Rands between R150 and R650, snapped neatly to integers
|
||||
Amount = Math.Round(faker.Random.Decimal(150m, 650m), 2),
|
||||
Discount = 0.0m
|
||||
}, stoppingToken);
|
||||
@@ -127,6 +153,34 @@ public class ProductsSeederService(ProductService productService, AuthorService
|
||||
break;
|
||||
}
|
||||
|
||||
// Safe bounded picking for Authors (Real Avatars)
|
||||
string authorAvatarUrl = faker.Internet.Avatar(); // Fallback
|
||||
if (cdnSettings.Authors is not null && cdnSettings.Authors.Length > 0)
|
||||
{
|
||||
authorAvatarUrl = $"{cdnSettings.BaseCdn}{faker.PickRandom(cdnSettings.Authors)}";
|
||||
}
|
||||
|
||||
// Safe bounded picking for Author Thumbnails (Cartoon Avatars)
|
||||
string? authorThumbnailUrl = null;
|
||||
if (cdnSettings.AuthorThumbnails is not null && cdnSettings.AuthorThumbnails.Length > 0)
|
||||
{
|
||||
var selectedThumb = faker.PickRandom(cdnSettings.AuthorThumbnails);
|
||||
authorThumbnailUrl = $"{cdnSettings.BaseCdn}{selectedThumb}.jpg";
|
||||
}
|
||||
|
||||
// Synthesize a highly dynamic, organic opening bio statement
|
||||
var professionalBackgrounds = new[]
|
||||
{
|
||||
$"{authorFirstName} {authorLastName} is an award-winning {faker.Name.JobDescriptor()} {faker.Name.JobTitle()} with over {faker.Random.Number(5, 25)} years of core engineering domain expertise.",
|
||||
$"As a veteran systems consultant and practicing {faker.Name.JobTitle()}, {authorFirstName} has spent decades leading digital infrastructure transformations and managing complex topologies.",
|
||||
$"Operating from modern innovation hubs, {authorFirstName} {authorLastName} specializes in global product strategies and serves as an authority in {faker.Name.JobDescriptor()} computing.",
|
||||
$"With a rich professional background as a principal {faker.Name.JobTitle()} at {publisherCompany}, {authorFirstName} has spent a lifetime refining the system workflows highlighted here."
|
||||
};
|
||||
|
||||
// Pick a randomized context hook and append a 2-paragraph contextual narrative block
|
||||
var biographyPrefix = faker.PickRandom(professionalBackgrounds);
|
||||
var authorBiography = $"{biographyPrefix} {faker.Lorem.Paragraph(2)}";
|
||||
|
||||
// Step 4: Create Author
|
||||
var authorCreateResult = await authorService.CreateAuthorAsync(request: new Authors.Models.CreateAuthor
|
||||
{
|
||||
@@ -137,7 +191,7 @@ public class ProductsSeederService(ProductService productService, AuthorService
|
||||
PublisherType = faker.PickRandom<PublisherTypes>(),
|
||||
Email = faker.Internet.Email(authorFirstName, authorLastName),
|
||||
Website = faker.Internet.Url(),
|
||||
ImageUrl = faker.Internet.Avatar(),
|
||||
ImageUrl = authorAvatarUrl,
|
||||
SocialMedia =
|
||||
[
|
||||
new Models.SocialMedia
|
||||
@@ -155,8 +209,8 @@ public class ProductsSeederService(ProductService productService, AuthorService
|
||||
Url = $"https://github.com/tech-{authorFirstName.ToLower(culture)}"
|
||||
}
|
||||
],
|
||||
Biography = $"{authorFirstName} {authorLastName} is a veteran technologist and systems architect with over a decade of domain expertise. " + faker.Lorem.Paragraph(2),
|
||||
ThumbnailImageUrl = null
|
||||
Biography = authorBiography,
|
||||
ThumbnailImageUrl = authorThumbnailUrl
|
||||
}, stoppingToken);
|
||||
|
||||
if (authorCreateResult.IsFailed)
|
||||
|
||||
Reference in New Issue
Block a user