feat: add POST endpoint for admin marketplace import jobs

Add POST /api/v1/admin/marketplace-import-jobs endpoint to allow
admins to create import jobs for any vendor.

Changes:
- Add AdminMarketplaceImportJobRequest schema with vendor_id field
- Add create_marketplace_import_job endpoint in admin/marketplace.py
- Make vendor_code and vendor_name optional in response model
  to handle edge cases where vendor relationship may not be loaded

This fixes the 405 Method Not Allowed error when trying to import
products from the admin marketplace page.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-05 21:48:13 +01:00
parent 8776bbdda6
commit 962cc8dcef
2 changed files with 76 additions and 3 deletions

View File

@@ -29,6 +29,33 @@ class MarketplaceImportJobRequest(BaseModel):
return v.strip()
class AdminMarketplaceImportJobRequest(BaseModel):
"""Request schema for admin-triggered marketplace import.
Includes vendor_id since admin can import for any vendor.
"""
vendor_id: int = Field(..., description="Vendor ID to import products for")
source_url: str = Field(..., description="URL to CSV file from marketplace")
marketplace: str = Field(default="Letzshop", description="Marketplace name")
batch_size: int | None = Field(
1000, description="Processing batch size", ge=100, le=10000
)
@field_validator("source_url")
@classmethod
def validate_url(cls, v):
# Basic URL security validation
if not v.startswith(("http://", "https://")):
raise ValueError("URL must start with http:// or https://")
return v.strip()
@field_validator("marketplace")
@classmethod
def validate_marketplace(cls, v):
return v.strip()
class MarketplaceImportJobResponse(BaseModel):
"""Response schema for marketplace import job."""
@@ -36,8 +63,8 @@ class MarketplaceImportJobResponse(BaseModel):
job_id: int
vendor_id: int
vendor_code: str # Populated from vendor relationship
vendor_name: str # Populated from vendor relationship
vendor_code: str | None = None # Populated from vendor relationship
vendor_name: str | None = None # Populated from vendor relationship
marketplace: str
source_url: str
status: str