Commit b244e650 authored by cst's avatar cst
Browse files

added endpoint to get last entry

parent 4dc7a101
from web.helpers.db import Db
from web.helpers.utils import Utils
from web.helpers.scaling import Scaling
from itertools import groupby
import arrow
from web.helpers.processing import Scale, Calculate, Convert
class LastEntryPostHandler:
def __init__(self):
pass
def get_validation_rules(self):
rules = [
{'name': 'id', 'required': True, 'type': str}
]
return rules
def handle(self, model):
values = []
sql = """
select to_char(o.to_time,'yyyy-mm-dd HH24:mi:ss') as to_time
from sampling_points s, observing_capabilities o
where s.id = o.sampling_point_id
and s.logger_id = %(id)s
"""
sp = Db.fetchone(sql, model)
return sp
\ No newline at end of file
......@@ -2,6 +2,7 @@ from flask import Blueprint
from web.helpers.user import User
from web.api.imports.observations.observations_post_handler import ObservationsPostHandler
from web.api.imports.observations.logger_post_handler import LoggerPostHandler
from web.api.imports.observations.lastentry_post_handler import LastEntryPostHandler
from web.helpers.model_binder import ModelBinder as Binder
from werkzeug.exceptions import InternalServerError, BadRequest
......@@ -26,7 +27,7 @@ def observations_get():
@obs.route("/imports/logger", methods=['POST'])
@User.basicauth_required
def logger_get():
def logger_post():
loggerHandler = LoggerPostHandler()
obsHandler = ObservationsPostHandler()
loggerModel = Binder.bind_and_validate(loggerHandler.get_validation_rules())
......@@ -42,4 +43,20 @@ def logger_get():
except Exception as e:
raise InternalServerError(description=str(e))
@obs.route("/imports/logger", methods=['GET'])
@User.basicauth_required
def logger_get():
lastEntryHandler = LastEntryPostHandler()
model = Binder.bind_and_validate(lastEntryHandler.get_validation_rules())
try:
lastentry = lastEntryHandler.handle(model)
if lastentry is None:
raise BadRequest(description="Logger id not found")
return Responses.json({"lastEntry": lastentry["to_time"]})
except Exception as e:
raise InternalServerError(description=str(e))
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