diff --git a/gateway/app/routes/tenant.py b/gateway/app/routes/tenant.py index d39c40e2..d549bcdd 100644 --- a/gateway/app/routes/tenant.py +++ b/gateway/app/routes/tenant.py @@ -399,7 +399,9 @@ async def proxy_tenant_ingredients_base(request: Request, tenant_id: str = Path( @router.api_route("/{tenant_id}/ingredients/count", methods=["GET"]) async def proxy_tenant_ingredients_count(request: Request, tenant_id: str = Path(...)): """Proxy tenant ingredient count requests to inventory service""" - target_path = f"/api/v1/tenants/{tenant_id}/ingredients/count" + # Inventory service uses RouteBuilder('inventory').build_base_route("ingredients/count") + # which generates /api/v1/tenants/{tenant_id}/inventory/ingredients/count + target_path = f"/api/v1/tenants/{tenant_id}/inventory/ingredients/count" return await _proxy_to_inventory_service(request, target_path, tenant_id=tenant_id) @router.api_route("/{tenant_id}/ingredients/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"]) @@ -513,7 +515,9 @@ async def proxy_tenant_suppliers_base(request: Request, tenant_id: str = Path(.. @router.api_route("/{tenant_id}/suppliers/count", methods=["GET"]) async def proxy_tenant_suppliers_count(request: Request, tenant_id: str = Path(...)): """Proxy tenant supplier count requests to suppliers service""" - target_path = f"/api/v1/tenants/{tenant_id}/suppliers/count" + # Suppliers service uses RouteBuilder('suppliers').build_operations_route("count") + # which generates /api/v1/tenants/{tenant_id}/suppliers/operations/count + target_path = f"/api/v1/tenants/{tenant_id}/suppliers/operations/count" return await _proxy_to_suppliers_service(request, target_path, tenant_id=tenant_id) @router.api_route("/{tenant_id}/suppliers/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"]) diff --git a/services/suppliers/app/api/supplier_operations.py b/services/suppliers/app/api/supplier_operations.py index c2490cdf..41024931 100644 --- a/services/suppliers/app/api/supplier_operations.py +++ b/services/suppliers/app/api/supplier_operations.py @@ -4,7 +4,7 @@ Supplier Business Operations API endpoints (BUSINESS) Handles approvals, status updates, active/top suppliers, and delivery/PO operations """ -from fastapi import APIRouter, Depends, HTTPException, Query, Path, Header +from fastapi import APIRouter, Depends, HTTPException, Query, Path from typing import List, Optional, Dict, Any from uuid import UUID from datetime import datetime @@ -172,20 +172,16 @@ async def get_suppliers_by_type( @router.get(route_builder.build_operations_route("count")) async def get_supplier_count( tenant_id: str = Path(..., description="Tenant ID"), - x_internal_request: str = Header(None), current_user: Dict[str, Any] = Depends(get_current_user_dep), db: Session = Depends(get_db) ): """ Get total count of suppliers for a tenant - Internal endpoint for subscription usage tracking + Used for subscription usage tracking and dashboard metrics """ - if x_internal_request != "true": - raise HTTPException(status_code=403, detail="Internal endpoint only") - try: service = SupplierService(db) - suppliers = await service.get_suppliers(tenant_id=current_user["tenant_id"]) + suppliers = await service.get_active_suppliers(tenant_id=UUID(current_user["tenant_id"])) count = len(suppliers) return {"count": count} diff --git a/services/suppliers/app/services/supplier_service.py b/services/suppliers/app/services/supplier_service.py index 75ce1f34..2c07f007 100644 --- a/services/suppliers/app/services/supplier_service.py +++ b/services/suppliers/app/services/supplier_service.py @@ -280,7 +280,7 @@ class SupplierService: async def get_active_suppliers(self, tenant_id: UUID) -> List[Supplier]: """Get all active suppliers""" - return self.repository.get_active_suppliers(tenant_id) + return await self.repository.get_active_suppliers(tenant_id) async def get_suppliers_by_type( self,