Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions library/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
urlpatterns = [
path('createbook/', views.create_book, name='createbook'),
path('createAuthor/', views.create_author, name='createauthor'),
path('getBook/', views.get_book, name='getbook'),
path('getAuthor/', views.get_author, name='getauthor'),
]
16 changes: 15 additions & 1 deletion library/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from rest_framework.decorators import api_view
from rest_framework.response import Response

from library.models import Author, Book
from library.serializer import BookSerializer, AuthorSerializer


Expand Down Expand Up @@ -31,4 +32,17 @@ def create_author(request):
return Response(author_serializer.errors, status=status.HTTP_400_BAD_REQUEST)

# TODO: GET BOOK BY ID and return json response..
# TODO: GET AUTHOR BY ID and return json response..
#127.0.0.1:8000/api/getBook?id=1
@api_view(['GET'])
def get_book(request):
index = request.query_params.get('id')
book_serializer = BookSerializer(Book.objects.get(pk=index))
return Response(book_serializer.data, status=status.HTTP_200_OK)

#127.0.0.1:8000/api/getAuthor?id=1
# TODO: GET AUTHOR BY ID and return json response..
@api_view(['GET'])
def get_author(request):
index = request.query_params.get('id')
author_serializer = AuthorSerializer(Author.objects.get(pk=index))
return Response(author_serializer.data, status=status.HTTP_200_OK)