refactor(http): drop categories/subcategories shim
Remove the transitional layer added in commits 1+2:
models.py
- Drop Category, Subcategory, CreateCategory, CreateSubcategory.
crud.py
- Drop create_category / update_category / get_category /
get_categories / delete_category and the subcategory variants
along with the _node_row_to_category / _node_row_to_subcategory
helpers. Tree state is owned exclusively by menu_node CRUD now.
views_api.py
- Remove old endpoints:
GET /api/v1/restaurants/{id}/categories
POST /api/v1/categories
DELETE /api/v1/categories/{id}
GET /api/v1/categories/{id}/subcategories
POST /api/v1/subcategories
DELETE /api/v1/subcategories/{id}
Hits return 404 now.
- GET /api/v1/restaurants/{id}/menu loses the synthetic
'categories' projection. Response is {restaurant, tree, items}.
static/js/api.js
- Drop listCategories / createCategory / deleteCategory and the
subcategory wrappers.
The CMS menu builder is broken between this commit and commit 4.
The plan acknowledged this trade-off: keeping commits revertible
beats the cost of an unshipped UI page rendering a stale empty
sidebar for one commit's lifetime.
This commit is contained in:
parent
ab87ddb2da
commit
b7fa1aec4a
4 changed files with 8 additions and 300 deletions
130
views_api.py
130
views_api.py
|
|
@ -34,24 +34,18 @@ from lnbits.decorators import (
|
|||
|
||||
from .crud import (
|
||||
create_availability_window,
|
||||
create_category,
|
||||
create_menu_item,
|
||||
create_menu_node,
|
||||
create_modifier,
|
||||
create_modifier_group,
|
||||
create_restaurant,
|
||||
create_subcategory,
|
||||
delete_availability_window,
|
||||
delete_category,
|
||||
delete_menu_item,
|
||||
delete_menu_node,
|
||||
delete_modifier,
|
||||
delete_modifier_group,
|
||||
delete_restaurant,
|
||||
delete_subcategory,
|
||||
get_availability_windows,
|
||||
get_categories,
|
||||
get_category,
|
||||
get_menu_item,
|
||||
get_menu_items,
|
||||
get_menu_node,
|
||||
|
|
@ -67,7 +61,6 @@ from .crud import (
|
|||
get_restaurant,
|
||||
get_restaurants,
|
||||
get_settings,
|
||||
get_subcategories,
|
||||
move_menu_node,
|
||||
update_menu_item,
|
||||
update_menu_node,
|
||||
|
|
@ -77,18 +70,14 @@ from .crud import (
|
|||
)
|
||||
from .models import (
|
||||
AvailabilityWindow,
|
||||
Category,
|
||||
CreateAvailabilityWindow,
|
||||
CreateCategory,
|
||||
CreateMenuItem,
|
||||
CreateMenuNode,
|
||||
CreateModifier,
|
||||
CreateModifierGroup,
|
||||
CreateOrder,
|
||||
CreateRestaurant,
|
||||
CreateSubcategory,
|
||||
MenuItem,
|
||||
MenuNode,
|
||||
MenuNodeRow,
|
||||
Modifier,
|
||||
ModifierGroup,
|
||||
|
|
@ -97,7 +86,6 @@ from .models import (
|
|||
OrderWithItems,
|
||||
Restaurant,
|
||||
RestaurantSettings,
|
||||
Subcategory,
|
||||
)
|
||||
from .nostr_publisher import (
|
||||
build_delete_event,
|
||||
|
|
@ -421,72 +409,6 @@ async def api_delete_menu_node(
|
|||
# --------------------------------------------------------------------- #
|
||||
|
||||
|
||||
@restaurant_api_router.get("/api/v1/restaurants/{restaurant_id}/categories")
|
||||
async def api_list_categories(restaurant_id: str) -> list[Category]:
|
||||
return await get_categories(restaurant_id)
|
||||
|
||||
|
||||
@restaurant_api_router.post("/api/v1/categories")
|
||||
async def api_create_category(
|
||||
data: CreateCategory,
|
||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||
) -> Category:
|
||||
restaurant = await get_restaurant(data.restaurant_id)
|
||||
if not restaurant:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Restaurant not found."
|
||||
)
|
||||
_require_owner(restaurant, wallet)
|
||||
return await create_category(data)
|
||||
|
||||
|
||||
@restaurant_api_router.delete("/api/v1/categories/{category_id}")
|
||||
async def api_delete_category(
|
||||
category_id: str,
|
||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||
):
|
||||
cat = await get_category(category_id)
|
||||
if not cat:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Category not found."
|
||||
)
|
||||
restaurant = await get_restaurant(cat.restaurant_id)
|
||||
if restaurant:
|
||||
_require_owner(restaurant, wallet)
|
||||
await delete_category(category_id)
|
||||
return "", HTTPStatus.NO_CONTENT
|
||||
|
||||
|
||||
@restaurant_api_router.get("/api/v1/categories/{category_id}/subcategories")
|
||||
async def api_list_subcategories(category_id: str) -> list[Subcategory]:
|
||||
return await get_subcategories(category_id)
|
||||
|
||||
|
||||
@restaurant_api_router.post("/api/v1/subcategories")
|
||||
async def api_create_subcategory(
|
||||
data: CreateSubcategory,
|
||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||
) -> Subcategory:
|
||||
cat = await get_category(data.category_id)
|
||||
if not cat:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Category not found."
|
||||
)
|
||||
restaurant = await get_restaurant(cat.restaurant_id)
|
||||
if restaurant:
|
||||
_require_owner(restaurant, wallet)
|
||||
return await create_subcategory(data)
|
||||
|
||||
|
||||
@restaurant_api_router.delete("/api/v1/subcategories/{subcategory_id}")
|
||||
async def api_delete_subcategory(
|
||||
subcategory_id: str,
|
||||
wallet: WalletTypeInfo = Depends(require_admin_key),
|
||||
):
|
||||
await delete_subcategory(subcategory_id)
|
||||
return "", HTTPStatus.NO_CONTENT
|
||||
|
||||
|
||||
# --------------------------------------------------------------------- #
|
||||
# Menu items #
|
||||
# --------------------------------------------------------------------- #
|
||||
|
|
@ -495,18 +417,16 @@ async def api_delete_subcategory(
|
|||
@restaurant_api_router.get("/api/v1/restaurants/{restaurant_id}/menu")
|
||||
async def api_get_menu(restaurant_id: str) -> dict:
|
||||
"""
|
||||
Public composite endpoint: returns the menu in three shapes in one
|
||||
Public composite endpoint: returns the menu in two shapes in one
|
||||
round trip.
|
||||
|
||||
* ``tree`` — the full hydrated tree (root nodes with
|
||||
nested children + items, depth, path).
|
||||
* ``items`` — flat enriched list (modifier groups, modifier
|
||||
options, availability windows attached);
|
||||
useful for search / filter.
|
||||
* ``categories`` — depth-0 nodes only, with their direct items.
|
||||
A transitional projection so the existing
|
||||
CMS keeps rendering until commit 4 swaps it
|
||||
for q-tree. Drops in commit 3.
|
||||
* ``tree`` — the full hydrated tree (root nodes with nested
|
||||
children + items, depth, path). Each item is the
|
||||
bare MenuItem (no modifier hydration).
|
||||
* ``items`` — flat enriched list (modifier groups, modifier
|
||||
options, availability windows attached); useful
|
||||
for search / filter and for hydrating the items
|
||||
referenced from ``tree``.
|
||||
|
||||
The webapp loads this once and then trusts Nostr events for
|
||||
incremental updates.
|
||||
|
|
@ -535,44 +455,10 @@ async def api_get_menu(restaurant_id: str) -> dict:
|
|||
]
|
||||
enriched_items.append(item_dict)
|
||||
|
||||
# Synthetic transitional "categories" projection: depth-0 nodes
|
||||
# plus their immediate items, mapped to the legacy shape the CMS
|
||||
# still consumes. Removed in commit 3.
|
||||
items_by_node: dict[str, list[dict]] = {}
|
||||
for it in enriched_items:
|
||||
nid = it.get("node_id")
|
||||
if nid:
|
||||
items_by_node.setdefault(nid, []).append(it)
|
||||
|
||||
legacy_categories: list[dict] = []
|
||||
for root in tree:
|
||||
cat_dict = {
|
||||
"id": root.id,
|
||||
"restaurant_id": root.restaurant_id,
|
||||
"name": root.name,
|
||||
"description": root.description,
|
||||
"sort_order": root.sort_order,
|
||||
"image_url": root.image_url,
|
||||
"time": root.time,
|
||||
"subcategories": [
|
||||
{
|
||||
"id": child.id,
|
||||
"category_id": root.id,
|
||||
"name": child.name,
|
||||
"sort_order": child.sort_order,
|
||||
"time": child.time,
|
||||
}
|
||||
for child in root.children
|
||||
],
|
||||
"items": items_by_node.get(root.id, []),
|
||||
}
|
||||
legacy_categories.append(cat_dict)
|
||||
|
||||
return {
|
||||
"restaurant": restaurant.dict(),
|
||||
"tree": [t.dict() for t in tree],
|
||||
"items": enriched_items,
|
||||
"categories": legacy_categories, # transitional, drop in commit 3
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue