from rest_framework.views import APIView from rest_framework.response import Response from rest_framework import status from ..models import HadisSect, BookReference, Transmitters ,Hadis ,HadisCategory from ..docs import hadis_info_swagger from apps.bookmark.models import Bookmark class HadisInfoView(APIView): """ API view to get hadis statistics """ @hadis_info_swagger def get(self, request, *args, **kwargs): hadis_count = Hadis.objects.all().count() category_count = HadisCategory.objects.all().count() reference_count = BookReference.objects.count() bookmark_count = Bookmark.objects.filter( service=Bookmark.ServiceChoices.HADITH, status=True ).count() narrator_count = Transmitters.objects.count() data = { 'hadis_count':hadis_count, 'category_count': category_count, 'reference_count': reference_count, 'bookmark_count': bookmark_count, 'narrator_count': narrator_count } return Response(data, status=status.HTTP_200_OK)