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

@@ -31,13 +31,13 @@ class InventoryServiceClient(BaseServiceClient):
async def get_ingredient_by_id(self, ingredient_id: UUID, tenant_id: str) -> Optional[Dict[str, Any]]:
"""Get ingredient details by ID"""
try:
result = await self.get(f"ingredients/{ingredient_id}", tenant_id=tenant_id)
result = await self.get(f"inventory/ingredients/{ingredient_id}", tenant_id=tenant_id)
if result:
logger.info("Retrieved ingredient from inventory service",
logger.info("Retrieved ingredient from inventory service",
ingredient_id=ingredient_id, tenant_id=tenant_id)
return result
except Exception as e:
logger.error("Error fetching ingredient by ID",
logger.error("Error fetching ingredient by ID",
error=str(e), ingredient_id=ingredient_id, tenant_id=tenant_id)
return None
@@ -64,10 +64,10 @@ class InventoryServiceClient(BaseServiceClient):
if is_active is not None:
params["is_active"] = is_active
result = await self.get("ingredients", tenant_id=tenant_id, params=params)
result = await self.get("inventory/ingredients", tenant_id=tenant_id, params=params)
ingredients = result if isinstance(result, list) else []
logger.info("Searched ingredients in inventory service",
logger.info("Searched ingredients in inventory service",
search_term=search, count=len(ingredients), tenant_id=tenant_id)
return ingredients
@@ -83,7 +83,7 @@ class InventoryServiceClient(BaseServiceClient):
if is_active is not None:
params["is_active"] = is_active
ingredients = await self.get_paginated("ingredients", tenant_id=tenant_id, params=params)
ingredients = await self.get_paginated("inventory/ingredients", tenant_id=tenant_id, params=params)
logger.info("Retrieved all ingredients from inventory service",
count=len(ingredients), tenant_id=tenant_id)
@@ -101,7 +101,7 @@ class InventoryServiceClient(BaseServiceClient):
if is_active is not None:
params["is_active"] = is_active
result = await self.get("ingredients/count", tenant_id=tenant_id, params=params)
result = await self.get("inventory/ingredients/count", tenant_id=tenant_id, params=params)
count = result.get("ingredient_count", 0) if isinstance(result, dict) else 0
logger.info("Retrieved ingredient count from inventory service",
@@ -116,7 +116,7 @@ class InventoryServiceClient(BaseServiceClient):
async def create_ingredient(self, ingredient_data: Dict[str, Any], tenant_id: str) -> Optional[Dict[str, Any]]:
"""Create a new ingredient"""
try:
result = await self.post("ingredients", data=ingredient_data, tenant_id=tenant_id)
result = await self.post("inventory/ingredients", data=ingredient_data, tenant_id=tenant_id)
if result:
logger.info("Created ingredient in inventory service",
ingredient_name=ingredient_data.get('name'), tenant_id=tenant_id)
@@ -134,7 +134,7 @@ class InventoryServiceClient(BaseServiceClient):
) -> Optional[Dict[str, Any]]:
"""Update an existing ingredient"""
try:
result = await self.put(f"ingredients/{ingredient_id}", data=ingredient_data, tenant_id=tenant_id)
result = await self.put(f"inventory/ingredients/{ingredient_id}", data=ingredient_data, tenant_id=tenant_id)
if result:
logger.info("Updated ingredient in inventory service",
ingredient_id=ingredient_id, tenant_id=tenant_id)
@@ -147,7 +147,7 @@ class InventoryServiceClient(BaseServiceClient):
async def delete_ingredient(self, ingredient_id: UUID, tenant_id: str) -> bool:
"""Delete (deactivate) an ingredient"""
try:
result = await self.delete(f"ingredients/{ingredient_id}", tenant_id=tenant_id)
result = await self.delete(f"inventory/ingredients/{ingredient_id}", tenant_id=tenant_id)
success = result is not None
if success:
logger.info("Deleted ingredient in inventory service",
@@ -170,7 +170,7 @@ class InventoryServiceClient(BaseServiceClient):
if include_unavailable:
params["include_unavailable"] = include_unavailable
result = await self.get(f"ingredients/{ingredient_id}/stock", tenant_id=tenant_id, params=params)
result = await self.get(f"inventory/ingredients/{ingredient_id}/stock", tenant_id=tenant_id, params=params)
stock_entries = result if isinstance(result, list) else []
logger.info("Retrieved ingredient stock from inventory service",
@@ -193,7 +193,7 @@ class InventoryServiceClient(BaseServiceClient):
if ingredient_ids:
params["ingredient_ids"] = [str(id) for id in ingredient_ids]
result = await self.get("stock", tenant_id=tenant_id, params=params)
result = await self.get("inventory/stock", tenant_id=tenant_id, params=params)
stock_levels = result if isinstance(result, list) else []
logger.info("Retrieved stock levels from inventory service",
@@ -208,7 +208,7 @@ class InventoryServiceClient(BaseServiceClient):
async def get_low_stock_alerts(self, tenant_id: str) -> List[Dict[str, Any]]:
"""Get low stock alerts"""
try:
result = await self.get("alerts", tenant_id=tenant_id, params={"type": "low_stock"})
result = await self.get("inventory/alerts", tenant_id=tenant_id, params={"type": "low_stock"})
alerts = result if isinstance(result, list) else []
logger.info("Retrieved low stock alerts from inventory service",
@@ -227,7 +227,7 @@ class InventoryServiceClient(BaseServiceClient):
) -> Optional[Dict[str, Any]]:
"""Record stock consumption"""
try:
result = await self.post("stock/consume", data=consumption_data, tenant_id=tenant_id)
result = await self.post("inventory/operations/consume-stock", data=consumption_data, tenant_id=tenant_id)
if result:
logger.info("Recorded stock consumption",
tenant_id=tenant_id)
@@ -244,7 +244,7 @@ class InventoryServiceClient(BaseServiceClient):
) -> Optional[Dict[str, Any]]:
"""Record stock receipt"""
try:
result = await self.post("stock/receive", data=receipt_data, tenant_id=tenant_id)
result = await self.post("inventory/operations/receive-stock", data=receipt_data, tenant_id=tenant_id)
if result:
logger.info("Recorded stock receipt",
tenant_id=tenant_id)
@@ -271,7 +271,7 @@ class InventoryServiceClient(BaseServiceClient):
"sales_volume": sales_volume
}
result = await self.post("inventory/classify-product", data=classification_data, tenant_id=tenant_id)
result = await self.post("inventory/operations/classify-product", data=classification_data, tenant_id=tenant_id)
if result:
logger.info("Classified product",
product=product_name,
@@ -296,7 +296,7 @@ class InventoryServiceClient(BaseServiceClient):
"products": products
}
result = await self.post("inventory/classify-products-batch", data=classification_data, tenant_id=tenant_id)
result = await self.post("inventory/operations/classify-products-batch", data=classification_data, tenant_id=tenant_id)
if result:
suggestions = result.get('suggestions', [])
business_model = result.get('business_model_analysis', {}).get('model', 'unknown')
@@ -319,7 +319,7 @@ class InventoryServiceClient(BaseServiceClient):
async def get_inventory_dashboard(self, tenant_id: str) -> Optional[Dict[str, Any]]:
"""Get inventory dashboard data"""
try:
result = await self.get("dashboard", tenant_id=tenant_id)
result = await self.get("inventory/dashboard/overview", tenant_id=tenant_id)
if result:
logger.info("Retrieved inventory dashboard data", tenant_id=tenant_id)
return result
@@ -331,7 +331,7 @@ class InventoryServiceClient(BaseServiceClient):
async def get_inventory_summary(self, tenant_id: str) -> Optional[Dict[str, Any]]:
"""Get inventory summary statistics"""
try:
result = await self.get("dashboard/summary", tenant_id=tenant_id)
result = await self.get("inventory/dashboard/summary", tenant_id=tenant_id)
if result:
logger.info("Retrieved inventory summary", tenant_id=tenant_id)
return result
@@ -351,7 +351,7 @@ class InventoryServiceClient(BaseServiceClient):
) -> Optional[Dict[str, Any]]:
"""Create a product transformation (e.g., par-baked to fully baked)"""
try:
result = await self.post("transformations", data=transformation_data, tenant_id=tenant_id)
result = await self.post("inventory/transformations", data=transformation_data, tenant_id=tenant_id)
if result:
logger.info("Created product transformation",
transformation_reference=result.get('transformation_reference'),
@@ -388,7 +388,7 @@ class InventoryServiceClient(BaseServiceClient):
if notes:
params["notes"] = notes
result = await self.post("transformations/par-bake-to-fresh", params=params, tenant_id=tenant_id)
result = await self.post("inventory/transformations/par-bake-to-fresh", params=params, tenant_id=tenant_id)
if result:
logger.info("Created par-bake transformation",
transformation_id=result.get('transformation_id'),
@@ -426,7 +426,7 @@ class InventoryServiceClient(BaseServiceClient):
if days_back:
params["days_back"] = days_back
result = await self.get("transformations", tenant_id=tenant_id, params=params)
result = await self.get("inventory/transformations", tenant_id=tenant_id, params=params)
transformations = result if isinstance(result, list) else []
logger.info("Retrieved transformations from inventory service",
@@ -445,7 +445,7 @@ class InventoryServiceClient(BaseServiceClient):
) -> Optional[Dict[str, Any]]:
"""Get specific transformation by ID"""
try:
result = await self.get(f"transformations/{transformation_id}", tenant_id=tenant_id)
result = await self.get(f"inventory/transformations/{transformation_id}", tenant_id=tenant_id)
if result:
logger.info("Retrieved transformation by ID",
transformation_id=transformation_id, tenant_id=tenant_id)
@@ -463,7 +463,7 @@ class InventoryServiceClient(BaseServiceClient):
"""Get transformation summary for dashboard"""
try:
params = {"days_back": days_back}
result = await self.get("transformations/summary", tenant_id=tenant_id, params=params)
result = await self.get("inventory/dashboard/transformations-summary", tenant_id=tenant_id, params=params)
if result:
logger.info("Retrieved transformation summary",
days_back=days_back, tenant_id=tenant_id)