From 52acb063dd83c7856d5c8d2be9618ea2000d4470 Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Thu, 25 Feb 2021 22:45:12 -0500 Subject: Add history route --- poller/__init__.py | 1 + poller/models.py | 19 +++++++++++++++++++ poller/routes.py | 7 +++++++ 3 files changed, 27 insertions(+) create mode 100644 poller/routes.py diff --git a/poller/__init__.py b/poller/__init__.py index c0c25c0..1e1580b 100644 --- a/poller/__init__.py +++ b/poller/__init__.py @@ -30,5 +30,6 @@ APP.logger.info('SQLAlchemy pointed at ' + repr(db.engine.url)) #pylint: disable=wrong-import-position from . import models from . import commands +from . import routes db.create_all() diff --git a/poller/models.py b/poller/models.py index a5dd2fa..15b223d 100644 --- a/poller/models.py +++ b/poller/models.py @@ -32,3 +32,22 @@ class Day(db.Model): Helper to get all values from the database """ return cls.query.all() + + def serialize(self): + """ + used for json serialization + """ + return { + 'last_updated': self.last_updated, + 'alert_level': self.alert_level, + 'beds_available': self.beds_available, + 'isolation_off_campus': self.isolation_off_campus, + 'isolation_on_campus': self.isolation_on_campus, + 'new_staff': self.new_staff, + 'new_students': self.new_students, + 'quarantine_off_campus': self.quarantine_off_campus, + 'quarantine_on_campus': self.quarantine_on_campus, + 'tests_administered': self.tests_administered, + 'total_staff': self.total_staff, + 'total_students': self.total_students, + } diff --git a/poller/routes.py b/poller/routes.py new file mode 100644 index 0000000..4c0010b --- /dev/null +++ b/poller/routes.py @@ -0,0 +1,7 @@ +from flask import Flask, jsonify +from . import APP +from .models import Day + +@APP.route('/api/v0/history') +def _get_api_v0_history(): + return jsonify([day.serialize() for day in Day.get_all()]) -- cgit v1.2.3