Compare commits

..

3 Commits

Author SHA1 Message Date
82fe7f2939 Task_9: Postgres (adaption) 2026-05-11 14:49:46 +02:00
c39dd9c625 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	storage.py
2026-05-11 14:46:32 +02:00
51c372d4ab Task_9: Postgres (adaption) 2026-05-11 14:42:54 +02:00

View File

@ -13,8 +13,8 @@ class StorageError(Exception):
pass
class StorageAdapter(ABC):
"""Abstrakte Basisklasse für POI-Storage-Backends."""
class StorageWriter(ABC):
"""Write-only Interface. Klassen MÜSSEN explizit erben."""
@abstractmethod
def store(self, results: list[POI]) -> str:
@ -27,30 +27,32 @@ class StorageAdapter(ABC):
Returns:
str: Identifier der gespeicherten Ressource
(Dateipfad, DB-Tabelle, URL, etc.)
Raises:
StorageError: Bei Schreibfehlern.
"""
raise NotImplementedError
class JsonStorage(StorageAdapter):
class JsonStorage(StorageWriter):
"""
"""
def __init__(self, output_dir: Path = Path(".")):
self.output_dir = output_dir
self._path = self.output_dir / "pois.json"
def store(self, results: list[POI]) -> str:
output_path = self.output_dir / "pois.json"
try:
with output_path.open("w", encoding="utf-8") as f:
with self._path.open("w", encoding="utf-8") as f:
json.dump([asdict(poi) for poi in results], f, indent=2, ensure_ascii=False)
except OSError as exc:
logger.error(f"Fehler beim Speichern:{exc}")
logger.error(f"Fehler beim Speichern: {exc}")
raise StorageError("Fehler beim Speichern der POIs") from exc
return str(output_path.resolve())
return str(self._path.resolve())
class PostgresStorage(StorageAdapter):
class PostgresStorage(StorageWriter):
def __init__(self, connection_string: str, table: str = "pois"):
pass