57 lines
2.1 KiB
Python
57 lines
2.1 KiB
Python
"""
|
||
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
|