39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import json
|
|
import logging
|
|
import pydapper
|
|
|
|
from ..schemas import model
|
|
from .. import local_db
|
|
from BreCal.database.sql_queries import SQLQuery
|
|
|
|
def GetNotifications(token, participant_id=None):
|
|
"""
|
|
Optional filtering by participant_id. Returns delivered (level=2) notifications.
|
|
"""
|
|
|
|
pooledConnection = None
|
|
try:
|
|
pooledConnection = local_db.getPoolConnection()
|
|
commands = pydapper.using(pooledConnection)
|
|
query = "SELECT id, shipcall_id, participant_id, level, type, message, created, modified FROM notification WHERE level = 2"
|
|
params = {}
|
|
if participant_id is not None:
|
|
query += " AND participant_id = ?participant_id?"
|
|
params["participant_id"] = participant_id
|
|
|
|
data = commands.query(query, model=model.Notification.from_query_row, param=params if params else None)
|
|
|
|
except Exception as ex:
|
|
logging.error(ex)
|
|
print(ex)
|
|
result = {}
|
|
result["error_field"] = "call failed"
|
|
return json.dumps(result), 500, {'Content-Type': 'application/json; charset=utf-8'}
|
|
finally:
|
|
if pooledConnection is not None:
|
|
pooledConnection.close()
|
|
|
|
return json.dumps(data, default=model.obj_dict), 200, {'Content-Type': 'application/json; charset=utf-8'}
|
|
|
|
|