diff --git a/docs/2023_03_23_Bremen Calling_Auszug_UserStories.docx b/docs/2023_03_23_Bremen Calling_Auszug_UserStories.docx new file mode 100644 index 0000000..a4a0bb6 Binary files /dev/null and b/docs/2023_03_23_Bremen Calling_Auszug_UserStories.docx differ diff --git a/docs/Arbeitspakete.xlsx b/docs/Arbeitspakete.xlsx new file mode 100644 index 0000000..0dffe22 Binary files /dev/null and b/docs/Arbeitspakete.xlsx differ diff --git a/docs/BremenCalling_Datenmodell_Vers.001.xlsx b/docs/BremenCalling_Datenmodell_Vers.001.xlsx new file mode 100644 index 0000000..31ab20c Binary files /dev/null and b/docs/BremenCalling_Datenmodell_Vers.001.xlsx differ diff --git a/docs/BremenCalling_Datenschema.pptx b/docs/BremenCalling_Datenschema.pptx new file mode 100644 index 0000000..dc1c2c3 Binary files /dev/null and b/docs/BremenCalling_Datenschema.pptx differ diff --git a/src/server/BreCal/__init__.py b/src/server/BreCal/__init__.py index 2e4ea94..ee89185 100644 --- a/src/server/BreCal/__init__.py +++ b/src/server/BreCal/__init__.py @@ -3,9 +3,7 @@ from flask import Flask import os import logging import secrets - -import mysql.connector -import pydapper +from . import local_db from .api import shipcalls from .api import verify @@ -14,9 +12,10 @@ from .api import times from .api import notifications from .api import berths +sessions = dict() def create_app(test_config=None): - global connection_pool + app = Flask(__name__, instance_relative_config=True) app.config.from_mapping( SECRET_KEY='dev' @@ -41,29 +40,11 @@ def create_app(test_config=None): app.register_blueprint(berths.bp) logging.basicConfig(filename='brecal.log', level=logging.DEBUG, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s') + + local_db.initPool() + logging.info('App started') - try: - connection_pool = mysql.connector.connect( - host="lager", - port=3306, - user="ds", - password="HalloWach23", - pool_name="brecal_pool", - pool_size=20, - database="bremen_calling" - ) - - commands = pydapper.using(connection_pool) - data = commands.query_single("SELECT id from `user`") - print(data) - - except mysql.connector.PoolError as e: - logging.error(f"Failed to create connection pool: {e}") - print(e) - - sessions = dict() - return app def create_api_key(): diff --git a/src/server/BreCal/impl/berths.py b/src/server/BreCal/impl/berths.py index 0315cea..7acfefa 100644 --- a/src/server/BreCal/impl/berths.py +++ b/src/server/BreCal/impl/berths.py @@ -3,7 +3,7 @@ import logging import pydapper from ..schemas import model -from ..schemas import __init__ +from .. import local_db def GetBerths(token): """ @@ -14,14 +14,20 @@ def GetBerths(token): try: - commands = pydapper.using(__init__.connection_pool) - data = commands.query("SELECT id, name1, name2 FROM berth ORDER BY name1", model=model.BerthList) + commands = pydapper.using(local_db.connection_pool) + data = commands.query("SELECT id, name1, name2 FROM berth ORDER BY name1", model=model.Berth) except Exception as ex: logging.error(ex) + print(ex) return json.dumps("call failed"), 500 - return json.dumps(data), 200 + print(data) + + + + return json.dumps(data, default=model.obj_dict), 200 + diff --git a/src/server/BreCal/local_db.py b/src/server/BreCal/local_db.py new file mode 100644 index 0000000..c2c2cf9 --- /dev/null +++ b/src/server/BreCal/local_db.py @@ -0,0 +1,26 @@ +import mysql.connector +import pydapper +import logging + +connection_pool = None + +def initPool(): + try: + global connection_pool + connection_pool = mysql.connector.connect( + host="lager", + port=3306, + user="ds", + password="HalloWach23", + pool_name="brecal_pool", + pool_size=20, + database="bremen_calling" + ) + + commands = pydapper.using(connection_pool) + data = commands.query_single("SELECT id from `user`") + print("DB connection successful") + + except mysql.connector.PoolError as e: + logging.error(f"Failed to create connection pool: {e}") + print(e) \ No newline at end of file diff --git a/src/server/BreCal/schemas/model.py b/src/server/BreCal/schemas/model.py index f40e6d5..d300b65 100644 --- a/src/server/BreCal/schemas/model.py +++ b/src/server/BreCal/schemas/model.py @@ -1,12 +1,19 @@ from marshmallow import Schema, fields +from dataclasses import dataclass +import json +def obj_dict(obj): + return obj.__dict__ +@dataclass class Berth(Schema): + id: int + name1: str + name2: str id = fields.Int() name1 = fields.String() name2 = fields.String() - class Error(Schema): message = fields.String(required=True,) @@ -62,7 +69,7 @@ class Times(Schema): class TimesId(Schema): pass - +@dataclass class BerthList(Berth): pass