GetPreviousAndNextFile.py 725 B

1234567891011121314151617181920212223242526272829303132
  1. from flask import abort, jsonify
  2. from flask.views import View
  3. from pycs.database.Database import Database
  4. class GetPreviousAndNextFile(View):
  5. """
  6. return the previous and the next file
  7. """
  8. # pylint: disable=arguments-differ
  9. methods = ['GET']
  10. def __init__(self, db: Database):
  11. # pylint: disable=invalid-name
  12. self.db = db
  13. def dispatch_request(self, file_id: int):
  14. # get file from database
  15. file = self.db.file(file_id)
  16. if file is None:
  17. return abort(404)
  18. # get previous and next
  19. result = {
  20. 'previous': file.previous(),
  21. 'next': file.next()
  22. }
  23. # return data
  24. return jsonify(result)