Skip to content
Snippets Groups Projects
Select Git revision
  • a039609b9da9d765fb1229ff2ed84cb00214efb5
  • master default protected
  • compose
  • dockerservices
  • simpleservices
  • hotsource
6 results

bookings.py

Blame
  • Forked from COM3014 / microservices
    1 commit behind the upstream repository.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    bookings.py 801 B
    from services import root_dir, nice_json
    from flask import Flask
    import json
    from werkzeug.exceptions import NotFound
    
    
    app = Flask(__name__)
    
    with open("{}/database/bookings.json".format(root_dir()), "r") as f:
        bookings = json.load(f)
    
    
    @app.route("/", methods=['GET'])
    def hello():
        return nice_json({
            "uri": "/",
            "subresource_uris": {
                "bookings": "/bookings",
                "booking": "/bookings/<username>"
            }
        })
    
    
    @app.route("/bookings", methods=['GET'])
    def booking_list():
        return nice_json(bookings)
    
    
    @app.route("/bookings/<username>", methods=['GET'])
    def booking_record(username):
        if username not in bookings:
            raise NotFound
    
        return nice_json(bookings[username])
    
    if __name__ == "__main__":
        app.run(port=5003, debug=True)