Divar geo-coords to facility map + medical gate + RawListing FK/geo migrations
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user