REFACTOR API gateway fix 5
This commit is contained in:
@@ -173,7 +173,7 @@ async def import_sales_data(
|
||||
current_user: Dict[str, Any] = Depends(get_current_user_dep),
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
"""Import sales data from file for tenant"""
|
||||
"""Import sales data from file for tenant - FIXED VERSION"""
|
||||
try:
|
||||
logger.info("Importing sales data",
|
||||
tenant_id=tenant_id,
|
||||
@@ -185,7 +185,7 @@ async def import_sales_data(
|
||||
content = await file.read()
|
||||
file_content = content.decode('utf-8')
|
||||
|
||||
# Process import
|
||||
# ✅ FIX: tenant_id comes from URL path, not file upload
|
||||
result = await DataImportService.process_upload(
|
||||
tenant_id,
|
||||
file_content,
|
||||
@@ -198,7 +198,7 @@ async def import_sales_data(
|
||||
# Publish event
|
||||
try:
|
||||
await publish_data_imported({
|
||||
"tenant_id": tenant_id,
|
||||
"tenant_id": str(tenant_id), # Ensure string conversion
|
||||
"type": "file_import",
|
||||
"format": file_format,
|
||||
"filename": file.filename,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
from sqlalchemy import Column, String, DateTime, Float, Integer, Text, Index
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
@@ -15,15 +15,17 @@ class SalesData(Base):
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
tenant_id = Column(UUID(as_uuid=True), nullable=False, index=True)
|
||||
date = Column(DateTime, nullable=False, index=True)
|
||||
date = Column(DateTime(timezone=True), nullable=False, index=True)
|
||||
product_name = Column(String(255), nullable=False, index=True)
|
||||
quantity_sold = Column(Integer, nullable=False)
|
||||
revenue = Column(Float, nullable=False)
|
||||
location_id = Column(String(100), nullable=True, index=True)
|
||||
source = Column(String(50), nullable=False, default="manual")
|
||||
notes = Column(Text, nullable=True)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
created_at = Column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc))
|
||||
updated_at = Column(DateTime(timezone=True),
|
||||
default=lambda: datetime.now(timezone.utc),
|
||||
onupdate=lambda: datetime.now(timezone.utc))
|
||||
|
||||
__table_args__ = (
|
||||
Index('idx_sales_tenant_date', 'tenant_id', 'date'),
|
||||
|
||||
@@ -9,8 +9,9 @@ from typing import Optional, List, Dict, Any
|
||||
from uuid import UUID
|
||||
|
||||
class SalesDataCreate(BaseModel):
|
||||
"""Schema for creating sales data"""
|
||||
tenant_id: UUID
|
||||
"""Schema for creating sales data - FIXED to work with gateway"""
|
||||
# ✅ FIX: Make tenant_id optional since it comes from URL path
|
||||
tenant_id: Optional[UUID] = Field(None, description="Tenant ID (auto-injected from URL path)")
|
||||
date: datetime
|
||||
product_name: str = Field(..., min_length=1, max_length=255)
|
||||
quantity_sold: int = Field(..., gt=0)
|
||||
@@ -25,6 +26,16 @@ class SalesDataCreate(BaseModel):
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
json_schema_extra = {
|
||||
"example": {
|
||||
"date": "2024-01-15T10:00:00Z",
|
||||
"product_name": "Pan Integral",
|
||||
"quantity_sold": 25,
|
||||
"revenue": 37.50,
|
||||
"source": "manual"
|
||||
# Note: tenant_id is automatically injected from URL path by gateway
|
||||
}
|
||||
}
|
||||
|
||||
class SalesDataResponse(BaseModel):
|
||||
"""Schema for sales data response"""
|
||||
@@ -62,15 +73,23 @@ class SalesDataQuery(BaseModel):
|
||||
from_attributes = True
|
||||
|
||||
class SalesDataImport(BaseModel):
|
||||
"""Schema for importing sales data"""
|
||||
tenant_id: UUID
|
||||
data: str # JSON string or CSV content
|
||||
"""Schema for importing sales data - FIXED to work with gateway"""
|
||||
# ✅ FIX: Make tenant_id optional since it comes from URL path
|
||||
tenant_id: Optional[UUID] = Field(None, description="Tenant ID (auto-injected from URL path)")
|
||||
data: str = Field(..., description="JSON string or CSV content")
|
||||
data_format: str = Field(..., pattern="^(csv|json|excel)$")
|
||||
source: str = Field(default="import", max_length=50)
|
||||
validate_only: bool = Field(default=False)
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
json_schema_extra = {
|
||||
"example": {
|
||||
"data": "date,product,quantity,revenue\n2024-01-01,bread,10,25.50",
|
||||
"data_format": "csv",
|
||||
# Note: tenant_id is automatically injected from URL path by gateway
|
||||
}
|
||||
}
|
||||
|
||||
class SalesDataBulkCreate(BaseModel):
|
||||
"""Schema for bulk creating sales data"""
|
||||
|
||||
Reference in New Issue
Block a user