Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ce0b3e3e8 |
@@ -11,6 +11,28 @@ namespace Meezi.Infrastructure.Data;
|
|||||||
/// <summary>Seeds 30 Persian showcase cafés for public discover (development only).</summary>
|
/// <summary>Seeds 30 Persian showcase cafés for public discover (development only).</summary>
|
||||||
public static class DiscoverShowcaseSeeder
|
public static class DiscoverShowcaseSeeder
|
||||||
{
|
{
|
||||||
|
// Approximate city centres. Each café is scattered around its city with a
|
||||||
|
// small deterministic offset (derived from its id) so the marketing map
|
||||||
|
// shows a realistic cluster of blinking lights instead of one stacked dot.
|
||||||
|
private static readonly Dictionary<string, (double Lat, double Lng, double Spread)> CityGeo = new()
|
||||||
|
{
|
||||||
|
["تهران"] = (35.70, 51.39, 0.13),
|
||||||
|
["کرج"] = (35.83, 50.99, 0.07),
|
||||||
|
};
|
||||||
|
|
||||||
|
private static (double Lat, double Lng) GeoFor(string id, string city)
|
||||||
|
{
|
||||||
|
var (lat, lng, spread) = CityGeo.TryGetValue(city, out var g) ? g : (35.70, 51.39, 0.13);
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
var h = 17;
|
||||||
|
foreach (var ch in id) h = (h * 31) + ch;
|
||||||
|
var ox = (((h & 0xFFFF) / 65535.0) - 0.5) * 2 * spread;
|
||||||
|
var oy = ((((h >> 16) & 0xFFFF) / 65535.0) - 0.5) * 2 * spread;
|
||||||
|
return (Math.Round(lat + oy, 5), Math.Round(lng + ox, 5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly string[] ReviewAuthors = ["سارا", "علی", "مینا", "رضا", "نازنین"];
|
private static readonly string[] ReviewAuthors = ["سارا", "علی", "مینا", "رضا", "نازنین"];
|
||||||
private static readonly string[] ReviewComments =
|
private static readonly string[] ReviewComments =
|
||||||
[
|
[
|
||||||
@@ -27,6 +49,7 @@ public static class DiscoverShowcaseSeeder
|
|||||||
foreach (var spec in DiscoverShowcaseCatalog.Cafes)
|
foreach (var spec in DiscoverShowcaseCatalog.Cafes)
|
||||||
{
|
{
|
||||||
var cafe = await db.Cafes.FirstOrDefaultAsync(c => c.Id == spec.Id);
|
var cafe = await db.Cafes.FirstOrDefaultAsync(c => c.Id == spec.Id);
|
||||||
|
var (geoLat, geoLng) = GeoFor(spec.Id, spec.City);
|
||||||
if (cafe is null)
|
if (cafe is null)
|
||||||
{
|
{
|
||||||
cafe = new Cafe
|
cafe = new Cafe
|
||||||
@@ -37,6 +60,8 @@ public static class DiscoverShowcaseSeeder
|
|||||||
Slug = spec.Slug,
|
Slug = spec.Slug,
|
||||||
City = spec.City,
|
City = spec.City,
|
||||||
Address = spec.Address,
|
Address = spec.Address,
|
||||||
|
Latitude = geoLat,
|
||||||
|
Longitude = geoLng,
|
||||||
Description = spec.Description,
|
Description = spec.Description,
|
||||||
PlanTier = spec.PlanTier,
|
PlanTier = spec.PlanTier,
|
||||||
PreferredLanguage = "fa",
|
PreferredLanguage = "fa",
|
||||||
@@ -100,6 +125,12 @@ public static class DiscoverShowcaseSeeder
|
|||||||
cafe.IsVerified = true;
|
cafe.IsVerified = true;
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
if (cafe.Latitude is null || cafe.Longitude is null)
|
||||||
|
{
|
||||||
|
cafe.Latitude = geoLat;
|
||||||
|
cafe.Longitude = geoLng;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
if (changed)
|
if (changed)
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user