REFACTOR ALL APIs

This commit is contained in:
Urtzi Alfaro
2025-10-06 15:27:01 +02:00
parent dc8221bd2f
commit 38fb98bc27
166 changed files with 18454 additions and 13605 deletions

View File

@@ -28,7 +28,7 @@ class SuppliersServiceClient(BaseServiceClient):
async def get_supplier_by_id(self, tenant_id: str, supplier_id: str) -> Optional[Dict[str, Any]]:
"""Get supplier details by ID"""
try:
result = await self.get(f"suppliers/{supplier_id}", tenant_id=tenant_id)
result = await self.get(f"suppliers/list/{supplier_id}", tenant_id=tenant_id)
if result:
logger.info("Retrieved supplier details from suppliers service",
supplier_id=supplier_id, tenant_id=tenant_id)
@@ -45,7 +45,7 @@ class SuppliersServiceClient(BaseServiceClient):
if is_active is not None:
params["is_active"] = is_active
result = await self.get_paginated("suppliers", tenant_id=tenant_id, params=params)
result = await self.get_paginated("suppliers/list", tenant_id=tenant_id, params=params)
logger.info("Retrieved all suppliers from suppliers service",
suppliers_count=len(result), tenant_id=tenant_id)
return result
@@ -63,7 +63,7 @@ class SuppliersServiceClient(BaseServiceClient):
if category:
params["category"] = category
result = await self.get("suppliers/search", tenant_id=tenant_id, params=params)
result = await self.get("suppliers/list/search", tenant_id=tenant_id, params=params)
suppliers = result.get('suppliers', []) if result else []
logger.info("Searched suppliers from suppliers service",
search_term=search, suppliers_count=len(suppliers), tenant_id=tenant_id)
@@ -81,7 +81,7 @@ class SuppliersServiceClient(BaseServiceClient):
"""Get supplier recommendations for procurement"""
try:
params = {"ingredient_id": ingredient_id}
result = await self.get("recommendations", tenant_id=tenant_id, params=params)
result = await self.get("suppliers/recommendations", tenant_id=tenant_id, params=params)
if result:
logger.info("Retrieved supplier recommendations from suppliers service",
ingredient_id=ingredient_id, tenant_id=tenant_id)
@@ -98,7 +98,7 @@ class SuppliersServiceClient(BaseServiceClient):
"ingredient_id": ingredient_id,
"criteria": criteria or {}
}
result = await self.post("find-best-supplier", data=data, tenant_id=tenant_id)
result = await self.post("suppliers/operations/find-best-supplier", data=data, tenant_id=tenant_id)
if result:
logger.info("Retrieved best supplier from suppliers service",
ingredient_id=ingredient_id, tenant_id=tenant_id)
@@ -115,7 +115,7 @@ class SuppliersServiceClient(BaseServiceClient):
async def create_purchase_order(self, tenant_id: str, order_data: Dict[str, Any]) -> Optional[Dict[str, Any]]:
"""Create a new purchase order"""
try:
result = await self.post("purchase-orders", data=order_data, tenant_id=tenant_id)
result = await self.post("suppliers/purchase-orders", data=order_data, tenant_id=tenant_id)
if result:
logger.info("Created purchase order",
order_id=result.get('id'),
@@ -136,7 +136,7 @@ class SuppliersServiceClient(BaseServiceClient):
if supplier_id:
params["supplier_id"] = supplier_id
result = await self.get("purchase-orders", tenant_id=tenant_id, params=params)
result = await self.get("suppliers/purchase-orders", tenant_id=tenant_id, params=params)
orders = result.get('orders', []) if result else []
logger.info("Retrieved purchase orders from suppliers service",
orders_count=len(orders), tenant_id=tenant_id)
@@ -150,7 +150,7 @@ class SuppliersServiceClient(BaseServiceClient):
"""Update purchase order status"""
try:
data = {"status": status}
result = await self.put(f"purchase-orders/{order_id}/status", data=data, tenant_id=tenant_id)
result = await self.put(f"suppliers/purchase-orders/{order_id}/status", data=data, tenant_id=tenant_id)
if result:
logger.info("Updated purchase order status",
order_id=order_id, status=status, tenant_id=tenant_id)
@@ -173,7 +173,7 @@ class SuppliersServiceClient(BaseServiceClient):
if date:
params["date"] = date
result = await self.get("deliveries", tenant_id=tenant_id, params=params)
result = await self.get("suppliers/deliveries", tenant_id=tenant_id, params=params)
deliveries = result.get('deliveries', []) if result else []
logger.info("Retrieved deliveries from suppliers service",
deliveries_count=len(deliveries), tenant_id=tenant_id)
@@ -190,7 +190,7 @@ class SuppliersServiceClient(BaseServiceClient):
if notes:
data["notes"] = notes
result = await self.put(f"deliveries/{delivery_id}/status", data=data, tenant_id=tenant_id)
result = await self.put(f"suppliers/deliveries/{delivery_id}/status", data=data, tenant_id=tenant_id)
if result:
logger.info("Updated delivery status",
delivery_id=delivery_id, status=status, tenant_id=tenant_id)
@@ -203,7 +203,7 @@ class SuppliersServiceClient(BaseServiceClient):
async def get_supplier_order_summaries(self, tenant_id: str) -> Optional[Dict[str, Any]]:
"""Get supplier order summaries for central bakery dashboard"""
try:
result = await self.get("supplier-order-summaries", tenant_id=tenant_id)
result = await self.get("suppliers/dashboard/order-summaries", tenant_id=tenant_id)
if result:
logger.info("Retrieved supplier order summaries from suppliers service",
tenant_id=tenant_id)
@@ -221,7 +221,7 @@ class SuppliersServiceClient(BaseServiceClient):
"""Get supplier performance metrics"""
try:
params = {"period": period}
result = await self.get(f"suppliers/{supplier_id}/performance", tenant_id=tenant_id, params=params)
result = await self.get(f"suppliers/analytics/performance/{supplier_id}", tenant_id=tenant_id, params=params)
if result:
logger.info("Retrieved supplier performance from suppliers service",
supplier_id=supplier_id, period=period, tenant_id=tenant_id)
@@ -234,7 +234,7 @@ class SuppliersServiceClient(BaseServiceClient):
async def get_performance_alerts(self, tenant_id: str) -> Optional[List[Dict[str, Any]]]:
"""Get supplier performance alerts"""
try:
result = await self.get("performance-alerts", tenant_id=tenant_id)
result = await self.get("suppliers/alerts/performance", tenant_id=tenant_id)
alerts = result.get('alerts', []) if result else []
logger.info("Retrieved supplier performance alerts",
alerts_count=len(alerts), tenant_id=tenant_id)
@@ -264,7 +264,7 @@ class SuppliersServiceClient(BaseServiceClient):
async def get_dashboard_summary(self, tenant_id: str) -> Optional[Dict[str, Any]]:
"""Get suppliers dashboard summary data"""
try:
result = await self.get("dashboard-summary", tenant_id=tenant_id)
result = await self.get("suppliers/dashboard/summary", tenant_id=tenant_id)
if result:
logger.info("Retrieved suppliers dashboard summary",
tenant_id=tenant_id)
@@ -281,7 +281,7 @@ class SuppliersServiceClient(BaseServiceClient):
"start_date": start_date,
"end_date": end_date
}
result = await self.get("cost-analysis", tenant_id=tenant_id, params=params)
result = await self.get("suppliers/analytics/cost-analysis", tenant_id=tenant_id, params=params)
if result:
logger.info("Retrieved supplier cost analysis",
start_date=start_date, end_date=end_date, tenant_id=tenant_id)
@@ -294,7 +294,7 @@ class SuppliersServiceClient(BaseServiceClient):
async def get_supplier_reliability_metrics(self, tenant_id: str) -> Optional[Dict[str, Any]]:
"""Get supplier reliability and quality metrics"""
try:
result = await self.get("reliability-metrics", tenant_id=tenant_id)
result = await self.get("suppliers/analytics/reliability-metrics", tenant_id=tenant_id)
if result:
logger.info("Retrieved supplier reliability metrics",
tenant_id=tenant_id)
@@ -311,7 +311,7 @@ class SuppliersServiceClient(BaseServiceClient):
async def acknowledge_alert(self, tenant_id: str, alert_id: str) -> Optional[Dict[str, Any]]:
"""Acknowledge a supplier-related alert"""
try:
result = await self.post(f"alerts/{alert_id}/acknowledge", data={}, tenant_id=tenant_id)
result = await self.post(f"suppliers/alerts/{alert_id}/acknowledge", data={}, tenant_id=tenant_id)
if result:
logger.info("Acknowledged supplier alert",
alert_id=alert_id, tenant_id=tenant_id)