Mit berths klappt es jetzt und so wird's auch passieren
This commit is contained in:
parent
f64ea1b7cd
commit
f929ca338f
BIN
docs/2023_03_23_Bremen Calling_Auszug_UserStories.docx
Normal file
BIN
docs/2023_03_23_Bremen Calling_Auszug_UserStories.docx
Normal file
Binary file not shown.
BIN
docs/Arbeitspakete.xlsx
Normal file
BIN
docs/Arbeitspakete.xlsx
Normal file
Binary file not shown.
BIN
docs/BremenCalling_Datenmodell_Vers.001.xlsx
Normal file
BIN
docs/BremenCalling_Datenmodell_Vers.001.xlsx
Normal file
Binary file not shown.
BIN
docs/BremenCalling_Datenschema.pptx
Normal file
BIN
docs/BremenCalling_Datenschema.pptx
Normal file
Binary file not shown.
@ -3,9 +3,7 @@ from flask import Flask
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import secrets
|
import secrets
|
||||||
|
from . import local_db
|
||||||
import mysql.connector
|
|
||||||
import pydapper
|
|
||||||
|
|
||||||
from .api import shipcalls
|
from .api import shipcalls
|
||||||
from .api import verify
|
from .api import verify
|
||||||
@ -14,9 +12,10 @@ from .api import times
|
|||||||
from .api import notifications
|
from .api import notifications
|
||||||
from .api import berths
|
from .api import berths
|
||||||
|
|
||||||
|
sessions = dict()
|
||||||
|
|
||||||
def create_app(test_config=None):
|
def create_app(test_config=None):
|
||||||
global connection_pool
|
|
||||||
app = Flask(__name__, instance_relative_config=True)
|
app = Flask(__name__, instance_relative_config=True)
|
||||||
app.config.from_mapping(
|
app.config.from_mapping(
|
||||||
SECRET_KEY='dev'
|
SECRET_KEY='dev'
|
||||||
@ -41,29 +40,11 @@ def create_app(test_config=None):
|
|||||||
app.register_blueprint(berths.bp)
|
app.register_blueprint(berths.bp)
|
||||||
|
|
||||||
logging.basicConfig(filename='brecal.log', level=logging.DEBUG, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s')
|
logging.basicConfig(filename='brecal.log', level=logging.DEBUG, format='%(asctime)s | %(name)s | %(levelname)s | %(message)s')
|
||||||
|
|
||||||
|
local_db.initPool()
|
||||||
|
|
||||||
logging.info('App started')
|
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
|
return app
|
||||||
|
|
||||||
def create_api_key():
|
def create_api_key():
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import logging
|
|||||||
import pydapper
|
import pydapper
|
||||||
|
|
||||||
from ..schemas import model
|
from ..schemas import model
|
||||||
from ..schemas import __init__
|
from .. import local_db
|
||||||
|
|
||||||
def GetBerths(token):
|
def GetBerths(token):
|
||||||
"""
|
"""
|
||||||
@ -14,14 +14,20 @@ def GetBerths(token):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
commands = pydapper.using(__init__.connection_pool)
|
commands = pydapper.using(local_db.connection_pool)
|
||||||
data = commands.query("SELECT id, name1, name2 FROM berth ORDER BY name1", model=model.BerthList)
|
data = commands.query("SELECT id, name1, name2 FROM berth ORDER BY name1", model=model.Berth)
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
|
print(ex)
|
||||||
return json.dumps("call failed"), 500
|
return json.dumps("call failed"), 500
|
||||||
|
|
||||||
return json.dumps(data), 200
|
print(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return json.dumps(data, default=model.obj_dict), 200
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
26
src/server/BreCal/local_db.py
Normal file
26
src/server/BreCal/local_db.py
Normal file
@ -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)
|
||||||
@ -1,12 +1,19 @@
|
|||||||
from marshmallow import Schema, fields
|
from marshmallow import Schema, fields
|
||||||
|
from dataclasses import dataclass
|
||||||
|
import json
|
||||||
|
|
||||||
|
def obj_dict(obj):
|
||||||
|
return obj.__dict__
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class Berth(Schema):
|
class Berth(Schema):
|
||||||
|
id: int
|
||||||
|
name1: str
|
||||||
|
name2: str
|
||||||
id = fields.Int()
|
id = fields.Int()
|
||||||
name1 = fields.String()
|
name1 = fields.String()
|
||||||
name2 = fields.String()
|
name2 = fields.String()
|
||||||
|
|
||||||
|
|
||||||
class Error(Schema):
|
class Error(Schema):
|
||||||
message = fields.String(required=True,)
|
message = fields.String(required=True,)
|
||||||
|
|
||||||
@ -62,7 +69,7 @@ class Times(Schema):
|
|||||||
class TimesId(Schema):
|
class TimesId(Schema):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class BerthList(Berth):
|
class BerthList(Berth):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user