some work on returning berths (ok) and participants (so far not ok)
This commit is contained in:
parent
fdeacdca6e
commit
f6f2f73d01
@ -15,17 +15,13 @@ def GetBerths(token):
|
||||
try:
|
||||
|
||||
commands = pydapper.using(local_db.connection_pool)
|
||||
data = commands.query("SELECT id, name1, name2 FROM berth ORDER BY name1", model=model.Berth)
|
||||
data = commands.query("SELECT id, name, participant_id, `lock`, created, modified FROM berth ORDER BY name", model=model.Berth)
|
||||
|
||||
except Exception as ex:
|
||||
logging.error(ex)
|
||||
print(ex)
|
||||
return json.dumps("call failed"), 500
|
||||
|
||||
print(data)
|
||||
|
||||
|
||||
|
||||
return json.dumps(data, default=model.obj_dict), 200
|
||||
|
||||
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import sys
|
||||
import json
|
||||
import mariadb
|
||||
import logging
|
||||
import pydapper
|
||||
|
||||
from ..schemas import model
|
||||
from .. import local_db
|
||||
|
||||
def GetParticipant(options):
|
||||
"""
|
||||
@ -9,33 +11,16 @@ def GetParticipant(options):
|
||||
options["user_id"]: **Id of user**. *Example: 2*. User id returned by verify call.
|
||||
|
||||
"""
|
||||
# TODO: validate token
|
||||
|
||||
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)
|
||||
commands = pydapper.using(local_db.connection_pool)
|
||||
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 INNER JOIN user u WHERE u.participant_id = p.id and u.id = ?user_id?", model=model.Participant, param=[{"user_id" : options["user_id"]}])
|
||||
|
||||
cur = conn.cursor()
|
||||
except Exception as ex:
|
||||
logging.error(ex)
|
||||
print(ex)
|
||||
return json.dumps("call failed"), 500
|
||||
|
||||
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
|
||||
return json.dumps(data, default=model.obj_dict), 200
|
||||
|
||||
|
||||
@ -1,18 +1,27 @@
|
||||
from marshmallow import Schema, fields
|
||||
from dataclasses import dataclass
|
||||
import json
|
||||
import datetime
|
||||
|
||||
def obj_dict(obj):
|
||||
if isinstance(obj, datetime.datetime):
|
||||
return obj.isoformat()
|
||||
return obj.__dict__
|
||||
|
||||
@dataclass
|
||||
class Berth(Schema):
|
||||
id: int
|
||||
name1: str
|
||||
name2: str
|
||||
name: str
|
||||
participant_id: int
|
||||
lock: bool
|
||||
created: datetime
|
||||
modified: datetime
|
||||
id = fields.Int()
|
||||
name1 = fields.String()
|
||||
name2 = fields.String()
|
||||
name = fields.String()
|
||||
participant_id = fields.Int()
|
||||
lock = fields.Bool()
|
||||
created = fields.DateTime()
|
||||
modified = fields.DateTime()
|
||||
|
||||
class Error(Schema):
|
||||
message = fields.String(required=True,)
|
||||
@ -31,14 +40,29 @@ class Notification(Schema):
|
||||
timestamp = fields.DateTime()
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
class Participant(Schema):
|
||||
city = fields.String()
|
||||
id: int
|
||||
name: str
|
||||
street: str
|
||||
postal_code: str
|
||||
city: str
|
||||
flags: int
|
||||
created: datetime
|
||||
modified: datetime
|
||||
|
||||
id = fields.Int()
|
||||
name = fields.String()
|
||||
postal_code = fields.String(data_key="postal code",)
|
||||
street = fields.String()
|
||||
postal_code = fields.String()
|
||||
city = fields.String()
|
||||
flags = fields.Int()
|
||||
created = fields.DateTime()
|
||||
modified = fields.DateTime()
|
||||
|
||||
@dataclass
|
||||
class ParticipantList(Participant):
|
||||
pass
|
||||
|
||||
class Shipcall(Schema):
|
||||
description = fields.String()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user