Add Order schema
This commit is contained in:
parent
2e9bb7acec
commit
19f945ab40
42
schemas/order.py
Normal file
42
schemas/order.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user