Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nn #3703

Open
wants to merge 56 commits into
base: master
Choose a base branch
from
Open

nn #3703

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d82efca
Update README.md
Favouridowu02 Sep 5, 2024
2b64173
Update README.md
Favouridowu02 Sep 5, 2024
d8afe06
Made little changes to the file_storage engine
Favouridowu02 Sep 6, 2024
802de92
Merge pull request #1 from Favouridowu02/storage_get_count
Favouridowu02 Sep 6, 2024
cc48034
Made the file_storage compatable
Favouridowu02 Sep 6, 2024
11bd34a
Merge pull request #2 from Favouridowu02/storage_get_count
Favouridowu02 Sep 6, 2024
977364e
Updated the DBstorage Engine
Favouridowu02 Sep 6, 2024
68f4b61
Merge pull request #3 from Favouridowu02/storage_get_count
Favouridowu02 Sep 6, 2024
f3cbbba
Made the DBStorage pycodestyle complaint
Favouridowu02 Sep 6, 2024
2d4f7d6
Made the DBStorage pycodestyle complaint
Favouridowu02 Sep 6, 2024
b8ea506
Handled an egde case in the get method of DBStorage
Favouridowu02 Sep 6, 2024
abd8a6e
Merge pull request #4 from Favouridowu02/storage_get_count
Favouridowu02 Sep 6, 2024
6ffdeb8
Handled an egde case in the get method of FileStorage
Favouridowu02 Sep 6, 2024
cf66212
Merge pull request #5 from Favouridowu02/storage_get_count
Favouridowu02 Sep 6, 2024
1f57570
Updated the test cases for the FileStorage and DBStorage Engine
Favouridowu02 Sep 6, 2024
3c98e91
Merge pull request #6 from Favouridowu02/storage_get_count
Favouridowu02 Sep 6, 2024
6fe8fac
Implemented the layout for the api of the Airbnb Clone project
Favouridowu02 Sep 7, 2024
b1aae5a
Merge pull request #7 from Favouridowu02/storage_get_count
Favouridowu02 Sep 7, 2024
0502a47
Implemented the layout for the api of the Airbnb Clone project
Favouridowu02 Sep 7, 2024
7fb63ba
Merge pull request #8 from Favouridowu02/storage_get_count
Favouridowu02 Sep 7, 2024
83f92c1
Made the app and index pycodestyle
Favouridowu02 Sep 7, 2024
d9a55e0
Merge pull request #9 from Favouridowu02/storage_get_count
Favouridowu02 Sep 7, 2024
573f999
Made the app and index pycodestyle
Favouridowu02 Sep 7, 2024
8aeff16
Merge pull request #10 from Favouridowu02/storage_get_count
Favouridowu02 Sep 7, 2024
fc75080
Implemented the /api/v1/stats route. This Route returns the number of…
Favouridowu02 Sep 7, 2024
9ca2bc1
Merge pull request #11 from Favouridowu02/storage_get_count
Favouridowu02 Sep 7, 2024
be74b49
Made few changes to the index.py module to handle some edge cases
Favouridowu02 Sep 7, 2024
bff7733
Implemented the 404 route to return a jsonify object
Favouridowu02 Sep 7, 2024
86029f3
made a little tweak to the app module by turning off the debug
Favouridowu02 Sep 7, 2024
81b3bcf
Updated the the app module to handle the 404 page more efficiently
Favouridowu02 Sep 8, 2024
ca713e9
Made little tweaks while trying to fix the error bugs
Favouridowu02 Sep 8, 2024
2feaf06
Made little tweaks to the gile ti make the json file to be pretty for…
Favouridowu02 Sep 8, 2024
4b7fe15
Implemented a state route that performs a CRUD operation:
Favouridowu02 Sep 10, 2024
093521c
Merge pull request #12 from Favouridowu02/main
Favouridowu02 Sep 10, 2024
64dc84d
-
Favouridowu02 Sep 11, 2024
49ccd8c
Included the Amenity route, But yet to configure
Favouridowu02 Sep 12, 2024
6b39057
Made Little changes to the app model
Favouridowu02 Sep 12, 2024
58fffb8
Merge pull request #13 from Favouridowu02/main
Favouridowu02 Sep 12, 2024
86ae2af
Updated the api.v1.views.cities module.
Favouridowu02 Sep 12, 2024
347d4dc
Updated the api.v1.views.cities module.
Favouridowu02 Sep 12, 2024
7f2df77
Updated the api.v1.views.cities module.
Favouridowu02 Sep 12, 2024
f53fa95
Updated the api.v1.views.cities module.
Favouridowu02 Sep 12, 2024
5ce693c
Made little changes tto the api.v1.views.cities model
Favouridowu02 Sep 13, 2024
76f5ce3
-
Favouridowu02 Sep 15, 2024
8af3c46
Implemented the Amenity Route
Favouridowu02 Sep 18, 2024
c49d57f
Implemented the Amenity Route
Favouridowu02 Sep 18, 2024
70ef794
Implemented the Amenity Route
Favouridowu02 Sep 18, 2024
4ddd79b
Updated the amenity API:
Favouridowu02 Sep 19, 2024
777679d
Updated the amenity model:
Favouridowu02 Sep 19, 2024
a47118f
Made the api pycodestyle comply able
Favouridowu02 Sep 19, 2024
881945a
Updated the api/v1/amenity model api:
Favouridowu02 Sep 19, 2024
81e4530
Added the user.py in route '/api/v1/user'
Favouridowu02 Sep 26, 2024
da9ff29
Added the Place api route
Favouridowu02 Sep 27, 2024
9d1697b
Added the Place api route
Favouridowu02 Sep 27, 2024
a0226c1
Just made ffew changes to some api model
Favouridowu02 Sep 28, 2024
6a58dbe
Added the api model for the review model
Favouridowu02 Sep 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ No known bugs at this time.
Alexa Orrico - [Github](https://github.com/alexaorrico) / [Twitter](https://twitter.com/alexa_orrico)
Jennifer Huang - [Github](https://github.com/jhuang10123) / [Twitter](https://twitter.com/earthtojhuang)

Favour Idowu - [Github](https://github.com/favouridowu02) / [Twitter](https://twitter.com/favour_eng)

Second part of Airbnb: Joann Vuong
## License
Public Domain. No copy write protection.
18 changes: 18 additions & 0 deletions Testing/main_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/python3
"""Testing file
"""
import json
import requests

if __name__ == "__main__":
r = requests.get("http://0.0.0.0:5050/api/v1/amenities")
r_j = r.json()
print(type(r_j))
print(len(r_j))
for amenity_j in r_j:
if amenity_j.get('name') in ["Wifi", "Ethernet", "Soap", "Bed"]:
print("OK")
else:
print("Missing: {}".format(amenity_j.get('name')))
if amenity_j.get('id') is None:
print("Missing ID for Amenity: {}".format(amenity_j.get('name')))
20 changes: 20 additions & 0 deletions Testing/main_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/python3
"""Testing file
"""
import json
import requests

if __name__ == "__main__":
""" Get one amenity
"""
r = requests.get("http://0.0.0.0:5050/api/v1/amenities")
r_j = r.json()
amenity_id = r_j[0].get('id')

""" GET /api/v1/amenities/<amenity_id>
"""
r = requests.get("http://0.0.0.0:5050/api/v1/amenities/{}".format(amenity_id))
print(r.status_code)
r_j = r.json()
print(r_j.get('id') == amenity_id)
print(r_j.get('name') is None)
27 changes: 27 additions & 0 deletions Testing/main_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/python3
"""Testing file
"""
import json
import requests

if __name__ == "__main__":
""" Get one amenity
"""
r = requests.get("http://0.0.0.0:5050/api/v1/amenities")
r_j = r.json()
amenity_id = r_j[0].get('id')

""" DELETE /api/v1/amenities/<amenity_id>
"""
r = requests.delete("http://0.0.0.0:5050/api/v1/amenities/{}".format(amenity_id))
print(r.status_code)

""" Verify if the deleted amenity is not present anymore
"""
r = requests.get("http://0.0.0.0:5050/api/v1/amenities")
r_j = r.json()
for amenity_j in r_j:
if amenity_j.get('id') == amenity_id:
print("amenitie is not deleted")
else:
print("OK")
14 changes: 14 additions & 0 deletions Testing/main_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/python3
"""Testing file
"""
import json
import requests

if __name__ == "__main__":
""" POST /api/v1/amenities/
"""
r = requests.post("http://0.0.0.0:5050/api/v1/amenities/", data=json.dumps({ 'name': "Fridge" }), headers={ 'Content-Type': "application/json" })
print(r.status_code)
r_j = r.json()
print(r_j.get('id') is None)
print(r_j.get('name') == "Fridge")
11 changes: 11 additions & 0 deletions Testing/main_5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/python3
"""Testing file
"""
import json
import requests

if __name__ == "__main__":
""" POST /api/v1/amenities
"""
r = requests.post("http://0.0.0.0:5050/api/v1/amenities/", data={ 'name': "Fridge" }, headers={ 'Content-Type': "application/x-www-form-urlencoded" })
print(r.status_code)
11 changes: 11 additions & 0 deletions Testing/main_6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/python3
"""Testing file
"""
import json
import requests

if __name__ == "__main__":
""" POST /api/v1/amenities
"""
r = requests.post("http://0.0.0.0:5050/api/v1/amenities/", data=json.dumps({ 'fake_name': "Fridge" }), headers={ 'Content-Type': "application/json" })
print(r.status_code)
29 changes: 29 additions & 0 deletions Testing/main_7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/python3
"""Testing file
"""
import json
import requests

if __name__ == "__main__":
""" Get one amenity
"""
r = requests.get("http://0.0.0.0:5050/api/v1/amenities")
r_j = r.json()
amenity_id = r_j[0].get('id')

""" PUT /api/v1/amenities/<amenity_id>
"""
r = requests.put("http://0.0.0.0:5050/api/v1/amenities/{}".format(amenity_id), data=json.dumps({ 'name': "NewAmenityName" }), headers={ 'Content-Type': "application/json" })
print(r.status_code)
r_j = r.json()
print(r_j.get('id') == amenity_id)
print(r_j.get('name') == "NewAmenityName")

""" Verify if the state is updated
"""
r = requests.get("http://0.0.0.0:5050/api/v1/amenities")
r_j = r.json()
for amenity_j in r_j:
if amenity_j.get('id') == amenity_id:
print(amenity_j.get('name') == "NewAmenityName")

17 changes: 17 additions & 0 deletions Testing/main_8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/python3
"""Testing file
"""
import json
import requests

if __name__ == "__main__":
""" Get one amenity
"""
r = requests.get("http://0.0.0.0:5050/api/v1/amenities")
r_j = r.json()
amenity_id = r_j[0].get('id')

""" PUT /api/v1/amenities/<amenity_id>
"""
r = requests.put("http://0.0.0.0:5050/api/v1/amenities/{}".format(amenity_id), data={ 'name': "NewAmenityName" }, headers={ 'Content-Type': "application/x-www-form-urlencoded" })
print(r.status_code)
45 changes: 45 additions & 0 deletions Testing/places/main_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/python3
"""Testing file
"""
import json
import requests

if __name__ == "__main__":
""" get the state with cities
"""
r = requests.get("http://0.0.0.0:5050/api/v1/states")
r_j = r.json()

state_id = None
for state_j in r_j:
rs = requests.get("http://0.0.0.0:5050/api/v1/states/{}/cities".format(state_j.get('id')))
rs_j = rs.json()
if len(rs_j) != 0:
state_id = state_j.get('id')
break

if state_id is None:
print("State with cities not found")

""" get city
"""
r = requests.get("http://0.0.0.0:5050/api/v1/states/{}/cities".format(state_id))
r_j = r.json()
city_id = None
for city_j in r_j:
rc = requests.get("http://0.0.0.0:5050/api/v1/cities/{}/places".format(city_j.get('id')))
rc_j = rc.json()
if len(rc_j) == 0:
city_id = city_j.get('id')
break

if city_id is None:
print("City without places not found")


""" Fetch places
"""
r = requests.get("http://0.0.0.0:5050/api/v1/cities/{}/places".format(city_id))
r_j = r.json()
print(type(r_j))
print(len(r_j))
Binary file added __pycache__/console.cpython-310.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions api.pid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
106561
Empty file added api/__init__.py
Empty file.
Binary file added api/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Empty file added api/v1/__init__.py
Empty file.
Binary file added api/v1/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added api/v1/__pycache__/app.cpython-310.pyc
Binary file not shown.
38 changes: 38 additions & 0 deletions api/v1/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/python3
"""
This Module Contains the api using flask
"""
from flask import Flask, jsonify
from os import getenv
from models import storage
from api.v1.views import app_views

app = Flask(__name__)

app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
app.register_blueprint(blueprint=app_views)


@app.route('/')
def home():
return "Home"


@app.errorhandler(404)
def page_not_found(error):
return jsonify({"error": "Not found"}), 404


@app.teardown_appcontext
def close(exception=True):
return storage.close()


if __name__ == "__main__":
HBNB_API_HOST = getenv("HBNB_API_HOST")
HBNB_API_PORT = getenv("HBNB_API_PORT")
if not getenv("HBNB_API_HOST"):
HBNB_API_HOST = '0.0.0.0'
if not getenv("HBNB_API_PORT"):
HBNB_API_PORT = '5000'
app.run(host=HBNB_API_HOST, port=HBNB_API_PORT, threaded=True, debug=True)
20 changes: 20 additions & 0 deletions api/v1/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/python3
"""
This Module contains the v1 of the api

Content:
app_views = A Blueprint with prefix /api/v1
"""
from flask import Blueprint

app_views = Blueprint('app_views', __name__, url_prefix='/api/v1')

from api.v1.views.index import *
from api.v1.views.states import *
from api.v1.views.cities import *
from api.v1.views.amenities import *
from api.v1.views.users import *
from api.v1.views.places import *
from api.v1.views.places_reviews import *

# print("\n\n",app_views)
Binary file added api/v1/views/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file added api/v1/views/__pycache__/cities.cpython-310.pyc
Binary file not shown.
Binary file added api/v1/views/__pycache__/index.cpython-310.pyc
Binary file not shown.
Binary file added api/v1/views/__pycache__/places.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file added api/v1/views/__pycache__/states.cpython-310.pyc
Binary file not shown.
Binary file added api/v1/views/__pycache__/users.cpython-310.pyc
Binary file not shown.
92 changes: 92 additions & 0 deletions api/v1/views/amenities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/python3
"""
This Module contains all the Amenities Routes
"""
from api.v1.views import app_views
from models.amenity import Amenity
from models import storage
from flask import abort, jsonify, request


@app_views.route('/amenities', strict_slashes=True, methods=['GET'])
@app_views.route('/amenities/<amenity_id>', strict_slashes=True,
methods=['GET'])
def get_amenities(amenity_id=None):
"""
This Method returns all the Amenities

Arguments:
amenity_id: the amenity Id to be returned or None.

Return:
this method returns the amenity value to be returned or All
if the amenit_id is None.
"""
amenities = []
if amenity_id is None:
for amenity in storage.all(Amenity).values():
amenities.append(amenity.to_dict())
return jsonify(amenities), 200
else:
amenity = storage.get(Amenity, amenity_id)
if not amenity:
abort(404)
return jsonify(amenity.to_dict()), 200


@app_views.route('/amenities/<amenity_id>', strict_slashes=True,
methods=['DELETE'])
def delete_amenity(amenity_id):
"""
This Method deletes the amenity instance
"""
amenity = storage.get(Amenity, amenity_id)
if not amenity:
abort(404)
storage.delete(amenity)
storage.save()
return jsonify({}), 200


@app_views.route('/amenities/', strict_slashes=True, methods=['POST'])
def post_amenity():
"""
This method creates an instances of amenities
"""
if request.content_type != 'application/json':
return jsonify({"error": "Not a JSON"}), 400
data = request.get_json()
if "name" not in data.keys():
return jsonify({"error": "Missing name"}), 400
new_amenity = Amenity(**data)
storage.new(new_amenity)
storage.save()
return jsonify(new_amenity.to_dict()), 201


@app_views.route('/amenities/<amenity_id>', strict_slashes=True,
methods=['PUT'])
def put_amenity(amenity_id):
"""
This method creates Updates the Attributes of an instance of a class

Argument:
amenity_id: This is the amenity id
Return: a jsonify object of the updated instance with a status code of
200 when succesful
"""
amenity = storage.get(Amenity, amenity_id)
if not amenity:
abort(404)
if request.content_type != "application/json":
return jsonify({"error": "Not a JSON"}), 400
data = request.get_json()
if not data:
return jsonify({"error": "Not a JSON"}), 400
if "name" not in data:
return jsonify({"error": "Missing name"}), 400
for key, value in data.items():
if key not in ["id", "created_at", "updated_at"]:
setattr(amenity, key, value)
amenity.save()
return jsonify(amenity.to_dict()), 200
Loading