git_brcal/src/server/BreCal/impl/participant.py

41 lines
1.1 KiB
Python

import sys
import json
import mariadb
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 verify call.
"""
try:
conn = mariadb.connect(host="lager", user="ds", password="Gurkensalat48", database="bremen_calling")
except mariadb.Error as e:
print(f"Error connecting to the database: {e}")
sys.exit(1)
cur = conn.cursor()
id = options["user_id"]
query = "SELECT p.id, p.name, p.street, p.postal_code, p.city, p.flags FROM participant p INNER JOIN user u WHERE u.participant_id = p.id AND u.id = %d "
data = [id]
cur.execute(query, data)
for (id, name, street, postal_code, city, flags) in cur:
# Implement your business logic here
# All the parameters are present in the options argument
return json.dumps({
"id": id,
"city": city,
"name": name,
"postal code": postal_code,
"street": street,
}), 200
return json.dumps([]), 200