Browse Source

new swagger docs for hadis

master
Mohsen Taba 5 months ago
parent
commit
3b08a3804a
  1. 78
      apps/hadis/docs.py
  2. 5
      apps/hadis/views/hadis.py
  3. 2
      apps/hadis/views/info.py

78
apps/hadis/docs.py

@ -347,6 +347,84 @@ hadis_detail_swagger = swagger_auto_schema(
) )
# Swagger documentation for HadisCollectionListView
hadis_collections_swagger = swagger_auto_schema(
operation_description="Get list of all active hadis collections for browsing and categorization",
operation_summary="List Hadis Collections",
operation_id="getHadisCollections",
tags=['Hadis'],
responses={
status.HTTP_200_OK: openapi.Response(
description="List of hadis collections",
examples={
"application/json": [
{
"id": 1,
"title": "Collection Title",
"description": "Collection description",
"order": 1,
"status": True
}
]
}
),
status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response(
description="Internal server error"
)
}
)
# Swagger documentation for HadisInfoView
hadis_info_swagger = swagger_auto_schema(
operation_description="Get statistical information about hadis database including counts of categories, references, bookmarks, and narrators",
operation_summary="Get Hadis Statistics",
operation_id="getHadisInfo",
tags=['Hadis'],
responses={
status.HTTP_200_OK: openapi.Response(
description="Hadis database statistics",
examples={
"application/json": {
"category_count": 25,
"reference_count": 150,
"bookmark_count": 75,
"narrator_count": 200
}
}
),
status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response(
description="Internal server error"
)
}
)
# Swagger documentation for HadisSyncView
hadis_sync_swagger = swagger_auto_schema(
operation_description="Get complete hadis data for offline synchronization including all categories, hadis, and related information",
operation_summary="Sync Hadis Data",
operation_id="syncHadisData",
tags=['Hadis'],
responses={
status.HTTP_200_OK: openapi.Response(
description="Complete hadis data for synchronization",
examples={
"application/json": {
"categories": [],
"hadis": [],
"references": [],
"transmitters": []
}
}
),
status.HTTP_500_INTERNAL_SERVER_ERROR: openapi.Response(
description="Internal server error"
)
}
)
# Swagger documentation for TransmitterView # Swagger documentation for TransmitterView
transmitter_list_swagger = swagger_auto_schema( transmitter_list_swagger = swagger_auto_schema(
operation_description="Get list of transmitters (narrators) with optional filtering by status, madhhab, and generation", operation_description="Get list of transmitters (narrators) with optional filtering by status, madhhab, and generation",

5
apps/hadis/views/hadis.py

@ -5,7 +5,7 @@ from rest_framework.response import Response
from ..models import HadisCategory, Hadis, HadisCollection from ..models import HadisCategory, Hadis, HadisCollection
from ..serializers import HadisListSerializer, HadisDetailSerializer, HadisCollectionListSerializer, HadisSyncSerializer from ..serializers import HadisListSerializer, HadisDetailSerializer, HadisCollectionListSerializer, HadisSyncSerializer
from ..docs import hadis_list_swagger, hadis_detail_swagger
from ..docs import hadis_list_swagger, hadis_detail_swagger, hadis_collections_swagger, hadis_sync_swagger
class HadisCollectionListView(ListAPIView): class HadisCollectionListView(ListAPIView):
@ -16,6 +16,7 @@ class HadisCollectionListView(ListAPIView):
serializer_class = HadisCollectionListSerializer serializer_class = HadisCollectionListSerializer
pagination_class = NoPagination pagination_class = NoPagination
@hadis_collections_swagger
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs) return self.list(request, *args, **kwargs)
@ -27,6 +28,8 @@ class HadisSyncView(ListAPIView):
serializer_class = HadisSyncSerializer serializer_class = HadisSyncSerializer
pagination_class = NoPagination pagination_class = NoPagination
@hadis_sync_swagger
def get_queryset(self): def get_queryset(self):
return Hadis.objects.filter(status=True).select_related( return Hadis.objects.filter(status=True).select_related(
'category', 'hadis_status' 'category', 'hadis_status'

2
apps/hadis/views/info.py

@ -3,6 +3,7 @@ from rest_framework.response import Response
from rest_framework import status from rest_framework import status
from ..models import HadisSect, BookReference, Transmitters from ..models import HadisSect, BookReference, Transmitters
from ..docs import hadis_info_swagger
from apps.bookmark.models import Bookmark from apps.bookmark.models import Bookmark
@ -11,6 +12,7 @@ class HadisInfoView(APIView):
API view to get hadis statistics API view to get hadis statistics
""" """
@hadis_info_swagger
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
category_count = HadisSect.objects.filter(is_active=True).count() category_count = HadisSect.objects.filter(is_active=True).count()
reference_count = BookReference.objects.count() reference_count = BookReference.objects.count()

Loading…
Cancel
Save