Digitale bierlijst

general.py 896B

123456789101112131415161718192021222324252627282930313233343536373839
  1. """
  2. Provides general routes.
  3. """
  4. from flask import jsonify
  5. from piket_server.flask import app
  6. from piket_server.models import Consumption
  7. @app.route("/ping")
  8. def ping() -> str:
  9. """ Return a status ping. """
  10. return "Pong"
  11. @app.route("/status")
  12. def status():
  13. """ Return a status dict with info about the database. """
  14. unsettled_q = Consumption.query.filter_by(settlement=None).filter_by(reversed=False)
  15. unsettled = unsettled_q.count()
  16. first = None
  17. last = None
  18. if unsettled:
  19. last = (
  20. unsettled_q.order_by(Consumption.created_at.desc())
  21. .first()
  22. .created_at.isoformat()
  23. )
  24. first = (
  25. unsettled_q.order_by(Consumption.created_at.asc())
  26. .first()
  27. .created_at.isoformat()
  28. )
  29. return jsonify({"unsettled": {"amount": unsettled, "first": first, "last": last}})