diff --git a/backend/hermes/.env b/backend/hermes/.env new file mode 100644 index 0000000..c43a93a --- /dev/null +++ b/backend/hermes/.env @@ -0,0 +1,5 @@ +DATABASE_URL=postgresql+psycopg://olympus:FsFs03285310!!!@olympus-db:5432/olympus + +APP_NAME=Hermes API + +APP_VERSION=0.1.0 diff --git a/backend/hermes/app/__pycache__/main.cpython-314.pyc b/backend/hermes/app/__pycache__/main.cpython-314.pyc index 06c55d6..1be2f4b 100644 Binary files a/backend/hermes/app/__pycache__/main.cpython-314.pyc and b/backend/hermes/app/__pycache__/main.cpython-314.pyc differ diff --git a/backend/hermes/app/core/__pycache__/config.cpython-314.pyc b/backend/hermes/app/core/__pycache__/config.cpython-314.pyc new file mode 100644 index 0000000..7ed23be Binary files /dev/null and b/backend/hermes/app/core/__pycache__/config.cpython-314.pyc differ diff --git a/backend/hermes/app/core/config.py b/backend/hermes/app/core/config.py new file mode 100644 index 0000000..2a3355c --- /dev/null +++ b/backend/hermes/app/core/config.py @@ -0,0 +1,16 @@ +from pydantic_settings import BaseSettings, SettingsConfigDict + + +class Settings(BaseSettings): + app_name: str = "Hermes API" + app_version: str = "0.1.0" + + database_url: str + + model_config = SettingsConfigDict( + env_file=".env", + case_sensitive=False + ) + + +settings = Settings() \ No newline at end of file diff --git a/backend/hermes/app/db/__pycache__/database.cpython-314.pyc b/backend/hermes/app/db/__pycache__/database.cpython-314.pyc new file mode 100644 index 0000000..0d3d656 Binary files /dev/null and b/backend/hermes/app/db/__pycache__/database.cpython-314.pyc differ diff --git a/backend/hermes/app/db/__pycache__/health.cpython-314.pyc b/backend/hermes/app/db/__pycache__/health.cpython-314.pyc new file mode 100644 index 0000000..7493d1d Binary files /dev/null and b/backend/hermes/app/db/__pycache__/health.cpython-314.pyc differ diff --git a/backend/hermes/app/db/database.py b/backend/hermes/app/db/database.py new file mode 100644 index 0000000..a747234 --- /dev/null +++ b/backend/hermes/app/db/database.py @@ -0,0 +1,29 @@ +from sqlalchemy import create_engine +from sqlalchemy.orm import DeclarativeBase +from sqlalchemy.orm import sessionmaker + +from app.core.config import settings + + +engine = create_engine( + settings.database_url, + echo=False +) + +SessionLocal = sessionmaker( + autocommit=False, + autoflush=False, + bind=engine +) + + +class Base(DeclarativeBase): + pass + + +def get_db(): + db = SessionLocal() + try: + yield db + finally: + db.close() \ No newline at end of file diff --git a/backend/hermes/app/db/health.py b/backend/hermes/app/db/health.py new file mode 100644 index 0000000..4cefa6e --- /dev/null +++ b/backend/hermes/app/db/health.py @@ -0,0 +1,12 @@ +from sqlalchemy import text + +from app.db.database import engine + + +def check_database() -> bool: + try: + with engine.connect() as connection: + connection.execute(text("SELECT 1")) + return True + except Exception: + return False \ No newline at end of file diff --git a/backend/hermes/app/main.py b/backend/hermes/app/main.py index f98f36b..7db3816 100644 --- a/backend/hermes/app/main.py +++ b/backend/hermes/app/main.py @@ -1,5 +1,7 @@ from fastapi import FastAPI +from app.db.health import check_database + app = FastAPI( title="Hermes API", version="0.1.0", @@ -9,9 +11,15 @@ app = FastAPI( @app.get("/") def root(): - return {"service": "Hermes", "status": "running"} + return { + "service": "Hermes", + "status": "running" + } @app.get("/health") def health(): - return {"status": "healthy"} + return { + "status": "healthy", + "database": check_database() + } \ No newline at end of file