Fix suppliers

This commit is contained in:
Urtzi Alfaro
2025-12-29 14:48:24 +01:00
parent 2e7e1f5557
commit adef7971a0
3 changed files with 10 additions and 10 deletions

View File

@@ -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"]) @router.api_route("/{tenant_id}/ingredients/count", methods=["GET"])
async def proxy_tenant_ingredients_count(request: Request, tenant_id: str = Path(...)): async def proxy_tenant_ingredients_count(request: Request, tenant_id: str = Path(...)):
"""Proxy tenant ingredient count requests to inventory service""" """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) 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"]) @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"]) @router.api_route("/{tenant_id}/suppliers/count", methods=["GET"])
async def proxy_tenant_suppliers_count(request: Request, tenant_id: str = Path(...)): async def proxy_tenant_suppliers_count(request: Request, tenant_id: str = Path(...)):
"""Proxy tenant supplier count requests to suppliers service""" """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) 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"]) @router.api_route("/{tenant_id}/suppliers/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])

View File

@@ -4,7 +4,7 @@ Supplier Business Operations API endpoints (BUSINESS)
Handles approvals, status updates, active/top suppliers, and delivery/PO operations 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 typing import List, Optional, Dict, Any
from uuid import UUID from uuid import UUID
from datetime import datetime from datetime import datetime
@@ -172,20 +172,16 @@ async def get_suppliers_by_type(
@router.get(route_builder.build_operations_route("count")) @router.get(route_builder.build_operations_route("count"))
async def get_supplier_count( async def get_supplier_count(
tenant_id: str = Path(..., description="Tenant ID"), tenant_id: str = Path(..., description="Tenant ID"),
x_internal_request: str = Header(None),
current_user: Dict[str, Any] = Depends(get_current_user_dep), current_user: Dict[str, Any] = Depends(get_current_user_dep),
db: Session = Depends(get_db) db: Session = Depends(get_db)
): ):
""" """
Get total count of suppliers for a tenant 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: try:
service = SupplierService(db) 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) count = len(suppliers)
return {"count": count} return {"count": count}

View File

@@ -280,7 +280,7 @@ class SupplierService:
async def get_active_suppliers(self, tenant_id: UUID) -> List[Supplier]: async def get_active_suppliers(self, tenant_id: UUID) -> List[Supplier]:
"""Get all active suppliers""" """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( async def get_suppliers_by_type(
self, self,