Added marketplace support

This commit is contained in:
2025-09-05 22:14:52 +02:00
parent 9dd177bddc
commit 4fb67e594d
6 changed files with 1307 additions and 117 deletions

View File

@@ -1,4 +1,4 @@
# models/api_models.py
# models/api_models.py - Updated with Marketplace Support
from pydantic import BaseModel, Field, field_validator, EmailStr
from typing import Optional, List
from datetime import datetime
@@ -55,7 +55,7 @@ class LoginResponse(BaseModel):
user: UserResponse
# Base Product Models
# Base Product Models with Marketplace Support
class ProductBase(BaseModel):
product_id: Optional[str] = None
title: Optional[str] = None
@@ -94,6 +94,9 @@ class ProductBase(BaseModel):
identifier_exists: Optional[str] = None
shipping: Optional[str] = None
currency: Optional[str] = None
# New marketplace fields
marketplace: Optional[str] = None
shop_name: Optional[str] = None
class ProductCreate(ProductBase):
@@ -161,9 +164,11 @@ class StockSummaryResponse(BaseModel):
product_title: Optional[str] = None
# Import Models
class CSVImportRequest(BaseModel):
url: str = Field(..., description="URL to CSV file")
# 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_name: str = Field(..., min_length=1, description="Name of the shop these products belong to")
batch_size: Optional[int] = Field(1000, gt=0, le=10000, description="Batch size for processing")
@field_validator('url')
@@ -173,10 +178,29 @@ class CSVImportRequest(BaseModel):
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()
class ImportJobResponse(BaseModel):
@field_validator('shop_name')
@classmethod
def validate_shop_name(cls, v):
if not v or not v.strip():
raise ValueError('Shop name cannot be empty')
return v.strip()
class MarketplaceImportJobResponse(BaseModel):
job_id: int
status: str
marketplace: str
shop_name: str
message: Optional[str] = None
imported: Optional[int] = 0
updated: Optional[int] = 0
@@ -205,5 +229,14 @@ class StatsResponse(BaseModel):
total_products: int
unique_brands: int
unique_categories: int
unique_marketplaces: int = 0
unique_shops: int = 0
total_stock_entries: int = 0
total_inventory_quantity: int = 0
class MarketplaceStatsResponse(BaseModel):
marketplace: str
total_products: int
unique_shops: int
unique_brands: int