123456789101112131415161718192021222324252627282930313233343536373839 |
- """
- Provides general routes.
- """
- from flask import jsonify
- from piket_server.flask import app
- from piket_server.models import Consumption
- @app.route("/ping")
- def ping() -> str:
- """ Return a status ping. """
- return "Pong"
- @app.route("/status")
- def status():
- """ Return a status dict with info about the database. """
- unsettled_q = Consumption.query.filter_by(settlement=None).filter_by(reversed=False)
- unsettled = unsettled_q.count()
- first = None
- last = None
- if unsettled:
- last = (
- unsettled_q.order_by(Consumption.created_at.desc())
- .first()
- .created_at.isoformat()
- )
- first = (
- unsettled_q.order_by(Consumption.created_at.asc())
- .first()
- .created_at.isoformat()
- )
- return jsonify({"unsettled": {"amount": unsettled, "first": first, "last": last}})
|