FreeDrinkHistory in einem Zeitraumen bekommen

Der Vorstand kann nun in einem bestimmten Zeitraum alle Freigetränke abrufen.
This commit is contained in:
Tim Gröger 2020-08-23 23:17:12 +02:00
parent fa5097da10
commit 1f5eb0be9d
3 changed files with 42 additions and 0 deletions

View File

@ -156,6 +156,28 @@ class Base:
self.db.connection.rollback() self.db.connection.rollback()
raise DatabaseExecption("Something went wrong with Database: {}".format(err)) raise DatabaseExecption("Something went wrong with Database: {}".format(err))
def get_free_drink_list_history_from_to(self, from_date, to_date):
try:
cursor = self.db.connection.cursor()
cursor.execute(f'select * from free_drink_list_history where timestamp>="{from_date}" and timestamp<="{to_date}"')
retVal = cursor.fetchall()
for data in retVal:
data['timestamp'] = {'year': data['timestamp'].year,
'month': data['timestamp'].month,
'day': data['timestamp'].day,
'hour': data['timestamp'].hour,
'minute': data['timestamp'].minute,
'second': data['timestamp'].second}
data['free_drink_config'] = self.get_free_drink_list_config(data['free_drink_config_id'])
data['free_drink_type'] = self.get_free_drink_list_type(data['free_drink_type_id'])
data['free_drink_list_reason'] = self.get_free_drink_list_reason(data['free_drink_list_reason_id']) if \
data['free_drink_list_reason_id'] else None
return retVal
except Exception as err:
traceback.print_exc()
self.db.connection.rollback()
raise DatabaseExecption("Something went wrong with Database: {}".format(err))
def update_free_drink_list_history(self, free_drink_list_history): def update_free_drink_list_history(self, free_drink_list_history):
try: try:
cursor = self.db.connection.cursor() cursor = self.db.connection.cursor()
@ -166,6 +188,7 @@ class Base:
traceback.print_exc() traceback.print_exc()
self.db.connection.rollback() self.db.connection.rollback()
raise DatabaseExecption("Something went wrong with Database: {}".format(err)) raise DatabaseExecption("Something went wrong with Database: {}".format(err))
def delete_free_drink_list_history(self, free_drink_list_history): def delete_free_drink_list_history(self, free_drink_list_history):
try: try:
cursor = self.db.connection.cursor() cursor = self.db.connection.cursor()

View File

@ -1,5 +1,6 @@
import geruecht.controller.databaseController as dc import geruecht.controller.databaseController as dc
from geruecht.logger import getDebugLogger from geruecht.logger import getDebugLogger
from datetime import datetime
db = dc.DatabaseController() db = dc.DatabaseController()
debug = getDebugLogger() debug = getDebugLogger()
@ -30,6 +31,11 @@ class Base:
db.update_free_drink_list_history(data) db.update_free_drink_list_history(data)
return db.get_free_drink_list_history_by_user(user) return db.get_free_drink_list_history_by_user(user)
def get_free_drink_list_history_from_to(self, data):
from_date = datetime(data["from_date"]["year"], data["from_date"]["month"], data["from_date"]["day"])
to_date = datetime(data["to_date"]["year"], data["to_date"]["month"], data["to_date"]["day"])
return db.get_free_drink_list_history_from_to(from_date, to_date)
def get_free_drink_list_reasons(self): def get_free_drink_list_reasons(self):
return db.get_free_drink_list_reasons() return db.get_free_drink_list_reasons()

View File

@ -78,6 +78,19 @@ def _free_drink_list_history(**kwargs):
debug.warning("exception in get free_dirnk_list_config.", exc_info=True) debug.warning("exception in get free_dirnk_list_config.", exc_info=True)
return jsonify({"error": str(err)}), 500 return jsonify({"error": str(err)}), 500
@app.route("/freeDrinkListHistoryFromTo", methods=['POST'])
@login_required(groups=[VORSTAND])
def _free_drink_list_history_from_to(**kwargs):
try:
debug.info("get free_drink_list_history")
data = request.get_json()
retVal = mainController.get_free_drink_list_history_from_to(data)
debug.debug(f'return free_drink_list_history {{{retVal}}}')
return jsonify(retVal)
except Exception as err:
debug.warning("exception in get free_dirnk_list_history.", exc_info=True)
return jsonify({"error": str(err)}), 500
@app.route("/deleteDrinkListHistory", methods=['POST']) @app.route("/deleteDrinkListHistory", methods=['POST'])
@login_required() @login_required()
def _delete_free_drink_list_history(**kwargs): def _delete_free_drink_list_history(**kwargs):