- 添加 .env.example 环境变量配置示例 - 添加 .gitignore 忽略文件配置 - 添加 core/config.py 配置管理模块 - 添加 deployments/k8s/configmap.yaml Kubernetes 配置 - 添加 core/database.py 数据库连接管理模块 - 添加 core/dependencies.py 全局依赖模块 - 添加 DEPENDENCIES_UPDATED.md 依赖更新记录 - 添加 deployments/k8s/deployment.yaml Kubernetes 部署配置- 添加 deployments/swarm/docker-compose.swarm.yml Docker Swarm 部署配置 - 添加 deployments/docker/docker-compose.yml Docker 部署配置 - 添加 deployments/docker/Dockerfile 应用镜像构建文件 - 添加 middleware/error_handler.py 全局异常处理中间件
81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
"""
|
|
App B Schemas - Pydantic schemas for products.
|
|
"""
|
|
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class ProductCreate(BaseModel):
|
|
"""Schema for creating a new product."""
|
|
|
|
name: str = Field(..., min_length=1, max_length=100)
|
|
description: Optional[str] = Field(None, max_length=500)
|
|
price: Decimal = Field(..., gt=0, decimal_places=2)
|
|
stock: int = Field(default=0, ge=0)
|
|
sku: str = Field(..., min_length=1, max_length=50)
|
|
is_available: bool = Field(default=True)
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"name": "Laptop",
|
|
"description": "High-performance laptop",
|
|
"price": "999.99",
|
|
"stock": 10,
|
|
"sku": "LAP-001",
|
|
"is_available": True,
|
|
}
|
|
}
|
|
|
|
|
|
class ProductUpdate(BaseModel):
|
|
"""Schema for updating a product."""
|
|
|
|
name: Optional[str] = Field(None, min_length=1, max_length=100)
|
|
description: Optional[str] = Field(None, max_length=500)
|
|
price: Optional[Decimal] = Field(None, gt=0, decimal_places=2)
|
|
stock: Optional[int] = Field(None, ge=0)
|
|
is_available: Optional[bool] = None
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"name": "Updated Laptop",
|
|
"price": "899.99",
|
|
"stock": 15,
|
|
}
|
|
}
|
|
|
|
|
|
class ProductResponse(BaseModel):
|
|
"""Schema for product response."""
|
|
|
|
id: int
|
|
name: str
|
|
description: Optional[str]
|
|
price: Decimal
|
|
stock: int
|
|
sku: str
|
|
is_available: bool
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
json_schema_extra = {
|
|
"example": {
|
|
"id": 1,
|
|
"name": "Laptop",
|
|
"description": "High-performance laptop",
|
|
"price": "999.99",
|
|
"stock": 10,
|
|
"sku": "LAP-001",
|
|
"is_available": True,
|
|
"created_at": "2024-01-15T10:30:00Z",
|
|
"updated_at": "2024-01-15T10:30:00Z",
|
|
}
|
|
}
|