Commit 9c1d1855 authored by cst's avatar cst
Browse files

moved loggerid into arr so it cant accept many ids

parent 92f1d252
......@@ -11,27 +11,33 @@ class LoggerPostHandler:
def get_validation_rules(self):
rules = [
{'name': 'id', 'required': True, 'type': str},
{'name': 'values', 'required': True, 'type': dict, 'action': 'append'}
]
return rules
def handle(self, model):
logger_ids = []
[logger_ids.append(obj["logger_id"]) or obj for obj in model["values"] if obj["logger_id"] not in logger_ids]
values = []
sql = """
select sp.id
select sp.id, sp.logger_id
from sampling_points sp
where sp.logger_id = %(id)s
where sp.logger_id in %(ids)s
"""
sp = Db.fetchone(sql, model)
sp = Db.fetchall(sql, {"ids": tuple(logger_ids)})
if sp is None:
if len(sp) == 0 or len(sp) != len(logger_ids):
return None
for m in model["values"]:
spid = [item for item in sp if item['logger_id'] == m["logger_id"]]
if(len(spid) == 0):
return None
v = {}
v["sampling_point_id"] = sp["id"]
v["sampling_point_id"] = spid[0]["id"]
v["begin_position"] = m["fromTime"]
v["end_position"] = m["toTime"]
v["value"] = m["value"]
......
......@@ -38,7 +38,7 @@ def logger_post():
raise InternalServerError(description=str(e))
if obsModel is None:
raise BadRequest(description="Logger id not found")
raise BadRequest(description="One or more logger id was not found")
try:
obsHandler.handle(obsModel)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment