backedn
This commit is contained in:
@@ -168,6 +168,98 @@ class IntegrationViewSet(SiteSectorModelViewSet):
|
||||
|
||||
return success_response(status_data, request=request)
|
||||
|
||||
@action(detail=True, methods=['get'], url_path='content-types')
|
||||
def content_types_summary(self, request, pk=None):
|
||||
"""
|
||||
Get content types summary with counts from synced data.
|
||||
|
||||
GET /api/v1/integration/integrations/{id}/content-types/
|
||||
|
||||
Returns:
|
||||
{
|
||||
"success": true,
|
||||
"data": {
|
||||
"post_types": {
|
||||
"post": {"label": "Posts", "count": 123, "synced_count": 50},
|
||||
"page": {"label": "Pages", "count": 12, "synced_count": 12},
|
||||
"product": {"label": "Products", "count": 456, "synced_count": 200}
|
||||
},
|
||||
"taxonomies": {
|
||||
"category": {"label": "Categories", "count": 25, "synced_count": 25},
|
||||
"post_tag": {"label": "Tags", "count": 102, "synced_count": 80},
|
||||
"product_cat": {"label": "Product Categories", "count": 15, "synced_count": 15}
|
||||
},
|
||||
"last_structure_fetch": "2025-11-22T10:00:00Z"
|
||||
}
|
||||
}
|
||||
"""
|
||||
integration = self.get_object()
|
||||
site = integration.site
|
||||
|
||||
# Get config from integration
|
||||
config = integration.config_json or {}
|
||||
content_types = config.get('content_types', {})
|
||||
|
||||
# Get synced counts from Content and ContentTaxonomy models
|
||||
from igny8_core.business.content.models import Content, ContentTaxonomy
|
||||
|
||||
# Build response with synced counts
|
||||
post_types_data = {}
|
||||
for wp_type, type_config in content_types.get('post_types', {}).items():
|
||||
# Map WP type to entity_type
|
||||
entity_type_map = {
|
||||
'post': 'post',
|
||||
'page': 'page',
|
||||
'product': 'product',
|
||||
'service': 'service',
|
||||
}
|
||||
entity_type = entity_type_map.get(wp_type, 'post')
|
||||
|
||||
# Count synced content
|
||||
synced_count = Content.objects.filter(
|
||||
site=site,
|
||||
entity_type=entity_type,
|
||||
external_type=wp_type,
|
||||
sync_status__in=['imported', 'synced']
|
||||
).count()
|
||||
|
||||
post_types_data[wp_type] = {
|
||||
'label': type_config.get('label', wp_type.title()),
|
||||
'count': type_config.get('count', 0),
|
||||
'synced_count': synced_count,
|
||||
'enabled': type_config.get('enabled', False),
|
||||
'fetch_limit': type_config.get('fetch_limit', 100),
|
||||
'last_synced': type_config.get('last_synced'),
|
||||
}
|
||||
|
||||
taxonomies_data = {}
|
||||
for wp_tax, tax_config in content_types.get('taxonomies', {}).items():
|
||||
# Count synced taxonomies
|
||||
synced_count = ContentTaxonomy.objects.filter(
|
||||
site=site,
|
||||
external_taxonomy=wp_tax,
|
||||
sync_status__in=['imported', 'synced']
|
||||
).count()
|
||||
|
||||
taxonomies_data[wp_tax] = {
|
||||
'label': tax_config.get('label', wp_tax.title()),
|
||||
'count': tax_config.get('count', 0),
|
||||
'synced_count': synced_count,
|
||||
'enabled': tax_config.get('enabled', False),
|
||||
'fetch_limit': tax_config.get('fetch_limit', 100),
|
||||
'last_synced': tax_config.get('last_synced'),
|
||||
}
|
||||
|
||||
summary = {
|
||||
'post_types': post_types_data,
|
||||
'taxonomies': taxonomies_data,
|
||||
'last_structure_fetch': config.get('last_structure_fetch'),
|
||||
'plugin_connection_enabled': config.get('plugin_connection_enabled', True),
|
||||
'two_way_sync_enabled': config.get('two_way_sync_enabled', True),
|
||||
}
|
||||
|
||||
return success_response(summary, request=request)
|
||||
|
||||
# Stage 4: Site-level sync endpoints
|
||||
|
||||
@action(detail=False, methods=['get'], url_path='sites/(?P<site_id>[^/.]+)/sync/status')
|
||||
|
||||
Reference in New Issue
Block a user