From 13de28e2e1a4bc7eca3e2d089939db3dd0faa815 Mon Sep 17 00:00:00 2001 From: Padreug Date: Mon, 11 May 2026 09:03:10 +0200 Subject: [PATCH] feat(api): public GET /restaurants/by-slug/{slug} Prerequisite for the customer webapp module (aiolabs/webapp, branch feat/restaurant-bundle): the webapp's /r/:slug route needs to resolve a slug to a Restaurant payload without an admin key. crud.get_restaurant_by_slug already exists (used by the server- rendered CMS routes in views.py); just expose it as a public REST endpoint. Mirrors api_get_restaurant by id and is declared before the bare-id route so the static prefix wins FastAPI's path match. Verified live against seeded 'Big Jay's Bustaurant': GET /restaurant/api/v1/restaurants/by-slug/big-jays-bustaurant -> 200 with the Restaurant payload. --- views_api.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/views_api.py b/views_api.py index 74ca8e3..ad26520 100644 --- a/views_api.py +++ b/views_api.py @@ -59,6 +59,7 @@ from .crud import ( get_print_job, get_print_jobs, get_restaurant, + get_restaurant_by_slug, get_restaurants, get_settings, move_menu_node, @@ -248,6 +249,20 @@ async def api_list_restaurants( return await get_restaurants(wallet_ids) +@restaurant_api_router.get("/api/v1/restaurants/by-slug/{slug}") +async def api_get_restaurant_by_slug(slug: str) -> Restaurant: + """Public — used by the customer webapp to resolve a URL slug + (e.g. /r/big-jays-bustaurant) to a restaurant. Mirrors + api_get_restaurant; declared *before* the bare-id route so the + static prefix wins the path match in FastAPI's router.""" + restaurant = await get_restaurant_by_slug(slug) + if not restaurant: + raise HTTPException( + status_code=HTTPStatus.NOT_FOUND, detail="Restaurant not found." + ) + return restaurant + + @restaurant_api_router.get("/api/v1/restaurants/{restaurant_id}") async def api_get_restaurant(restaurant_id: str) -> Restaurant: """Public — used by the webapp to fetch profile metadata."""