{'src': {'__init__.py': '', 'application': {'__init__.py': ''}, 'delivery': {'__init__.py': '', 'api': {'__init__.py': '', 'application.py': 'from fastapi import FastAPI, Request\nfrom fastapi.responses import JSONResponse\n\n\napp = FastAPI()\n\n@app.exception_handler(Exception)\nasync def unexpected_exception_handler(_: Request, exc: Exception) -> JSONResponse:\n\treturn HttpResponse.internal_error(exc)\n\n\n@app.exception_handler(DomainError)\nasync def domain_error_handler(_: Request, exc: DomainError) -> JSONResponse:\n\treturn HttpResponse.domain_error(exc, status_code=StatusCode.BAD_REQUEST)'}}, 'infra': {'__init__.py': '', 'http': {'__init__.py': '', 'http_response.py': 'from fastapi.responses import JSONResponse\n\n\nlogger = create_logger("logger")\n\n\nclass HttpResponse:\n\t@staticmethod\n\tdef domain_error(error: DomainError, status_code: StatusCode) -> JSONResponse:\n\t\tlogger.error(\n\t\t\t"error - domain error",\n\t\t\textra={"extra": {"error": error.to_primitives(), "status_code": status_code}},\n\t\t)\n\t\treturn JSONResponse(content={"error": error.to_primitives()}, status_code=status_code)\n\n\t@staticmethod\n\tdef internal_error(error: Exception) -> JSONResponse:\n\t\tlogger.error(\n\t\t\t"error - internal server error",\n\t\t\textra={\n\t\t\t\t"extra": {"error": str(error)},\n\t\t\t\t"status_code": StatusCode.INTERNAL_SERVER_ERROR,\n\t\t\t},\n\t\t)\n\t\treturn JSONResponse(\n\t\t\tcontent={"error": "Internal server error"},\n\t\t\tstatus_code=StatusCode.INTERNAL_SERVER_ERROR,\n\t\t)\n\n\t@staticmethod\n\tdef created(resource: str) -> JSONResponse:\n\t\tlogger.info(\n\t\t\tf"resource - {resource}",\n\t\t\textra={"extra": {"status_code": StatusCode.CREATED}},\n\t\t)\n\t\treturn JSONResponse(content={}, status_code=StatusCode.CREATED)\n\n\t@staticmethod\n\tdef ok(content: dict) -> JSONResponse:\n\t\treturn JSONResponse(content=content, status_code=StatusCode.OK)\n'}, 'logger': {'__init__.py': '', 'logger.py': 'from collections.abc import Sequence\n\nimport logging\nfrom datetime import date\nfrom logging.handlers import TimedRotatingFileHandler\nfrom pathlib import Path\n\n\ndef create_file_handler(file_name: str, level: int) -> TimedRotatingFileHandler:\n\troot_project_path = _find_project_root(markers=["pyproject.toml"])\n\tlog_folder = root_project_path / "logs"\n\tlog_folder.mkdir(parents=True, exist_ok=True)\n\n\tfile_handler = TimedRotatingFileHandler(\n\t\tfilename=f"{log_folder}/{file_name}_{date.today().isoformat()}.log",\n\t\twhen="midnight",\n\t\tinterval=1,\n\t\tbackupCount=7,\n\t\tencoding="utf-8",\n\t)\n\tfile_handler.setLevel(level)\n\n\treturn file_handler\n\n\ndef create_logger(logger_name: str) -> logging.Logger:\n\tlogger = logging.getLogger(logger_name)\n\tlogger.setLevel(logging.DEBUG)\n\n\tproduction_handler = create_file_handler(file_name="prod", level=logging.ERROR)\n\tdevelop_handler = create_file_handler(file_name="dev", level=logging.DEBUG)\n\n\tif not logger.handlers:\n\t\tlogger.addHandler(production_handler)\n\t\tlogger.addHandler(develop_handler)\n\n\treturn logger\n\ndef _find_project_root(markers: Sequence[str]) -> Path:\n\tstart = Path(__file__).resolve()\n\tfor parent in (start, *start.parents):\n\t\tif any((parent / marker).exists() for marker in markers):\n\t\t\treturn parent\n\traise FileNotFoundError(f"Could not find project root (markers: {markers}).")'}}}}
