aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2021-02-25 22:45:12 -0500
committerGalen Guyer <galen@galenguyer.com>2021-02-25 22:45:12 -0500
commit52acb063dd83c7856d5c8d2be9618ea2000d4470 (patch)
treef12099c0f83e58e350f2733361c7cf0e8a07b080
parent51079aa249b509e9160dd675fed13b3bacda661c (diff)
Add history route
-rw-r--r--poller/__init__.py1
-rw-r--r--poller/models.py19
-rw-r--r--poller/routes.py7
3 files changed, 27 insertions, 0 deletions
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()])