From f64ea1b7cd4e4647557f3239e51557468f2e1964 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Thu, 23 Mar 2023 17:56:04 +0100 Subject: [PATCH] WIP, berths dont work yet --- misc/create_schema.sql | 11 ++++++++++- src/server/BreCal/__init__.py | 1 - src/server/BreCal/api/berths.py | 4 ++-- src/server/BreCal/impl/berths.py | 26 +++++++++++++++++--------- src/server/BreCal/impl/verify.py | 7 +++++-- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/misc/create_schema.sql b/misc/create_schema.sql index 2fffd06..f405152 100644 --- a/misc/create_schema.sql +++ b/misc/create_schema.sql @@ -69,9 +69,18 @@ CREATE TABLE `participant` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='An organization taking part'; + CREATE TABLE `berth` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name1` varchar(128) DEFAULT NULL, `name2` varchar(128) DEFAULT NULL, - PRIMARY KEY(`id`) + PRIMARY KEY(`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Place of ship for a ship call'; + + +CREATE TABLE `shipcall_participant_map` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `shipcall_id` int(10) unsigned DEFAULT NULL, + `participant_id` int(10) unsigned DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Associates a participant with a shipcall'; diff --git a/src/server/BreCal/__init__.py b/src/server/BreCal/__init__.py index 99391ee..2e4ea94 100644 --- a/src/server/BreCal/__init__.py +++ b/src/server/BreCal/__init__.py @@ -13,7 +13,6 @@ from .api import participant from .api import times from .api import notifications from .api import berths -from .impl import util def create_app(test_config=None): diff --git a/src/server/BreCal/api/berths.py b/src/server/BreCal/api/berths.py index 5781d47..c0e0830 100644 --- a/src/server/BreCal/api/berths.py +++ b/src/server/BreCal/api/berths.py @@ -9,5 +9,5 @@ bp = Blueprint('berths', __name__) @bp.route('/berths', methods=['get']) def GetBerths(): - - return impl.berths.GetBerths() + token = request.headers.get('Authentication') + return impl.berths.GetBerths(token) diff --git a/src/server/BreCal/impl/berths.py b/src/server/BreCal/impl/berths.py index c25fa86..0315cea 100644 --- a/src/server/BreCal/impl/berths.py +++ b/src/server/BreCal/impl/berths.py @@ -1,19 +1,27 @@ import json import logging +import pydapper -def GetBerths(): +from ..schemas import model +from ..schemas import __init__ + +def GetBerths(token): + """ + No parameters, gets all entries """ - """ + # TODO: validate token - # Implement your business logic here - # All the parameters are present in the options argument + try: - return json.dumps([{ - "id": "", - "name1": "", - "name2": "", - }]), 200 + commands = pydapper.using(__init__.connection_pool) + data = commands.query("SELECT id, name1, name2 FROM berth ORDER BY name1", model=model.BerthList) + + except Exception as ex: + logging.error(ex) + return json.dumps("call failed"), 500 + + return json.dumps(data), 200 diff --git a/src/server/BreCal/impl/verify.py b/src/server/BreCal/impl/verify.py index 0d5dca2..4ab33c7 100644 --- a/src/server/BreCal/impl/verify.py +++ b/src/server/BreCal/impl/verify.py @@ -10,7 +10,7 @@ def GetVerify(apikey): :param apikey: the api-key registered with the user """ - if not apikey + if not apikey: return json.dumps("missing api key"), 400 sentinel = object() @@ -21,8 +21,11 @@ def GetVerify(apikey): return json.dumps("wrong api key", 403) except Exception as ex: + logging.error(ex) return json.dumps("logon failed"), 500 - logging.error(e) + + + # TODO: user authenticated: Create,store and transmit JWT token return json.dumps(""), 200