diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index db6ba82c..523a0ce1 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -8,5 +8,23 @@ jdbc:sqlite:$PROJECT_DIR$/db.sqlite3 $ProjectFileDir$ + + sqlite.xerial + true + true + $PROJECT_DIR$/helloworld/settings.py + org.sqlite.JDBC + jdbc:sqlite:C:\Users\Shreyas\Documents\Scalar\Django\demoDjangoProject\db.sqlite3 + $ProjectFileDir$ + + + sqlite.xerial + true + true + $PROJECT_DIR$/helloworld/settings.py + org.sqlite.JDBC + jdbc:sqlite:C:\Users\Shreyas\Documents\Scalar\Django\demoDjangoProject\db.sqlite3 + $ProjectFileDir$ + \ No newline at end of file diff --git a/.idea/helloworld.iml b/.idea/helloworld.iml index b1023c6e..1304465d 100644 --- a/.idea/helloworld.iml +++ b/.idea/helloworld.iml @@ -14,7 +14,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index 812ab5a6..7b668813 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 index 69bfcf1f..0b89e35c 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/env/pyvenv.cfg b/env/pyvenv.cfg index 89c3f403..b383617c 100644 --- a/env/pyvenv.cfg +++ b/env/pyvenv.cfg @@ -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 diff --git a/helloworld/settings.py b/helloworld/settings.py index 4ada6bff..2470c846 100644 --- a/helloworld/settings.py +++ b/helloworld/settings.py @@ -37,6 +37,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'rest_framework', 'tryHello', 'library' ] diff --git a/library/urls.py b/library/urls.py index b4361e4d..f52cf1d3 100644 --- a/library/urls.py +++ b/library/urls.py @@ -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//', views.get_book_by_id, name='getBookByID'), + path('author//', views.get_author_by_id, name='getAuthorByID'), ] \ No newline at end of file diff --git a/library/views.py b/library/views.py index 052affad..ea26628b 100644 --- a/library/views.py +++ b/library/views.py @@ -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. @@ -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.. \ No newline at end of file +@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) \ No newline at end of file