Add API: URLs, token auth, what-can-i-cook endpoint, log-cook with pantry deduction, browsable API
This commit is contained in:
@@ -38,9 +38,21 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
|
'rest_framework.authtoken',
|
||||||
'kitchen',
|
'kitchen',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Django REST Framework
|
||||||
|
REST_FRAMEWORK = {
|
||||||
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||||
|
'rest_framework.authentication.TokenAuthentication',
|
||||||
|
'rest_framework.authentication.SessionAuthentication', # for admin/browsable API
|
||||||
|
],
|
||||||
|
'DEFAULT_PERMISSION_CLASSES': [
|
||||||
|
'rest_framework.permissions.IsAuthenticated',
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'django.middleware.security.SecurityMiddleware',
|
'django.middleware.security.SecurityMiddleware',
|
||||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||||
|
|||||||
@@ -15,8 +15,10 @@ Including another URLconf
|
|||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
path('api/', include('kitchen.urls')),
|
||||||
|
path('api-auth/', include('rest_framework.urls')), # browsable API login
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
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 = [
|
||||||
|
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"),
|
||||||
|
]
|
||||||
+6
-2
@@ -205,8 +205,12 @@ def what_can_i_cook(request):
|
|||||||
warnings = get_pantry_warnings(base.ingredient_id)
|
warnings = get_pantry_warnings(base.ingredient_id)
|
||||||
|
|
||||||
if available < needed:
|
if available < needed:
|
||||||
if base.ingredient.is_staple_ingredient:
|
# Check if this ingredient is tracked as a staple in the pantry
|
||||||
# Staples like oil/salt — assume always available even if tracking says 0
|
is_staple = PantryItem.objects.filter(
|
||||||
|
ingredient=base.ingredient, is_staple=True
|
||||||
|
).exists()
|
||||||
|
if is_staple:
|
||||||
|
# Staples like oil/salt — assume always available
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
recipe_result["base_missing"].append({
|
recipe_result["base_missing"].append({
|
||||||
|
|||||||
Reference in New Issue
Block a user