From 4384d18fab4d8ce23eceb038156ef1fa89862aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Wed, 17 Jun 2020 20:25:29 +0200 Subject: [PATCH] =?UTF-8?q?registrierung=20wurde=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geruecht/__init__.py | 2 ++ .../controller/databaseController/__init__.py | 3 +- .../dbRegistrationController.py | 32 +++++++++++++++++++ .../controller/mainController/__init__.py | 3 +- .../mainRegistrationController.py | 14 ++++++++ geruecht/registration_route.py | 15 +++++++++ 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 geruecht/controller/databaseController/dbRegistrationController.py create mode 100644 geruecht/controller/mainController/mainRegistrationController.py create mode 100644 geruecht/registration_route.py diff --git a/geruecht/__init__.py b/geruecht/__init__.py index 0b4d1da..d2eb11d 100644 --- a/geruecht/__init__.py +++ b/geruecht/__init__.py @@ -39,6 +39,7 @@ from geruecht.finanzer.routes import finanzer from geruecht.user.routes import user from geruecht.vorstand.routes import vorstand from geruecht.gastro.routes import gastrouser +from geruecht.registration_route import registration DEBUG.info("Registrate bluebrints") app.register_blueprint(baruser) @@ -46,3 +47,4 @@ app.register_blueprint(finanzer) app.register_blueprint(user) app.register_blueprint(vorstand) app.register_blueprint(gastrouser) +app.register_blueprint(registration) diff --git a/geruecht/controller/databaseController/__init__.py b/geruecht/controller/databaseController/__init__.py index 08ee142..8f783fd 100644 --- a/geruecht/controller/databaseController/__init__.py +++ b/geruecht/controller/databaseController/__init__.py @@ -1,6 +1,6 @@ from ..mainController import Singleton from geruecht import db -from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbPricelistController, dbWorkerController, dbWorkgroupController, dbJobInviteController, dbJobRequesController, dbAccessTokenController +from ..databaseController import dbUserController, dbCreditListController, dbJobKindController, dbPricelistController, dbWorkerController, dbWorkgroupController, dbJobInviteController, dbJobRequesController, dbAccessTokenController, dbRegistrationController from geruecht.exceptions import DatabaseExecption import traceback from MySQLdb._exceptions import IntegrityError @@ -14,6 +14,7 @@ class DatabaseController(dbUserController.Base, dbJobInviteController.Base, dbJobRequesController.Base, dbAccessTokenController.Base, + dbRegistrationController.Base, metaclass=Singleton): ''' DatabaesController diff --git a/geruecht/controller/databaseController/dbRegistrationController.py b/geruecht/controller/databaseController/dbRegistrationController.py new file mode 100644 index 0000000..39aa2e1 --- /dev/null +++ b/geruecht/controller/databaseController/dbRegistrationController.py @@ -0,0 +1,32 @@ +import traceback +from geruecht.exceptions import DatabaseExecption + +class Base: + def setNewRegistration(self, data): + try: + cursor = self.db.connection.cursor() + if data['entryDate']: + sql = "insert into registration_list (firstname, lastname, clubname, email, keynumber, birthdate, entrydate) VALUES ('{}', '{}', '{}', '{}', {}, '{}', '{}')".format( + data['firstName'], + data['lastName'], + data['clubName'] if data['clubName'] else 'NULL', + data['mail'], + data['keynumber'] if data['keynumber'] else 'NULL', + data['birthDate'], + data['entryDate'] + ) + else: + sql = "insert into registration_list (firstname, lastname, clubname, email, keynumber, birthdate) VALUES ('{}', '{}', '{}', '{}', {}, '{}')".format( + data['firstName'], + data['lastName'], + data['clubName'] if data['clubName'] else 'NULL', + data['mail'], + data['keynumber'] if data['keynumber'] else 'NULL', + data['birthDate'] + ) + cursor.execute(sql) + self.db.connection.commit() + except Exception as err: + traceback.print_exc() + self.db.connection.rollback() + raise DatabaseExecption("Something went worng with Databes: {}".format(err)) \ No newline at end of file diff --git a/geruecht/controller/mainController/__init__.py b/geruecht/controller/mainController/__init__.py index 41f2a7f..602f6ab 100644 --- a/geruecht/controller/mainController/__init__.py +++ b/geruecht/controller/mainController/__init__.py @@ -5,7 +5,7 @@ import geruecht.controller.emailController as ec from geruecht.model.user import User from datetime import datetime, timedelta from geruecht.logger import getDebugLogger -from ..mainController import mainJobKindController, mainCreditListController, mainPricelistController, mainUserController, mainWorkerController, mainWorkgroupController, mainJobInviteController, mainJobRequestController +from ..mainController import mainJobKindController, mainCreditListController, mainPricelistController, mainUserController, mainWorkerController, mainWorkgroupController, mainJobInviteController, mainJobRequestController, mainRegistrationController db = dc.DatabaseController() ldap = lc.LDAPController() @@ -22,6 +22,7 @@ class MainController(mainJobKindController.Base, mainWorkgroupController.Base, mainJobInviteController.Base, mainJobRequestController.Base, + mainRegistrationController.Base, metaclass=Singleton): def __init__(self): diff --git a/geruecht/controller/mainController/mainRegistrationController.py b/geruecht/controller/mainController/mainRegistrationController.py new file mode 100644 index 0000000..a32893f --- /dev/null +++ b/geruecht/controller/mainController/mainRegistrationController.py @@ -0,0 +1,14 @@ +from datetime import date + +import geruecht.controller.databaseController as dc +from geruecht.logger import getDebugLogger + +db = dc.DatabaseController() +debug = getDebugLogger() + +class Base: + def setNewRegistration(self, data): + debug.info("set new registration {{ {} }}".format(data)) + data['birthDate'] = date(int(data['birthDate']['year']), int(data['birthDate']['month']), int(data['birthDate']['day'])) + data['entryDate'] = date(int(data['entryDate']['year']), int(data['entryDate']['month']), int(data['entryDate']['day'])) if data['entryDate'] else None + db.setNewRegistration(data) \ No newline at end of file diff --git a/geruecht/registration_route.py b/geruecht/registration_route.py new file mode 100644 index 0000000..8a4bed1 --- /dev/null +++ b/geruecht/registration_route.py @@ -0,0 +1,15 @@ +from flask import Blueprint, request, jsonify +import geruecht.controller.mainController as mc +from geruecht.logger import getDebugLogger + +registration = Blueprint("registration", __name__) + +mainController = mc.MainController() + +debug = getDebugLogger() + +@registration.route("/registration", methods=['PUT']) +def __registration(): + data = request.get_json() + mainController.setNewRegistration(data) + return jsonify({"ok":"ok"}) \ No newline at end of file