-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.py
executable file
·30 lines (24 loc) · 874 Bytes
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python3
""" Index """
from models.amenity import Amenity
from models.city import City
from models.place import Place
from models.review import Review
from models.state import State
from models.user import User
from models import storage
from api.v1.views import app_views
from flask import jsonify
@app_views.route('/status', methods=['GET'], strict_slashes=False)
def status():
""" Status of API """
return jsonify({"status": "OK"})
@app_views.route('/stats', methods=['GET'], strict_slashes=False)
def number_objects():
""" Retrieves the number of each objects by type """
classes = [Amenity, City, Place, Review, State, User]
names = ["amenities", "cities", "places", "reviews", "states", "users"]
num_objs = {}
for i in range(len(classes)):
num_objs[names[i]] = storage.count(classes[i])
return jsonify(num_objs)