Files
orion/models/api/marketplace.py

66 lines
2.0 KiB
Python

import re
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, ConfigDict, EmailStr, Field, field_validator
# Marketplace Import Models
class MarketplaceImportRequest(BaseModel):
url: str = Field(..., description="URL to CSV file from marketplace")
marketplace: str = Field(
default="Letzshop",
description="Name of the marketplace (e.g., Letzshop, Amazon, eBay)",
)
shop_code: str = Field(..., description="Shop code to associate products with")
batch_size: Optional[int] = Field(
1000, gt=0, le=10000, description="Batch size for processing"
)
@field_validator("url")
@classmethod
def validate_url(cls, v):
if not v.startswith(("http://", "https://")):
raise ValueError("URL must start with http:// or https://")
return v
@field_validator("marketplace")
@classmethod
def validate_marketplace(cls, v):
# You can add validation for supported marketplaces here
supported_marketplaces = [
"Letzshop",
"Amazon",
"eBay",
"Etsy",
"Shopify",
"Other",
]
if v not in supported_marketplaces:
# For now, allow any marketplace but log it
pass
return v.strip()
@field_validator("shop_code")
@classmethod
def validate_shop_code(cls, v):
return v.upper().strip()
class MarketplaceImportJobResponse(BaseModel):
job_id: int
status: str
marketplace: str
shop_id: int
shop_code: Optional[str] = None # Will be populated from shop relationship
shop_name: str
message: Optional[str] = None
imported: Optional[int] = 0
updated: Optional[int] = 0
total_processed: Optional[int] = 0
error_count: Optional[int] = 0
error_message: Optional[str] = None
created_at: Optional[datetime] = None
started_at: Optional[datetime] = None
completed_at: Optional[datetime] = None