You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.4 KiB
69 lines
2.4 KiB
from rest_framework import generics
|
|
from ..models import BookReference
|
|
from ..serializers.reference_v2 import BookReferenceV2DetailSerializer
|
|
from drf_yasg.utils import swagger_auto_schema
|
|
|
|
class BookReferenceV2DetailView(generics.RetrieveAPIView):
|
|
"""
|
|
V2 View to retrieve Book Reference details, formatted with tabs
|
|
(Information, Excerpts, Volumes) and supporting multiple editions per book.
|
|
"""
|
|
queryset = BookReference.objects.all()
|
|
serializer_class = BookReferenceV2DetailSerializer
|
|
lookup_field = 'slug'
|
|
|
|
def get_queryset(self):
|
|
return (
|
|
BookReference.objects
|
|
.filter(slug=self.kwargs.get('slug'))
|
|
.prefetch_related(
|
|
'authors',
|
|
'editions__volumes',
|
|
'volumes',
|
|
'hadis_references__hadis'
|
|
)
|
|
)
|
|
|
|
@swagger_auto_schema(
|
|
operation_summary="Get V2 Book Reference Detail",
|
|
operation_description="Retrieve structured metadata for a book reference, including its editions, related hadiths (excerpts), and volumes.",
|
|
tags=['Dobodbi - Hadis (V2)'],
|
|
responses={200: BookReferenceV2DetailSerializer}
|
|
)
|
|
def get(self, request, *args, **kwargs):
|
|
return super().get(request, *args, **kwargs)
|
|
|
|
from utils.pagination import NoPagination
|
|
from ..serializers.reference_v2 import BookReferenceV2SyncSerializer
|
|
|
|
class BookReferenceV2SyncView(generics.ListAPIView):
|
|
"""
|
|
API view to sync all V2 book reference data for offline mode
|
|
Returns all book references with editions, volumes, and related hadises
|
|
"""
|
|
serializer_class = BookReferenceV2SyncSerializer
|
|
pagination_class = NoPagination
|
|
|
|
@swagger_auto_schema(
|
|
operation_summary="Sync V2 Book References",
|
|
operation_description="Returns all book references for offline sync.",
|
|
tags=['Dobodbi - Hadis (V2)'],
|
|
responses={200: BookReferenceV2SyncSerializer(many=True)}
|
|
)
|
|
def get(self, request, *args, **kwargs):
|
|
return super().get(request, *args, **kwargs)
|
|
|
|
def get_queryset(self):
|
|
return (
|
|
BookReference.objects
|
|
.select_related()
|
|
.prefetch_related(
|
|
'authors',
|
|
'attributes',
|
|
'images',
|
|
'editions__volumes',
|
|
'volumes',
|
|
'hadis_references__hadis'
|
|
)
|
|
.order_by('id')
|
|
)
|