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
def GetNotifications():
try:
if 'shipcall_id' in request.args:
options = {}
options["shipcall_id"] = request.args.get("shipcall_id")
return impl.notifications.GetNotifications(options)
if 'Authorization' in request.headers:
token = request.headers.get('Authorization')
return impl.notifications.GetNotifications(token)
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:
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 BreCal.database.sql_queries import SQLQuery
def GetNotifications(options):
def GetNotifications(token):
"""
:param options: A dictionary containing all the paramters for the Operations
options["shipcall_id"]: **Id**. *Example: 42*. Id of referenced ship call.
No parameters, gets all entries
"""
try:
pooledConnection = local_db.getPoolConnection()
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 " +
"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()
except Exception as ex:

View File

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