Skip to content

Commit

Permalink
Merge pull request #18 from rkshaon/rkshaon
Browse files Browse the repository at this point in the history
updt: backend - get single book details api
  • Loading branch information
rkshaon authored Sep 7, 2024
2 parents f1be01a + aad6c5e commit 5f6b30a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/book_api/urls/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

urlpatterns = [
path('', v1.BookView.as_view()),
path('<int:pk>/', v1.BookView.as_view()),
path('<int:book_code>/', v1.BookView.as_view()),
]
6 changes: 3 additions & 3 deletions backend/book_api/views/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class BookView(APIView):
permission_classes = [AllowAny]

def get(self, request, *args, **kwargs):
pk = kwargs.get('pk', None)
book_code = kwargs.get('book_code', None)

if pk:
if book_code:
try:
book = Book.objects.get(pk=pk, is_deleted=False)
book = Book.objects.get(book_code=book_code, is_deleted=False)
except Book.DoesNotExist:
raise NotFound(detail="Book not found.")

Expand Down

0 comments on commit 5f6b30a

Please sign in to comment.