import json import os from pathlib import Path from typing import Dict, Any, Optional import logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) class DataService: def __init__(self, data_dir: str = "data"): """ Initialize data service. Args: data_dir: Path to data directory (default: "data") """ self.data_dir = Path(data_dir) if not self.data_dir.exists(): raise ValueError(f"Data directory '{data_dir}' does not exist") logger.info(f"DataService initialized with directory: {self.data_dir}") def get_data(self, filename: str) -> Optional[Dict[str, Any]]: """ Read and return complete data from JSON file. Args: filename: Name of JSON file (e.g., "GetCustomers.json") Returns: Dictionary with complete JSON data or None if error """ file_path = self.data_dir / filename try: if not file_path.exists(): logger.error(f"File not found: {file_path}") return None with open(file_path, 'r', encoding='utf-8') as f: data = json.load(f) logger.info(f"Successfully loaded data from {filename}") return data except json.JSONDecodeError as e: logger.error(f"Invalid JSON in {filename}: {e}") return None except Exception as e: logger.error(f"Error reading {filename}: {e}") return None