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
18 changes: 18 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/helloworld.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified db.sqlite3
Binary file not shown.
8 changes: 4 additions & 4 deletions env/pyvenv.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
home = /opt/homebrew/opt/python@3.12/bin
home = C:\Users\Shreyas\AppData\Local\Programs\Python\Python312
include-system-site-packages = false
version = 3.12.4
executable = /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/bin/python3.12
command = /opt/homebrew/opt/python@3.12/bin/python3.12 -m venv /Users/karan.bhatia/Desktop/personal/helloworld/env
version = 3.12.6
executable = C:\Users\Shreyas\AppData\Local\Programs\Python\Python312\python.exe
command = C:\Users\Shreyas\AppData\Local\Programs\Python\Python312\python.exe -m venv C:\Users\Shreyas\Documents\Scalar\Django\demoDjangoProject\env
1 change: 1 addition & 0 deletions helloworld/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'tryHello',
'library'
]
Expand Down
4 changes: 3 additions & 1 deletion library/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from library import views

urlpatterns = [
path('createbook/', views.create_book, name='createbook'),
path('createBook/', views.create_book, name='createbook'),
path('createAuthor/', views.create_author, name='createauthor'),
path('book/<int:id>/', views.get_book_by_id, name='getBookByID'),
path('author/<int:id>/', views.get_author_by_id, name='getAuthorByID'),
]
25 changes: 23 additions & 2 deletions library/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response

from .models import Book,Author
from library.serializer import BookSerializer, AuthorSerializer
from rest_framework.exceptions import NotFound


# Create your views here.
Expand Down Expand Up @@ -32,4 +33,24 @@ def create_author(request):


# TODO: GET BOOK BY ID and return json response..
# TODO: GET AUTHOR BY ID and return json response..
@api_view(['GET'])
def get_book_by_id(request,id):
try:
instance = Book.objects.get(pk=id)
except Book.DoesNotExist:
raise NotFound(f"No record found with ID {id}")

serializer = BookSerializer(instance)
return Response(serializer.data, status=status.HTTP_200_OK)


# TODO: GET AUTHOR BY ID and return json response..
@api_view(['GET'])
def get_author_by_id(request,id):
try:
instance = Author.objects.get(pk=id)
except Author.DoesNotExist:
raise NotFound(f"No record found with ID {id}")

serializer = AuthorSerializer(instance)
return Response(serializer.data, status=status.HTTP_200_OK)