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.
This commit is contained in:
parent
dd756ecfc3
commit
6dae57f3f4
3 changed files with 27 additions and 1 deletions
15
views_api.py
15
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."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue