Files
Tom FluxandClaude Opus 4.8 7255c9302c Phase 3a: close the Django API gaps for the MCP server
Backend prerequisites for the FastMCP service (mcp.md §6) — no model
changes, no migration.

- log_cook: accepts `rating`, validates via full_clean (enforces the
  exactly-one-recipe rule), and returns `used_ingredients` as a
  suggestion set instead of mutating the pantry. Auto-deduct path and
  _deduct_ingredient removed — pantry state changes only via set-state
  after the user confirms.
- New POST /api/pantry/set-state/ — set in/low/out by ingredient name
  (alias-aware), optional location; registered before the router so the
  pantry detail route doesn't capture "set-state" as a pk.
- what_can_i_cook: presence-based (exclude 'out', tolerate null
  quantity) so the API matcher agrees with the web one.
- bulk-pantry-add: restocks an existing ingredient+location row to 'in'
  instead of duplicating; quantity is an optional int.

Tests cover all four + that pantry `state` is serialized (24 pass).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 21:07:18 +01:00

30 lines
1.4 KiB
Python

from django.urls import path, include
from rest_framework.routers import DefaultRouter
from . import views
router = DefaultRouter()
router.register(r"tags", views.TagViewSet)
router.register(r"ingredients", views.IngredientViewSet)
router.register(r"pantry", views.PantryItemViewSet)
router.register(r"meta-recipes", views.MetaRecipeViewSet)
router.register(r"slots", views.SlotViewSet)
router.register(r"slot-options", views.SlotOptionViewSet)
router.register(r"meta-recipe-bases", views.MetaRecipeBaseViewSet)
router.register(r"recipes", views.RecipeViewSet)
router.register(r"recipe-ingredients", views.RecipeIngredientViewSet)
router.register(r"cook-log", views.CookLogViewSet)
router.register(r"shopping-list", views.ShoppingListItemViewSet)
urlpatterns = [
# Must precede the router include — otherwise the PantryItem detail route
# (pantry/<pk>/) captures "set-state" as a pk.
path("pantry/set-state/", views.set_pantry_state, name="set-pantry-state"),
path("", include(router.urls)),
path("what-can-i-cook/", views.what_can_i_cook, name="what-can-i-cook"),
path("log-cook/", views.log_cook, name="log-cook"),
path("bulk-pantry-add/", views.bulk_pantry_add, name="bulk-pantry-add"),
path("generate-shopping-list/", views.generate_shopping_list, name="generate-shopping-list"),
path("import-recipe/", views.import_recipe_url, name="import-recipe"),
path("create-meta-recipe/", views.create_meta_recipe, name="create-meta-recipe"),
]