Skip to content
Snippets Groups Projects
Verified Commit b6147d25 authored by TheJoeCoder's avatar TheJoeCoder
Browse files

Implement /status endpoint

parent 6a7c4307
No related branches found
No related tags found
No related merge requests found
import json, uuid, logging, requests import json, uuid, logging, requests, time
from flask import Flask, request, jsonify, Response from flask import Flask, request, jsonify, Response
from pymongo import MongoClient from pymongo import MongoClient
...@@ -13,6 +13,8 @@ client = MongoClient(config.mongo_uri) ...@@ -13,6 +13,8 @@ client = MongoClient(config.mongo_uri)
db = client[config.mongo_db] db = client[config.mongo_db]
start_time = time.time()
with open("pizza_types.json","r") as f: with open("pizza_types.json","r") as f:
pizza_types = json.loads(f.read()) pizza_types = json.loads(f.read())
...@@ -42,6 +44,11 @@ def hello_world(): ...@@ -42,6 +44,11 @@ def hello_world():
# Return OK message # Return OK message
return "{\"status\":200, \"message\": \"ok\"}", 200 return "{\"status\":200, \"message\": \"ok\"}", 200
@app.route("/status", methods=["GET"])
def get_status():
# Return status
return "{\"status\":200, \"message\": \"ok\", \"uptime\": " + str(time.time() - start_time) + "}", 200
@app.route("/pizzas", methods=["GET"]) @app.route("/pizzas", methods=["GET"])
def get_pizzas(): def get_pizzas():
# Return pizza types # Return pizza types
...@@ -125,7 +132,7 @@ def add_cart_item(): ...@@ -125,7 +132,7 @@ def add_cart_item():
}) })
return "{\"status\":200, \"message\": \"ok\", \"items\": " + json.dumps(cart["items"]) + "}", 200 return "{\"status\":200, \"message\": \"ok\", \"items\": " + json.dumps(cart["items"]) + "}", 200
@app.route("/cart/total") @app.route("/cart/total", methods=["GET"])
def get_cart_total(): def get_cart_total():
# Get cart id and key from request # Get cart id and key from request
cart_id = request.args.get("id") cart_id = request.args.get("id")
...@@ -201,5 +208,6 @@ def confirm_order_cart(): ...@@ -201,5 +208,6 @@ def confirm_order_cart():
# Return order ID # Return order ID
return "{\"status\":200,\"message\":\"OK\", \"code\":\"" + str(order_id) + "\"}", 200 return "{\"status\":200,\"message\":\"OK\", \"code\":\"" + str(order_id) + "\"}", 200
# Main program code
if (__name__ == "__main__"): if (__name__ == "__main__"):
app.run(debug=True, host="0.0.0.0") app.run(debug=True, host="0.0.0.0")
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment