Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iameraj committed Feb 4, 2024
1 parent b465911 commit 70cb30c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/recipe/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ class RecipeSerializer(serializers.ModelSerializer):

class Meta:
model = Recipe
fields = ["id", "title", "time_minutes", "price", "link"]
fields = ["id", "title", "time_minutes", "price" ]
read_only_fields = ["id"]
14 changes: 7 additions & 7 deletions app/recipe/test/testRecipeAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rest_framework import status
from rest_framework.authtoken.serializers import serializers
from rest_framework.test import APIClient
from core.models import Recipe
from core.models import Recipe, User
from recipe.serializers import RecipeSerializer

RECIPE_URL = reverse("recipe:recipe-list")
Expand All @@ -22,7 +22,6 @@ def create_recipe(user, **params):
"time_minutes": 23,
"price": Decimal("4.64"),
"description": "This is a sample recipe description",
"link": "https://example.com",
}

defaults.update(params)
Expand Down Expand Up @@ -52,12 +51,13 @@ class PrivateRecipeAPITests(TestCase):
"""

def setUp(self):
self.client = APIClient()
self.user = get_user_model().objects.create_user(
"[email protected]",
"test!password"
self.user = User.objects.create_user(
email="[email protected]",
password="testpassword",
name="TestUserIam",
)
self.client.force_authenticate()
self.client = APIClient()
self.client.force_authenticate(user=self.user)

def test_retrieve_recipes(self):
"""Tests retrieving recipes"""
Expand Down
14 changes: 14 additions & 0 deletions app/recipe/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Urls mapping for recipe app"""

from django.urls import path, include
from rest_framework.routers import DefaultRouter
from recipe import views

router = DefaultRouter()
router.register("recipes", views.RecipeViewSet)

app_name = "recipe"

urlpatterns = [
path("", include(router.urls)),
]
15 changes: 13 additions & 2 deletions app/recipe/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
"""
Views for recipe API endpoint
Views for recipe API endpoints
"""

from rest_framework import viewsets
from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import IsAuthenticated

from core.models import Recipe
from serializers import RecipeSerializer
from recipe.serializers import RecipeSerializer

class RecipeViewSet(viewsets.ModelViewSet):
"""Views to manage Recipe API endpoints"""

serializer_class = RecipeSerializer
queryset = Recipe.objects.all()
authentication_classes = [TokenAuthentication]
permission_classes = [IsAuthenticated]

def get_queryset(self):
"""Retrieve recipe for authenticated user"""

return self.queryset.filter(user=self.request.user).order_by("-id")

0 comments on commit 70cb30c

Please sign in to comment.