mirror of
https://github.com/dat515-2025/Group-8.git
synced 2026-03-22 06:57:47 +01:00
refactor(structure): move to 7project dir
This commit is contained in:
0
7project/backend/app/core/__init__.py
Normal file
0
7project/backend/app/core/__init__.py
Normal file
4
7project/backend/app/core/base.py
Normal file
4
7project/backend/app/core/base.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from sqlalchemy.ext.declarative import DeclarativeMeta, declarative_base
|
||||
|
||||
Base: DeclarativeMeta = declarative_base()
|
||||
|
||||
30
7project/backend/app/core/db.py
Normal file
30
7project/backend/app/core/db.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import os
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker
|
||||
from app.core.base import Base
|
||||
|
||||
DATABASE_URL = os.getenv("DATABASE_URL")
|
||||
if not DATABASE_URL:
|
||||
mariadb_host = os.getenv("MARIADB_HOST", "localhost")
|
||||
mariadb_port = os.getenv("MARIADB_PORT", "3306")
|
||||
mariadb_db = os.getenv("MARIADB_DB", "group_project")
|
||||
mariadb_user = os.getenv("MARIADB_USER", "root")
|
||||
mariadb_password = os.getenv("MARIADB_PASSWORD", "strongpassword")
|
||||
if mariadb_host and mariadb_db and mariadb_user and mariadb_password:
|
||||
DATABASE_URL = f"mysql+asyncmy://{mariadb_user}:{mariadb_password}@{mariadb_host}:{mariadb_port}/{mariadb_db}"
|
||||
else:
|
||||
raise Exception("Only MariaDB is supported. Please set the DATABASE_URL environment variable.")
|
||||
|
||||
# Load all models to register them
|
||||
from app.models.user import User
|
||||
from app.models.transaction import Transaction
|
||||
|
||||
ssl_enabled = os.getenv("MARIADB_HOST", "localhost") != "localhost"
|
||||
connect_args = {"ssl": {"ssl": True}} if ssl_enabled else {}
|
||||
|
||||
engine = create_async_engine(
|
||||
DATABASE_URL,
|
||||
pool_pre_ping=True,
|
||||
echo=os.getenv("SQL_ECHO", "0") == "1",
|
||||
connect_args=connect_args,
|
||||
)
|
||||
async_session_maker = async_sessionmaker(engine, expire_on_commit=False)
|
||||
6
7project/backend/app/core/queue.py
Normal file
6
7project/backend/app/core/queue.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import app.celery_app # noqa: F401
|
||||
from app.workers.celery_tasks import send_email
|
||||
|
||||
|
||||
def enqueue_email(to: str, subject: str, body: str) -> None:
|
||||
send_email.delay(to, subject, body)
|
||||
Reference in New Issue
Block a user