ReviewOS

stacks/smakelo

B2.1: Markets, businesses, hours, and geo radius search

#4
Closed chris opened this 9 days ago ·
9 days ago

Part of #1. Tracer bullet: model -> migration -> action -> route -> test.

  • Market + Business + BusinessHour CRUD actions and routes
  • GET /api/businesses?lat&lng&radius&q&open_now&type - SQL bounding-box prefilter + haversine distance (SQLite has no trig guarantee; compute distance in app code on prefiltered rows), distance sort, open-now computed from BusinessHour in the business timezone
  • Search engine (text relevance) indexes name/cuisine/description only; geo stays in SQL
  • Feature tests: radius correctness, open-now edge cases (overnight hours, holiday override)
9 days ago

Done in 864cdc9 and 9bbe173, live at https://smakelo.stacksjs.com

  • Market, Business, BusinessHour models with capability flags (delivery/pickup/dineIn/shop) rather than a type, since they do not correlate: a farm delivers and has no tables, a coffee shop has tables and no delivery.
  • searchBusinesses() in app/Actions/Business/search.ts: SQL bounding box, then an exact haversine circle in code. The box is indexable and keeps too much; the circle is exact and would be wasteful across a city.
  • The bounding box widens longitude by the cosine of latitude. Without it the box is too narrow in Los Angeles and silently drops about a sixth of the results.
  • Open-now resolves in the business's timezone via Intl, re-checks the previous day's intervals so a bar closing at 2am is open at 1am, handles split lunch/dinner service, and keeps unknown distinct from closed so a listing with unrecorded hours is not filtered out as though it were shut.
  • GET /api/businesses?lat&lng&radius&q&type&open_now&partners_only&sort is live and returns the same results the page renders.
  • 23 tests over geo and hours, including the daylight-saving boundary that made the first draft an hour wrong.

Sign in to comment on this issue.