fix(hosting): require merchant or prospect for site creation
- Schema: add merchant_id/prospect_id with model_validator requiring at least one. Remove from-prospect endpoint (unified into POST /sites) - Service: rewrite create() — if merchant_id use it directly, if prospect_id auto-create merchant from prospect data. Remove system merchant hack entirely. Extract _create_merchant_from_prospect helper. - Simplify accept_proposal() — merchant already exists at creation, only creates subscription and marks prospect converted - Tests: update all create calls with merchant_id, replace from-prospect tests with prospect_id + validation tests Closes docs/proposals/hosting-site-creation-fix.md Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,18 +3,31 @@
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
|
||||
|
||||
class HostedSiteCreate(BaseModel):
|
||||
"""Schema for creating a hosted site."""
|
||||
"""Schema for creating a hosted site.
|
||||
|
||||
Either merchant_id or prospect_id must be provided:
|
||||
- merchant_id: store is created under this merchant
|
||||
- prospect_id: a merchant is auto-created from prospect data
|
||||
"""
|
||||
|
||||
business_name: str = Field(..., max_length=255)
|
||||
merchant_id: int | None = None
|
||||
prospect_id: int | None = None
|
||||
contact_name: str | None = Field(None, max_length=255)
|
||||
contact_email: str | None = Field(None, max_length=255)
|
||||
contact_phone: str | None = Field(None, max_length=50)
|
||||
internal_notes: str | None = None
|
||||
|
||||
@model_validator(mode="after")
|
||||
def require_merchant_or_prospect(self) -> "HostedSiteCreate":
|
||||
if not self.merchant_id and not self.prospect_id:
|
||||
raise ValueError("Either merchant_id or prospect_id is required")
|
||||
return self
|
||||
|
||||
|
||||
class HostedSiteUpdate(BaseModel):
|
||||
"""Schema for updating a hosted site."""
|
||||
|
||||
Reference in New Issue
Block a user