fixed missing info in notification API

This commit is contained in:
Daniel Schick 2024-12-18 17:59:40 +01:00
parent 4d5d63dbdd
commit f218e5f96a
3 changed files with 9 additions and 13 deletions

View File

@ -12,12 +12,11 @@ bp = Blueprint('notifications', __name__)
@auth_guard() # no restriction by role @auth_guard() # no restriction by role
def GetNotifications(): def GetNotifications():
try: try:
if 'shipcall_id' in request.args: if 'Authorization' in request.headers:
options = {} token = request.headers.get('Authorization')
options["shipcall_id"] = request.args.get("shipcall_id") return impl.notifications.GetNotifications(token)
return impl.notifications.GetNotifications(options)
else: else:
return create_dynamic_exception_response(ex=None, status_code=400, message="missing argument: shipcall_id") return create_dynamic_exception_response(ex=None, status_code=403, message="not authenticated")
except Exception as ex: except Exception as ex:
return create_dynamic_exception_response(ex=ex, status_code=400) return create_dynamic_exception_response(ex=ex, status_code=400)

View File

@ -6,21 +6,17 @@ from ..schemas import model
from .. import local_db from .. import local_db
from BreCal.database.sql_queries import SQLQuery from BreCal.database.sql_queries import SQLQuery
def GetNotifications(options): def GetNotifications(token):
""" """
:param options: A dictionary containing all the paramters for the Operations No parameters, gets all entries
options["shipcall_id"]: **Id**. *Example: 42*. Id of referenced ship call.
""" """
try: try:
pooledConnection = local_db.getPoolConnection() pooledConnection = local_db.getPoolConnection()
commands = pydapper.using(pooledConnection) commands = pydapper.using(pooledConnection)
# query = SQLQuery.get_notifications()
# data = commands.query(query, model=model.Notification.from_query_row, param={"scid" : options["shipcall_id"]})
data = commands.query("SELECT id, shipcall_id, participant_id, level, type, message, created, modified FROM notification " + data = commands.query("SELECT id, shipcall_id, participant_id, level, type, message, created, modified FROM notification " +
"WHERE shipcall_id = ?scid?", model=model.Notification.from_query_row, param={"scid" : options["shipcall_id"]}) "WHERE level = 2", model=model.Notification.from_query_row)
pooledConnection.close() pooledConnection.close()
except Exception as ex: except Exception as ex:

View File

@ -155,6 +155,7 @@ class Notification:
return { return {
"id": self.id, "id": self.id,
"shipcall_id": self.shipcall_id, "shipcall_id": self.shipcall_id,
"participant_id": self.participant_id,
"level": self.level, "level": self.level,
"type": self.type.name if isinstance(self.type, IntEnum) else NotificationType(self.type).name, "type": self.type.name if isinstance(self.type, IntEnum) else NotificationType(self.type).name,
"message": self.message, "message": self.message,