Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
fe81163
Update README.md
ITSNE01 Feb 16, 2025
f38ad35
Update AUTHORS
ITSNE01 Feb 16, 2025
daa240e
Update airbnb clone v3
ITSNE01 Feb 16, 2025
c3b2c8e
exec
ITSNE01 Feb 16, 2025
e6186c9
pycode
ITSNE01 Feb 16, 2025
bb1524e
exec 2
ITSNE01 Feb 16, 2025
cc27741
edit
Mery16em Feb 16, 2025
fbc4e55
db_storage.py
ITSNE01 Feb 16, 2025
db22001
file_storage.py
ITSNE01 Feb 16, 2025
0df53b8
Merge branch 'storage_get_count' of https://github.com/ITSNE01/AirBnB…
Mery16em Feb 16, 2025
91febee
Merge pull request #1 from ITSNE01/storage_get_count
ITSNE01 Feb 16, 2025
7d556af
folder structure
Mery16em Feb 16, 2025
8b219f0
Merge branch 'master' of https://github.com/ITSNE01/AirBnB_clone_v3
Mery16em Feb 16, 2025
f0e0b07
merge master
Mery16em Feb 16, 2025
5afdfbf
exec
ITSNE01 Feb 16, 2025
806cdac
exec
ITSNE01 Feb 16, 2025
b82d38f
update index
Mery16em Feb 16, 2025
abffe64
Merge branch 'master' of https://github.com/ITSNE01/AirBnB_clone_v3
Mery16em Feb 16, 2025
d5c9caf
State
ITSNE01 Feb 17, 2025
b7378ba
State fix
ITSNE01 Feb 17, 2025
6ab7c54
state task
ITSNE01 Feb 17, 2025
1ec303a
City
ITSNE01 Feb 17, 2025
f154c65
update views
Mery16em Feb 17, 2025
e09a57b
update innit
Mery16em Feb 17, 2025
1d89fa3
update __innit
Mery16em Feb 17, 2025
1a8ce4e
updat amenities
Mery16em Feb 17, 2025
aae1f82
Merge branch 'master' of https://github.com/ITSNE01/AirBnB_clone_v3
Mery16em Feb 17, 2025
4ee20bd
Amenity
ITSNE01 Feb 17, 2025
4c5f0ba
update users
Mery16em Feb 17, 2025
31c925c
update innit
Mery16em Feb 17, 2025
81ad094
places
Mery16em Feb 17, 2025
f98939b
update init
Mery16em Feb 17, 2025
614061a
Reviews
ITSNE01 Feb 17, 2025
f6357d7
Place - Amenity
ITSNE01 Feb 17, 2025
fdcf5a6
Search
ITSNE01 Feb 17, 2025
9980d9b
Search fix
ITSNE01 Feb 17, 2025
b632310
Search fix
ITSNE01 Feb 17, 2025
8fa660c
dup
ITSNE01 Feb 21, 2025
7a36d35
Update README.md
ITSNE01 Feb 21, 2025
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: 1 addition & 1 deletion 1-pack_web_static.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def do_pack():
file_name = "versions/web_static_{}.tgz".format(date)
local("tar -cvzf {} web_static".format(file_name))
return file_name
except:
except Exception:
return None
2 changes: 1 addition & 1 deletion 2-do_deploy_web_static.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ def do_deploy(archive_path):
run('rm -rf /data/web_static/current')
run('ln -s {}{}/ /data/web_static/current'.format(path, no_ext))
return True
except:
except Exception:
return False
4 changes: 2 additions & 2 deletions 3-deploy_web_static.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def do_pack():
file_name = "versions/web_static_{}.tgz".format(date)
local("tar -cvzf {} web_static".format(file_name))
return file_name
except:
except Exception:
return None


Expand All @@ -40,7 +40,7 @@ def do_deploy(archive_path):
run('rm -rf /data/web_static/current')
run('ln -s {}{}/ /data/web_static/current'.format(path, no_ext))
return True
except:
except Exception:
return False


Expand Down
4 changes: 3 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@

Jennifer Huang <133@holbertonschool.com>
Alexa Orrico <210@holbertonschool.com>
Joann Vuong <130@holbertonschool.com>
Joann Vuong <130@holbertonschool.com>
Meryem Loutfi <ml.meryem.16@gmail.com>
Rabie Haddar <rabie.haddar1@gmail.com>
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,12 @@ EOF all create destroy help quit show update
No known bugs at this time.

## Authors
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)
Alexa Orrico - [Github](https://github.com/alexaorrico) / [X](https://X.com/alexa_orrico)
Jennifer Huang - [Github](https://github.com/jhuang10123) / [X](https://X.com/earthtojhuang)

Rabie Haddar - [Github](https://github.com/ITSNE01) - [X](https://x.com/HaddarRabie)

Meryem Loutfi - [Github](https://github.com/Mery16em) - [X](https://x.com/Myr3l)

Second part of Airbnb: Joann Vuong
## License
Expand Down
Binary file added __pycache__/console.cpython-38.pyc
Binary file not shown.
Empty file added api/__init__.py
Empty file.
Binary file added api/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Empty file added api/v1/__init__.py
Empty file.
Binary file added api/v1/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file added api/v1/__pycache__/app.cpython-38.pyc
Binary file not shown.
36 changes: 36 additions & 0 deletions api/v1/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/python3
"""Flask server (variable app)"""

from flask import Flask, jsonify
from models import storage
from os import getenv
from api.v1.views import app_views
from flask_cors import CORS

app = Flask(__name__)

CORS(app, resources={r"/*": {"origins": "0.0.0.0"}})
app.register_blueprint(app_views)
app.url_map.strict_slashes = False


@app.teardown_appcontext
def downtear(self):
"""A method that Closes the storage"""
storage.close()


@app.errorhandler(404)
def page_not_found(error):
"""This method is called if page not found"""
return jsonify({'error': 'Not found'}), 404


if __name__ == "__main__":
host = getenv('HBNB_API_HOST')
port = getenv('HBNB_API_PORT')
if not host:
host = '0.0.0.0'
if not port:
port = '5000'
app.run(host=host, port=port, threaded=True)
Binary file added api/v1/views/.index.py.swp
Binary file not shown.
15 changes: 15 additions & 0 deletions api/v1/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/python3
"""init file"""

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 *
from api.v1.views.places_amenities import *
67 changes: 67 additions & 0 deletions api/v1/views/amenities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/python3
""" Amenities """


from flask import abort, jsonify, request
from api.v1.views import app_views
from models.amenity import Amenity
from models import storage


@app_views.route('/amenities', methods=['GET'])
def get_amenities():
"""retrieve all amenities"""
amenities = storage.all(Amenity).values()
amenities_list = []
for amenity in amenities:
amenities_list.append(amenity.to_dict())
return jsonify(amenities_list)


@app_views.route('/amenities/<amenity_id>', methods=['GET'])
def get_amenity(amenity_id):
"""get amenity by id"""
amenity = storage.get(Amenity, amenity_id)
if amenity is None:
abort(404)
return jsonify(amenity.to_dict())


@app_views.route('/amenities/<amenity_id>', methods=['DELETE'])
def delete_amenity(amenity_id):
"""Deletes an Amenity object"""
amenity = storage.get(Amenity, amenity_id)
if amenity is None:
abort(404)
storage.delete(amenity)
storage.save()


@app_views.route('/amenities', methods=['POST'])
def create_amenity():
"""Creates an Amenity object"""
if not request.get_json():
abort(400, 'Not a JSON')
if 'name' not in request.get_json():
abort(400, 'Missing name')
amenity = Amenity(**request.get_json())
storage.new(amenity)
storage.save()
return jsonify(amenity.to_dict()), '201'


@app_views.route('/amenities/<amenity_id>', methods=['PUT'])
def update_amenity(amenity_id):
"""Updates an Amenity object"""
amenity = storage.get(Amenity, amenity_id)
if amenity is None:
abort(404)
if not request.get_json():
abort(400, 'Not a JSON')
payload = request.get_json()
ignore_keys = ['id', 'created_at', 'updated_at']
for key, value in payload.items():
if key not in ignore_keys:
setattr(amenity, key, value)
storage.save()
return jsonify(amenity.to_dict()), '200'
75 changes: 75 additions & 0 deletions api/v1/views/cities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/python3
""" Cities """

from flask import abort, jsonify, request
from api.v1.views import app_views
from models.city import City
from models.state import State
from models import storage


@app_views.route("/states/<state_id>/cities", methods=["GET"],
strict_slashes=False)
def get_cities(state_id):
"""retrieve all cities"""
state = storage.get(State, state_id)
if state is None:
abort(404)
cities = [city.to_dict() for city in state.cities]
return jsonify(cities)


@app_views.route("/cities/<city_id>", methods=["GET"], strict_slashes=False)
def get_city(city_id):
"""get city by id"""
city = storage.get(City, city_id)
if city is None:
abort(404)
return jsonify(city.to_dict())


@app_views.route("/states/<state_id>/cities", methods=["POST"],
strict_slashes=False)
def create_city(state_id):
"""create a State object"""
state = storage.get(State, state_id)
if state is None:
abort(404)
if not request.get_json():
abort(400, "Not a JSON")
if "name" not in request.get_json():
abort(400, "Missing name")
payload = request.get_json()
payload["state_id"] = state_id
city = City(**payload)
city.save()
return jsonify(city.to_dict()), 201


@app_views.route("/cities/<city_id>", methods=["PUT"], strict_slashes=False)
def update_city(city_id):
"""Update a State object"""
city = storage.get(City, city_id)
if city is None:
abort(404)
if not request.get_json():
abort(400, "Not a JSON")
payload = request.get_json()
ignore_keys = ["id", "state_id", "created_at", "updated_at"]
for key, value in payload.items():
if key not in ignore_keys:
setattr(city, key, value)
city.save()
return jsonify(city.to_dict()), '200'


@app_views.route("/cities/<city_id>", methods=["DELETE"],
strict_slashes=False)
def delete_city(city_id):
"""Deletes a City object"""
city = storage.get(City, city_id)
if city is None:
abort(404)
storage.delete(city)
storage.save()
return jsonify({}), '200'
29 changes: 29 additions & 0 deletions api/v1/views/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/python3xx
'''api status'''
import models
from models import storage
from models.base_model import BaseModel
from flask import jsonify
from api.v1.views import app_views


@app_views.route('/status', strict_slashes=False)
def returnstuff():
'''return stuff'''
return jsonify(status='OK')


@app_views.route('/stats', strict_slashes=False)
def get_stats():
'''JSON Responses'''
stats = {
'states': State,
'users': User,
'amenities': Amenity,
'cities': City,
'places': Place,
'reviews': Review
}
for key in stats:
stats[key] = storage.count(stats[key])
return jsonify(stats)
79 changes: 79 additions & 0 deletions api/v1/views/places.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/python3
""" Places """

from api.v1.views import app_views
from flask import jsonify, request, abort
from models import storage
from models.city import City
from models.place import Place
from models.user import User


@app_views.route('/cities/<city_id>/places',
methods=['GET'], strict_slashes=False)
def get_places(city_id):
"""Retrieve all places of a city"""
city = storage.get(City, city_id)
if not city:
abort(404)
places = [place.to_dict() for place in city.places]
return jsonify(places)


@app_views.route('/places/<place_id>', methods=['GET'], strict_slashes=False)
def get_place(place_id):
"""Retrieve a place"""
place = storage.get(Place, place_id)
if not place:
abort(404)
return jsonify(place.to_dict())


@app_views.route('/places/<place_id>',
methods=['DELETE'], strict_slashes=False)
def delete_place(place_id):
"""Deletes a place"""
place = storage.get(Place, place_id)
if not place:
abort(404)
storage.delete(place)
storage.save()
return jsonify({}), 200


@app_views.route('/cities/<city_id>/places',
methods=['POST'], strict_slashes=False)
def create_place(city_id):
"""Create a Place"""
payload = request.get_json()
if not payload:
abort(400, "Not a JSON")
city = storage.get(City, city_id)
if not city:
abort(404)
if 'user_id' not in payload:
abort(400, "Missing user_id")
user = storage.get(User, payload['user_id'])
if not user:
abort(404)
if 'name' not in payload:
abort(400, "Missing name")
place = Place(city_id=city_id, **payload)
place.save()
return jsonify(place.to_dict()), 201


@app_views.route('/places/<place_id>', methods=['PUT'], strict_slashes=False)
def update_place(place_id):
"""Updates a Place object"""
payload = request.get_json()
if not payload:
abort(400, "Not a JSON")
place = storage.get(Place, place_id)
if not place:
abort(404)
for key, value in payload.items():
if key not in ['id', 'user_id', 'city_id', 'created_at', 'updated_at']:
setattr(place, key, value)
place.save()
return jsonify(place.to_dict()), 200
Loading