diff --git a/backend/app/modules/editor/domain/entities.py b/backend/app/modules/editor/domain/entities.py index e69de29..f98c57c 100644 --- a/backend/app/modules/editor/domain/entities.py +++ b/backend/app/modules/editor/domain/entities.py @@ -0,0 +1,22 @@ +from dataclasses import dataclass +from datetime import datetime + + +@dataclass +class EditableFile: + path: str + format: str # csv, md, yaml, openapi + content: str + last_modified: datetime + + +@dataclass +class AffectedFile: + path: str + reason: str + + +@dataclass +class ImpactResult: + source_file: str + affected_files: list[AffectedFile] diff --git a/backend/app/modules/editor/infrastructure/file_io.py b/backend/app/modules/editor/infrastructure/file_io.py new file mode 100644 index 0000000..7a41a2f --- /dev/null +++ b/backend/app/modules/editor/infrastructure/file_io.py @@ -0,0 +1,35 @@ +from datetime import datetime, timezone +from pathlib import Path + +from app.modules.editor.domain.entities import EditableFile +from app.shared.infrastructure.filesystem import read_text, write_text + + +def detect_format(file_path: Path) -> str: + suffix = file_path.suffix.lower() + if suffix == ".csv": + return "csv" + elif suffix == ".md": + return "md" + elif suffix in (".yaml", ".yml"): + if "openapi" in file_path.name or "api-contracts" in file_path.name: + return "openapi" + return "yaml" + return "unknown" + + +def read_file(base_dir: Path, relative_path: str) -> EditableFile: + full_path = base_dir / relative_path + content = read_text(full_path) + stat = full_path.stat() + return EditableFile( + path=relative_path, + format=detect_format(full_path), + content=content, + last_modified=datetime.fromtimestamp(stat.st_mtime, tz=timezone.utc), + ) + + +def write_file(base_dir: Path, relative_path: str, content: str) -> None: + full_path = base_dir / relative_path + write_text(full_path, content)