From 8e796c9cfcd65f6225a6ae3ec2a4419f265b0ebc Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 17 Jul 2026 18:16:35 +0200 Subject: inventory-service init --- inventory-service/app/schemas/inventory.py | 93 ++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 inventory-service/app/schemas/inventory.py (limited to 'inventory-service/app/schemas/inventory.py') 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] -- cgit v1.2.3