32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
import json
|
|
import logging
|
|
import pydapper
|
|
|
|
from ..schemas import model
|
|
from .. import local_db
|
|
|
|
def GetParticipant(options):
|
|
"""
|
|
:param options: A dictionary containing all the paramters for the Operations
|
|
options["user_id"]: **Id of user**. *Example: 2*. User id returned by login call.
|
|
|
|
"""
|
|
# TODO: validate token
|
|
|
|
try:
|
|
commands = pydapper.using(local_db.connection_pool)
|
|
if "user_id" in options and options["user_id"]:
|
|
data = commands.query("SELECT p.id as id, p.name as name, p.street as street, p.postal_code as postal_code, p.city as city, p.flags as flags, p.created as created, p.modified as modified FROM p INNER JOIN user u WHERE u.participant_id = p.id and u.id = ?userid?", model=model.Participant, param={"userid" : options["user_id"]})
|
|
else:
|
|
data = commands.query("SELECT p.id as id, p.name as name, p.street as street, p.postal_code as postal_code, p.city as city, p.flags as flags, p.created as created, p.modified as modified FROM participant p ORDER BY p.name", model=model.Participant)
|
|
|
|
except Exception as ex:
|
|
logging.error(ex)
|
|
print(ex)
|
|
result = {}
|
|
result["message"] = "call failed"
|
|
return json.dumps("call failed"), 500
|
|
|
|
return json.dumps(data, default=model.obj_dict), 200
|
|
|