feat: plan limits, café location, nearby API, Iran map section
CI/CD / CI · API (dotnet build + test) (push) Successful in 56s
CI/CD / CI · Admin API (dotnet build) (push) Successful in 49s
CI/CD / CI · Dashboard (tsc) (push) Successful in 1m4s
CI/CD / CI · Admin Web (tsc) (push) Successful in 34s
CI/CD / CI · Website (tsc) (push) Successful in 44s
CI/CD / CI · Koja (tsc) (push) Successful in 50s
CI/CD / Deploy · all services (push) Successful in 3m15s

• PlanLimits: add MaxMenuCategories (Free→3), MaxMenuItems (Free→30),
  CanAccessCrm and CanAccessStatistics (Pro+ only)
• MenuController: enforce category/item limits before create (403 + PLAN_LIMIT_REACHED)
• Cafe entity + EF migration: Latitude/Longitude (double?, nullable)
• CafeSettingsController: PATCH accepts lat/lng with range validation
• PublicController: GET /api/public/map-markers (marketing SVG map feed)
  and GET /api/public/nearby (Koja nearby-cafés with Haversine sort)
• Dashboard settings: location card with OSM iframe preview + Neshan link
• Website homepage: IranMapSection — stylised SVG silhouette with
  SMIL-animated blinking dots at real café coordinates

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-01 15:09:09 +03:30
parent 665e3ca279
commit 5e980cdfc0
12 changed files with 619 additions and 4 deletions
@@ -367,4 +367,101 @@ public class PublicController : ControllerBase
return Ok(new ApiResponse<object>(true, null));
}
/// <summary>
/// Returns all cafés that have a known location (Latitude/Longitude set).
/// Used by the marketing website SVG map to render blinking dots.
/// </summary>
[HttpGet("map-markers")]
[EnableRateLimiting("public-read")]
public async Task<IActionResult> GetMapMarkers(
[FromServices] AppDbContext db,
CancellationToken ct)
{
var markers = await db.Cafes
.AsNoTracking()
.Where(c => c.DeletedAt == null && c.Latitude != null && c.Longitude != null)
.Select(c => new
{
c.Id,
c.Name,
c.Slug,
c.City,
c.Latitude,
c.Longitude,
c.LogoUrl
})
.ToListAsync(ct);
return Ok(new ApiResponse<object>(true, markers));
}
/// <summary>
/// Returns cafés near a given coordinate, sorted by distance ascending.
/// Used by Koja guest page to show "nearby cafés" section.
/// At most <paramref name="limit"/> results (default 5, max 20).
/// </summary>
[HttpGet("nearby")]
[EnableRateLimiting("public-read")]
public async Task<IActionResult> GetNearbyCafes(
[FromQuery] double lat,
[FromQuery] double lng,
[FromQuery] string? excludeSlug,
[FromQuery] int limit,
[FromServices] AppDbContext db,
CancellationToken ct)
{
limit = Math.Clamp(limit <= 0 ? 5 : limit, 1, 20);
// Pull all located cafés from DB (typically small set) and sort in memory with Haversine.
var cafes = await db.Cafes
.AsNoTracking()
.Where(c => c.DeletedAt == null
&& c.Latitude != null
&& c.Longitude != null
&& (excludeSlug == null || c.Slug != excludeSlug))
.Select(c => new
{
c.Id,
c.Name,
c.Slug,
c.City,
c.Latitude,
c.Longitude,
c.LogoUrl,
c.CoverImageUrl
})
.ToListAsync(ct);
static double ToRad(double deg) => deg * Math.PI / 180.0;
static double Haversine(double lat1, double lon1, double lat2, double lon2)
{
const double R = 6371; // km
var dLat = ToRad(lat2 - lat1);
var dLon = ToRad(lon2 - lon1);
var a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2)
+ Math.Cos(ToRad(lat1)) * Math.Cos(ToRad(lat2))
* Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
return R * 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
}
var nearby = cafes
.Select(c => new
{
c.Id,
c.Name,
c.Slug,
c.City,
c.Latitude,
c.Longitude,
c.LogoUrl,
c.CoverImageUrl,
DistanceKm = Math.Round(Haversine(lat, lng, c.Latitude!.Value, c.Longitude!.Value), 1)
})
.OrderBy(c => c.DistanceKm)
.Take(limit)
.ToList();
return Ok(new ApiResponse<object>(true, nearby));
}
}