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:
|
try:
|
||||||
|
|
||||||
commands = pydapper.using(local_db.connection_pool)
|
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:
|
except Exception as ex:
|
||||||
logging.error(ex)
|
logging.error(ex)
|
||||||
print(ex)
|
print(ex)
|
||||||
return json.dumps("call failed"), 500
|
return json.dumps("call failed"), 500
|
||||||
|
|
||||||
print(data)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return json.dumps(data, default=model.obj_dict), 200
|
return json.dumps(data, default=model.obj_dict), 200
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import sys
|
|
||||||
import json
|
import json
|
||||||
import mariadb
|
|
||||||
import logging
|
import logging
|
||||||
|
import pydapper
|
||||||
|
|
||||||
|
from ..schemas import model
|
||||||
|
from .. import local_db
|
||||||
|
|
||||||
def GetParticipant(options):
|
def GetParticipant(options):
|
||||||
"""
|
"""
|
||||||
@ -9,33 +11,16 @@ def GetParticipant(options):
|
|||||||
options["user_id"]: **Id of user**. *Example: 2*. User id returned by verify call.
|
options["user_id"]: **Id of user**. *Example: 2*. User id returned by verify call.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# TODO: validate token
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn = mariadb.connect(host="lager", user="ds", password="Gurkensalat48", database="bremen_calling")
|
commands = pydapper.using(local_db.connection_pool)
|
||||||
except mariadb.Error as e:
|
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"]}])
|
||||||
print(f"Error connecting to the database: {e}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
cur = conn.cursor()
|
except Exception as ex:
|
||||||
|
logging.error(ex)
|
||||||
|
print(ex)
|
||||||
|
return json.dumps("call failed"), 500
|
||||||
|
|
||||||
id = options["user_id"]
|
return json.dumps(data, default=model.obj_dict), 200
|
||||||
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
|
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +1,27 @@
|
|||||||
from marshmallow import Schema, fields
|
from marshmallow import Schema, fields
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import json
|
import json
|
||||||
|
import datetime
|
||||||
|
|
||||||
def obj_dict(obj):
|
def obj_dict(obj):
|
||||||
|
if isinstance(obj, datetime.datetime):
|
||||||
|
return obj.isoformat()
|
||||||
return obj.__dict__
|
return obj.__dict__
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Berth(Schema):
|
class Berth(Schema):
|
||||||
id: int
|
id: int
|
||||||
name1: str
|
name: str
|
||||||
name2: str
|
participant_id: int
|
||||||
|
lock: bool
|
||||||
|
created: datetime
|
||||||
|
modified: datetime
|
||||||
id = fields.Int()
|
id = fields.Int()
|
||||||
name1 = fields.String()
|
name = fields.String()
|
||||||
name2 = fields.String()
|
participant_id = fields.Int()
|
||||||
|
lock = fields.Bool()
|
||||||
|
created = fields.DateTime()
|
||||||
|
modified = fields.DateTime()
|
||||||
|
|
||||||
class Error(Schema):
|
class Error(Schema):
|
||||||
message = fields.String(required=True,)
|
message = fields.String(required=True,)
|
||||||
@ -31,14 +40,29 @@ class Notification(Schema):
|
|||||||
timestamp = fields.DateTime()
|
timestamp = fields.DateTime()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class Participant(Schema):
|
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()
|
id = fields.Int()
|
||||||
name = fields.String()
|
name = fields.String()
|
||||||
postal_code = fields.String(data_key="postal code",)
|
|
||||||
street = fields.String()
|
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):
|
class Shipcall(Schema):
|
||||||
description = fields.String()
|
description = fields.String()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user