From 0c12eade3ce48f0ddf86293e9e4b717ff54907b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=9A=D1=83=D1=82?= =?UTF-8?q?=D0=BB=D0=B0=D1=85=D0=BC=D0=B5=D1=82=D0=BE=D0=B2?= Date: Tue, 26 May 2026 13:53:45 +0000 Subject: [PATCH] add models.py --- models.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 models.py diff --git a/models.py b/models.py new file mode 100644 index 0000000..47ccd03 --- /dev/null +++ b/models.py @@ -0,0 +1,56 @@ +""" +Placeholder module for future data models. + +The current assignment does not require any persistent or structured data, but the +project layout follows a typical Python package structure. The ``models`` +module is kept minimal to satisfy the requirement of having at least four +files and to demonstrate how one might extend the project later. +""" + +from __future__ import annotations + +# --------------------------------------------------------------------------- +# Example data class – not used directly in the streaming demo but shows +# how a model could be defined for future extensions. +# --------------------------------------------------------------------------- +from dataclasses import dataclass, field +from typing import Dict, List + +@dataclass +class ProductPrice: + """Represents a price entry for a product in a specific city.""" + + product: str + city: str + price: float + currency: str = "rubles" + + def __post_init__(self) -> None: + if self.price < 0: + raise ValueError("Price cannot be negative") + +# --------------------------------------------------------------------------- +# Repository pattern – a very small in‑memory store. +# --------------------------------------------------------------------------- +class PriceRepository: + """Simple repository that holds :class:`ProductPrice` objects.""" + + def __init__(self) -> None: + self._store: Dict[tuple[str, str], ProductPrice] = {} + + def add(self, entry: ProductPrice) -> None: + key = (entry.product.lower(), entry.city.lower()) + self._store[key] = entry + + def get(self, product: str, city: str) -> ProductPrice | None: + return self._store.get((product.lower(), city.lower())) + +# --------------------------------------------------------------------------- +# Example usage – not executed in the main script but demonstrates API. +# --------------------------------------------------------------------------- +if __name__ == "__main__": # pragma: no cover + repo = PriceRepository() + repo.add(ProductPrice("milk", "kazan", 89)) + print(repo.get("Milk", "KAZAN")) + +# End of models.py