feat: Add WonderQ-MiniAPP Public API documentation
- Introduced a comprehensive API contract for the WonderQ-MiniAPP, detailing endpoints for site configuration, product listings, and lead submissions. - Defined data types for various entities including HeroSlide, Destination, Theme, CtaBanner, PublicProduct, and more. - Specified request and response formats, including error handling guidelines. chore: Update requirements to include python-multipart - Added python-multipart dependency to requirements.txt for handling file uploads. test: Implement API contract tests - Created test suite for API contracts, validating serializers and endpoints for public products and leads. - Included tests for destination and product serializers, ensuring correct data handling and validation. test: Add configuration tests for OSS settings - Implemented tests to verify that OSS settings are correctly loaded from environment variables.
This commit is contained in:
@@ -4,8 +4,8 @@ from sqlalchemy.orm import Session, selectinload
|
||||
from .shared import site_config
|
||||
from ..database import get_db
|
||||
from ..models import Destination, DestinationAlias, Lead, Product
|
||||
from ..schemas import LeadCreateIn, ProductQuery
|
||||
from ..serializers import destination_dict, product_dict
|
||||
from ..schemas import LeadCreateIn, ProductQuery, ProductStatus
|
||||
from ..serializers import destination_dict, public_product_dict
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
@@ -25,7 +25,7 @@ def get_site_config(db: Session = Depends(get_db)):
|
||||
def list_products(
|
||||
keyword: str | None = None,
|
||||
destinationId: str | None = None,
|
||||
status_value: str = Query(default="published", alias="status"),
|
||||
status_value: ProductStatus = Query(default="published", alias="status"),
|
||||
take: int = Query(default=48, ge=1, le=100),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
@@ -56,7 +56,7 @@ def list_products(
|
||||
.distinct()
|
||||
)
|
||||
products = db.scalars(stmt).unique().all()
|
||||
return {"items": [product_dict(product) for product in products]}
|
||||
return {"items": [public_product_dict(product) for product in products]}
|
||||
|
||||
|
||||
@router.get("/api/public/products/{product_id}")
|
||||
@@ -69,7 +69,7 @@ def get_product(product_id: str, db: Session = Depends(get_db)):
|
||||
product = db.scalars(stmt).first()
|
||||
if not product:
|
||||
raise HTTPException(status_code=404, detail="线路不存在")
|
||||
return product_dict(product)
|
||||
return public_product_dict(product)
|
||||
|
||||
|
||||
@router.get("/api/public/destinations")
|
||||
@@ -85,7 +85,7 @@ def list_destinations(db: Session = Depends(get_db)):
|
||||
|
||||
@router.post("/api/public/leads", status_code=status.HTTP_201_CREATED)
|
||||
def create_lead(body: LeadCreateIn, db: Session = Depends(get_db)):
|
||||
lead = Lead(**body.model_dump(exclude_none=True))
|
||||
lead = Lead(**body.model_dump(exclude_none=True), status="new")
|
||||
db.add(lead)
|
||||
db.commit()
|
||||
db.refresh(lead)
|
||||
|
||||
Reference in New Issue
Block a user