@ -137,18 +137,6 @@ class BookListView(ListAPIView):
# Filter books by these IDs
queryset = queryset . filter ( id__in = bookmarked_ids )
# Filter by downloaded books if requested
is_downloaded = self . request . query_params . get ( ' is_downloaded ' , ' ' ) . lower ( )
if is_downloaded == ' true ' :
# Get all downloaded book IDs for the current user
downloaded_ids = BookDownload . objects . filter (
user = self . request . user ,
status = True
) . values_list ( ' book_id ' , flat = True )
# Filter books by these IDs
queryset = queryset . filter ( id__in = downloaded_ids )
return queryset . order_by ( ' -pin ' , ' -created_at ' )
@ -191,6 +179,59 @@ class MiddleBookCollectionListView(ListAPIView):
) . order_by ( ' order ' )
class DownloadedBooksListView ( ListAPIView ) :
"""
API view to list books that have been downloaded by the current user
"""
serializer_class = BookSerializer
permission_classes = ( IsAuthenticated , )
filter_backends = [ SearchFilter ]
search_fields = [ ' title ' , ' summary ' , ' publisher ' , ' isbn ' ]
@swagger_auto_schema (
operation_id = " list_downloaded_books " ,
operation_description = """
Retrieve a list of books that have been downloaded by the current user .
This endpoint returns a paginated list of books that the authenticated user has downloaded .
The results are not cached to ensure real - time accuracy of the download list .
You can search for downloaded books by title , summary , publisher , or ISBN using the ' search ' query parameter .
""" ,
operation_summary = " List Downloaded Books " ,
tags = [ " Library " ] ,
manual_parameters = [
openapi . Parameter (
' search ' ,
openapi . IN_QUERY ,
description = " Search downloaded books by title, summary, publisher, or ISBN " ,
type = openapi . TYPE_STRING ,
required = False
)
] ,
responses = {
200 : " List of downloaded books with pagination " ,
401 : " Authentication credentials were not provided or are invalid " ,
500 : " Internal server error occurred "
}
)
def get ( self , request , * args , * * kwargs ) :
return super ( ) . get ( request , * args , * * kwargs )
def get_queryset ( self ) :
# Get all downloaded book IDs for the current user
downloaded_ids = BookDownload . objects . filter (
user = self . request . user ,
status = True
) . values_list ( ' book_id ' , flat = True )
# Return books that match these IDs
return Book . objects . filter (
id__in = downloaded_ids ,
status = True
) . order_by ( ' -created_at ' )
class BookDownloadCreateAPIView ( CreateAPIView ) :
"""
API view to create a book download record and increment the book ' s download count