aboutsummaryrefslogtreecommitdiff
path: root/inventory-service/app/schemas/inventory.py
diff options
context:
space:
mode:
authoralex <[email protected]>2026-07-17 18:16:35 +0200
committeralex <[email protected]>2026-07-17 18:16:35 +0200
commit8e796c9cfcd65f6225a6ae3ec2a4419f265b0ebc (patch)
tree1bf90385144be2e9f350c31da553b1ac306ee60b /inventory-service/app/schemas/inventory.py
parent5f6918db393ed78dd8f038e9e5f1ea85f811dc52 (diff)
downloadorder-inventory-system-8e796c9cfcd65f6225a6ae3ec2a4419f265b0ebc.tar.xz
order-inventory-system-8e796c9cfcd65f6225a6ae3ec2a4419f265b0ebc.zip
inventory-service initHEADmain
Diffstat (limited to 'inventory-service/app/schemas/inventory.py')
-rw-r--r--inventory-service/app/schemas/inventory.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/inventory-service/app/schemas/inventory.py b/inventory-service/app/schemas/inventory.py
new file mode 100644
index 0000000..592c10a
--- /dev/null
+++ b/inventory-service/app/schemas/inventory.py
@@ -0,0 +1,93 @@
+from datetime import datetime
+from decimal import Decimal
+from pydantic import BaseModel, Field, ConfigDict
+from typing import Optional
+
+
+class ProductCreate(BaseModel):
+ name: str = Field(..., min_length=1, max_length=255)
+ sku: str = Field(
+ ...,
+ min_length=1,
+ max_length=100,
+ description="Stock-keeping unit — must be unique",
+ )
+ quantity_in_stock: int = Field(
+ ..., ge=0, description="Initial stock level, cannot be negative"
+ )
+
+
+class ProductUpdate(BaseModel):
+ name: Optional[str] = Field(None, min_length=1, max_length=255)
+ quantity_in_stock: Optional[int] = Field(None, ge=0)
+
+
+class ProductOut(BaseModel):
+ id: int
+ name: str
+ sku: str
+ quantity_in_stock: int
+ created_at: datetime
+ updated_at: datetime
+
+ model_config = ConfigDict(from_attributes=True)
+
+
+class StockMovementOut(BaseModel):
+ id: int
+ product_id: int
+ order_id: int
+ movement_type: str
+ quantity_change: int
+ created_at: datetime
+
+ model_config = ConfigDict(from_attributes=True)
+
+
+class ReservedItem(BaseModel):
+ product_id: int
+ quantity: int
+
+
+class FailedItem(BaseModel):
+ product_id: int
+ quantity: int
+
+
+class StockReservedEvent(BaseModel):
+ """
+ Emitted on the 'inventory' topic when stock is successfully reserved.
+
+ Example payload:
+ {
+ "order_id": 123,
+ "status": "SUCCESS",
+ "reserved_items": [
+ {"product_id": 101, "quantity": 2},
+ {"product_id": 102, "quantity": 1}
+ ]
+ }
+ """
+
+ order_id: int
+ status: str = "SUCCESS"
+ reserved_items: list[ReservedItem]
+
+
+class StockReservationFailedEvent(BaseModel):
+ """
+ Emitted on the 'inventory' topic when stock cannot be reserved.
+
+ Example payload:
+ {
+ "order_id": 123,
+ "status": "FAILED",
+ "reason": "INSUFFICIENT_STOCK",
+ "failed_items": [{"product_id": 102, "quantity": 5}]
+ }
+ """
+
+ order_id: int
+ status: str = "FAILED"
+ reason: str = "INSUFFICIENT_STOCK"
+ failed_items: list[FailedItem]