42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from pydantic import BaseModel, Field, condecimal
|
|
from typing import Optional
|
|
from uuid import UUID
|
|
from decimal import Decimal
|
|
|
|
class OrderBase(BaseModel):
|
|
order_number: str = Field(..., min_length=1, max_length=50)
|
|
customer_id: str = Field(..., min_length=1)
|
|
total_amount: condecimal(max_digits=10, decimal_places=2)
|
|
shipping_address: str = Field(..., min_length=1)
|
|
status: str = Field(default="pending")
|
|
payment_status: str = Field(default="unpaid")
|
|
|
|
class OrderCreate(OrderBase):
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"order_number": "ORD-2023-001",
|
|
"customer_id": "user123",
|
|
"total_amount": "199.99",
|
|
"shipping_address": "123 Main St, City, Country",
|
|
"status": "pending",
|
|
"payment_status": "unpaid"
|
|
}
|
|
}
|
|
|
|
class Order(OrderBase):
|
|
id: UUID
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
"order_number": "ORD-2023-001",
|
|
"customer_id": "user123",
|
|
"total_amount": "199.99",
|
|
"shipping_address": "123 Main St, City, Country",
|
|
"status": "pending",
|
|
"payment_status": "unpaid"
|
|
}
|
|
} |