diff --git a/app/__init__.py b/app/__init__.py index a4a03c8..52cca2e 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -3,6 +3,7 @@ from flask_cors import CORS from app.config import Config from app.routes import auth_bp, autocall_bp from app.errors import method_not_allowed, unsupported_media_type +from app.extensions import db def create_app(): @@ -23,4 +24,7 @@ def create_app(): app.register_error_handler(405, method_not_allowed) app.register_error_handler(415, unsupported_media_type) + # Database + db.init_app(app) + return app diff --git a/app/config.py b/app/config.py index 9a20816..917a7fb 100644 --- a/app/config.py +++ b/app/config.py @@ -28,5 +28,15 @@ class Config: "BANK_CALL_BASIC_AUTH_PASSWORD", "password" ) + DATABASE_USER = os.getenv("DATABASE_USER") + DATABASE_PASSWORD = os.getenv("DATABASE_PASSWORD") + DATABASE_HOST = os.getenv("DATABASE_HOST") + DATABASE_NAME = os.getenv("DATABASE_NAME") + DATABASE_PORT = os.getenv("DATABASE_PORT", 10532) + + SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{DATABASE_USER}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}" + SQLALCHEMY_TRACK_MODIFICATIONS = False + + settings = Config() diff --git a/app/extensions.py b/app/extensions.py new file mode 100644 index 0000000..2e1eeb6 --- /dev/null +++ b/app/extensions.py @@ -0,0 +1,3 @@ +from flask_sqlalchemy import SQLAlchemy + +db = SQLAlchemy() \ No newline at end of file diff --git a/openapi.yml b/openapi.yml index 8db5711..c4bc462 100644 --- a/openapi.yml +++ b/openapi.yml @@ -95,6 +95,24 @@ paths: unicode: type: boolean example: true + responses: + 200: + description: A successful response + /autocall/refresh-verify-disbursement: + get: + summary: Refresh the disbursement to verify + responses: + 200: + description: A successful response + /autocall/refresh-disbursement: + get: + summary: Refresh the disbursement + responses: + 200: + description: A successful response + /autocall/payment-callback: + get: + summary: The Payment callback responses: 200: description: A successful response \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index a5968da..a9e0716 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,7 @@ marshmallow==3.19.0 Flask-Cors==3.0.10 gunicorn requests -confluent-kafka==1.9.2 \ No newline at end of file +confluent-kafka==1.9.2 +flask-sqlalchemy +psycopg2-binary +alembic \ No newline at end of file diff --git a/wsgi.py b/wsgi.py index 55e8617..b59093d 100644 --- a/wsgi.py +++ b/wsgi.py @@ -1,17 +1,13 @@ +import threading from app import create_app from app.integrations import KafkaIntegration from app.config import settings from app.utils.logger import logger app = create_app() +kafka = KafkaIntegration() -if __name__ != "__main__": - - #Expose WSGI app instance for Gunicorn - wsgi_app = app - - kafka = KafkaIntegration() - +def start_kafka_consumer(): logger.info("Starting Kafka consumer...") while True: try: @@ -28,8 +24,12 @@ if __name__ != "__main__": except Exception as e: logger.error(f"Error while receiving message: {e}") - raise +if __name__ != "__main__": + # Expose WSGI app instance for Gunicorn - # wsgi_app = app + wsgi_app = app + + # Start kafka in a thread + # threading.Thread(target=start_kafka_consumer, daemon=True).start()