Enhance API structure and documentation: Added new tags for Account, Integration, Automation, Linker, Optimizer, and Publisher; updated billing endpoints for admin and customer; improved API reference documentation; fixed endpoint paths in frontend services.

This commit is contained in:
IGNY8 VPS (Salman)
2025-12-07 01:13:38 +00:00
parent dc9dba2c9e
commit 7a2b424237
15 changed files with 314 additions and 24 deletions

View File

@@ -1,6 +1,10 @@
from django.urls import path
from rest_framework.routers import DefaultRouter
from .views import AdminBillingViewSet
from igny8_core.business.billing.views import (
AdminBillingViewSet as BillingAdminViewSet,
)
router = DefaultRouter()
@@ -9,6 +13,12 @@ urlpatterns = [
path('users/', AdminBillingViewSet.as_view({'get': 'list_users'}), name='admin-users-list'),
path('users/<int:user_id>/adjust-credits/', AdminBillingViewSet.as_view({'post': 'adjust_credits'}), name='admin-adjust-credits'),
path('credit-costs/', AdminBillingViewSet.as_view({'get': 'list_credit_costs', 'post': 'update_credit_costs'}), name='admin-credit-costs'),
# Unified admin billing endpoints (alias legacy /billing/admin/* under /admin/billing/*)
path('billing/invoices/', BillingAdminViewSet.as_view({'get': 'invoices'}), name='admin-billing-invoices'),
path('billing/payments/', BillingAdminViewSet.as_view({'get': 'payments'}), name='admin-billing-payments'),
path('billing/pending_payments/', BillingAdminViewSet.as_view({'get': 'pending_payments'}), name='admin-billing-pending-payments'),
path('billing/<int:pk>/approve_payment/', BillingAdminViewSet.as_view({'post': 'approve_payment'}), name='admin-billing-approve-payment'),
path('billing/<int:pk>/reject_payment/', BillingAdminViewSet.as_view({'post': 'reject_payment'}), name='admin-billing-reject-payment'),
]
urlpatterns += router.urls

View File

@@ -20,6 +20,9 @@ urlpatterns = [
path('', include(router.urls)),
# User-facing billing overview
path('account_balance/', BillingOverviewViewSet.as_view({'get': 'account_balance'}), name='account-balance'),
# Canonical credit balance endpoint
path('credits/balance/', CreditBalanceViewSet.as_view({'get': 'list'}), name='credit-balance-canonical'),
# Explicit list endpoints
path('transactions/', CreditTransactionViewSet.as_view({'get': 'list'}), name='transactions'),
path('usage/', CreditUsageViewSet.as_view({'get': 'list'}), name='usage'),
# Admin billing endpoints

View File

@@ -26,7 +26,7 @@ from .exceptions import InsufficientCreditsError
@extend_schema_view(
list=extend_schema(tags=['Billing']),
list=extend_schema(tags=['Billing'], summary='Get credit balance'),
)
class CreditBalanceViewSet(viewsets.ViewSet):
"""
@@ -38,8 +38,7 @@ class CreditBalanceViewSet(viewsets.ViewSet):
throttle_scope = 'billing'
throttle_classes = [DebugScopedRateThrottle]
@action(detail=False, methods=['get'])
def balance(self, request):
def list(self, request):
"""Get current credit balance and usage"""
account = getattr(request, 'account', None)
if not account:
@@ -125,6 +124,7 @@ class CreditUsageViewSet(AccountModelViewSet):
return queryset.order_by('-created_at')
@extend_schema(tags=['Billing'], summary='Get usage summary')
@action(detail=False, methods=['get'])
def summary(self, request):
"""Get usage summary for date range"""
@@ -214,6 +214,7 @@ class CreditUsageViewSet(AccountModelViewSet):
serializer = UsageSummarySerializer(data)
return success_response(data=serializer.data, request=request)
@extend_schema(tags=['Billing'], summary='Get usage limits')
@action(detail=False, methods=['get'], url_path='limits', url_name='limits')
def limits(self, request):
"""
@@ -434,6 +435,13 @@ class BillingOverviewViewSet(viewsets.ViewSet):
return Response(data)
@extend_schema_view(
stats=extend_schema(tags=['Admin Billing'], summary='Admin billing stats'),
list_users=extend_schema(tags=['Admin Billing'], summary='List users with credit info'),
adjust_credits=extend_schema(tags=['Admin Billing'], summary='Adjust user credits'),
list_credit_costs=extend_schema(tags=['Admin Billing'], summary='List credit cost configurations'),
update_credit_costs=extend_schema(tags=['Admin Billing'], summary='Update credit cost configurations'),
)
class AdminBillingViewSet(viewsets.ViewSet):
"""Admin-only billing management API"""
permission_classes = [IsAuthenticatedAndActive, permissions.IsAdminUser]

View File

@@ -6,6 +6,7 @@ from rest_framework import status
from rest_framework.decorators import action
from rest_framework.response import Response
from django.utils import timezone
from drf_spectacular.utils import extend_schema, extend_schema_view
from igny8_core.api.base import SiteSectorModelViewSet
from igny8_core.api.permissions import IsAuthenticatedAndActive, IsEditorOrAbove
@@ -21,6 +22,14 @@ import logging
logger = logging.getLogger(__name__)
@extend_schema_view(
list=extend_schema(tags=['Integration']),
create=extend_schema(tags=['Integration']),
retrieve=extend_schema(tags=['Integration']),
update=extend_schema(tags=['Integration']),
partial_update=extend_schema(tags=['Integration']),
destroy=extend_schema(tags=['Integration']),
)
class IntegrationViewSet(SiteSectorModelViewSet):
"""
ViewSet for SiteIntegration model.
@@ -88,6 +97,7 @@ class IntegrationViewSet(SiteSectorModelViewSet):
return SiteIntegrationSerializer
@extend_schema(tags=['Integration'])
@action(detail=True, methods=['post'])
def test_connection(self, request, pk=None):
"""
@@ -118,6 +128,7 @@ class IntegrationViewSet(SiteSectorModelViewSet):
def allow_request(self, request, view):
return True
@extend_schema(tags=['Integration'])
@action(detail=False, methods=['post'], url_path='test-connection',
permission_classes=[AllowAny], throttle_classes=[NoThrottle])
def test_connection_collection(self, request):
@@ -221,6 +232,7 @@ class IntegrationViewSet(SiteSectorModelViewSet):
logger.info(f"[IntegrationViewSet] Deleted integration {integration.id} due to failed connection test")
return error_response(result.get('message', 'Connection test failed'), None, status.HTTP_400_BAD_REQUEST, request)
@extend_schema(tags=['Integration'])
@action(detail=True, methods=['post'])
def sync(self, request, pk=None):
"""
@@ -252,6 +264,7 @@ class IntegrationViewSet(SiteSectorModelViewSet):
response_status = status.HTTP_200_OK if result.get('success') else status.HTTP_400_BAD_REQUEST
return success_response(result, request=request, status_code=response_status)
@extend_schema(tags=['Integration'])
@action(detail=True, methods=['get'])
def sync_status(self, request, pk=None):
"""

View File

@@ -11,6 +11,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from django.views.decorators.csrf import csrf_exempt
from django.utils.decorators import method_decorator
from drf_spectacular.utils import extend_schema, extend_schema_view
from igny8_core.api.base import SiteSectorModelViewSet
from igny8_core.api.permissions import IsAuthenticatedAndActive, IsEditorOrAbove
@@ -20,6 +21,14 @@ from igny8_core.business.publishing.models import PublishingRecord, DeploymentRe
from igny8_core.business.publishing.services.publisher_service import PublisherService
@extend_schema_view(
list=extend_schema(tags=['Publisher']),
create=extend_schema(tags=['Publisher']),
retrieve=extend_schema(tags=['Publisher']),
update=extend_schema(tags=['Publisher']),
partial_update=extend_schema(tags=['Publisher']),
destroy=extend_schema(tags=['Publisher']),
)
class PublishingRecordViewSet(SiteSectorModelViewSet):
"""
ViewSet for PublishingRecord model.
@@ -41,6 +50,14 @@ class PublishingRecordViewSet(SiteSectorModelViewSet):
return PublishingRecordSerializer
@extend_schema_view(
list=extend_schema(tags=['Publisher']),
create=extend_schema(tags=['Publisher']),
retrieve=extend_schema(tags=['Publisher']),
update=extend_schema(tags=['Publisher']),
partial_update=extend_schema(tags=['Publisher']),
destroy=extend_schema(tags=['Publisher']),
)
class DeploymentRecordViewSet(SiteSectorModelViewSet):
"""
ViewSet for DeploymentRecord model.
@@ -63,6 +80,7 @@ class DeploymentRecordViewSet(SiteSectorModelViewSet):
return DeploymentRecordSerializer
@extend_schema_view()
class PublisherViewSet(viewsets.ViewSet):
"""
Publisher actions for publishing content.
@@ -76,6 +94,7 @@ class PublisherViewSet(viewsets.ViewSet):
super().__init__(**kwargs)
self.publisher_service = PublisherService()
@extend_schema(tags=['Publisher'])
@action(detail=False, methods=['post'], url_path='publish')
def publish(self, request):
"""

View File

@@ -1580,12 +1580,12 @@ class ContentViewSet(SiteSectorModelViewSet):
@extend_schema_view(
list=extend_schema(tags=['Writer - Taxonomies']),
create=extend_schema(tags=['Writer - Taxonomies']),
retrieve=extend_schema(tags=['Writer - Taxonomies']),
update=extend_schema(tags=['Writer - Taxonomies']),
partial_update=extend_schema(tags=['Writer - Taxonomies']),
destroy=extend_schema(tags=['Writer - Taxonomies']),
list=extend_schema(tags=['Writer']),
create=extend_schema(tags=['Writer']),
retrieve=extend_schema(tags=['Writer']),
update=extend_schema(tags=['Writer']),
partial_update=extend_schema(tags=['Writer']),
destroy=extend_schema(tags=['Writer']),
)
class ContentTaxonomyViewSet(SiteSectorModelViewSet):
"""