Divar geo-coords to facility map + medical gate + RawListing FK/geo migrations
CI/CD / CI · dotnet build (push) Successful in 2m6s
CI/CD / Deploy · hamkadr (push) Successful in 2m3s

This commit is contained in:
soroush.asadi
2026-06-09 21:38:55 +03:30
parent cf5e0011c4
commit 380243b669
14 changed files with 3567 additions and 36 deletions
@@ -282,13 +282,26 @@ public class ReviewModel : PageModel
if (cityId is null) return null; // no cities seeded — cannot create a facility
// No facility named in the ad → use/create the shared placeholder.
var name = string.IsNullOrWhiteSpace(NewFacilityName) ? UnknownFacilityName : NewFacilityName.Trim();
var isPlaceholder = string.IsNullOrWhiteSpace(NewFacilityName);
var name = isPlaceholder ? UnknownFacilityName : NewFacilityName.Trim();
// Approximate coords carried from the crawl (e.g. Divar). NEVER apply them to the shared
// «نامشخص» placeholder — it's reused across many ads, so a single ad's point would mislead.
bool HasGeo() => !isPlaceholder && Raw?.Lat is not null;
// Reuse an existing facility that's exactly or closely the same (Persian-aware fuzzy
// match), so we don't create duplicates like «بیمارستان میلاد» vs «میلاد».
var all = await _db.Facilities.ToListAsync();
var match = FacilityMatcher.FindBest(all, name, cityId);
if (match is not null) return match.Id;
if (match is not null)
{
if (HasGeo() && match.Lat is null && match.Lng is null) // backfill only, never overwrite
{
match.Lat = Raw!.Lat; match.Lng = Raw.Lng;
await _db.SaveChangesAsync();
}
return match.Id;
}
var facility = new Facility
{
@@ -297,6 +310,8 @@ public class ReviewModel : PageModel
Type = FacilityType.Hospital,
Verification = VerificationStatus.Unverified,
IsVerified = false,
Lat = HasGeo() ? Raw!.Lat : null,
Lng = HasGeo() ? Raw!.Lng : null,
};
_db.Facilities.Add(facility);
await _db.SaveChangesAsync();