Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
ab544cd
get and count
lensonlovescode Feb 14, 2025
ff89d59
Storage get count
lensonlovescode Feb 14, 2025
3cdd101
Storage get count more corrections
lensonlovescode Feb 14, 2025
33d5e20
app.py
lensonlovescode Feb 15, 2025
c97db43
init
lensonlovescode Feb 15, 2025
99d013a
READMEs
lensonlovescode Feb 15, 2025
7222b36
Hesitate a bit
lensonlovescode Feb 15, 2025
8ca4d3e
pymysql
lensonlovescode Feb 15, 2025
9b5684e
Corrections
lensonlovescode Feb 15, 2025
81c3d0b
Executables
lensonlovescode Feb 15, 2025
f33d1e9
Let's try that again
lensonlovescode Feb 15, 2025
1535e5c
changes not found
dmuchai Feb 15, 2025
1de1eec
Task 7. City
dmuchai Feb 15, 2025
1cbeeaf
changes on cities
dmuchai Feb 15, 2025
91a1c32
update task cities
dmuchai Feb 15, 2025
118554a
update task cities init
dmuchai Feb 15, 2025
3cfa00e
changes to states
dmuchai Feb 16, 2025
d47f23c
changes to states obj
dmuchai Feb 16, 2025
34e3e96
changes to states obj
dmuchai Feb 16, 2025
047580a
Update to state objt
dmuchai Feb 16, 2025
60b3bbc
updates to task 7 cities
dmuchai Feb 16, 2025
2ea869f
Amenitites api
lensonlovescode Feb 16, 2025
58aaa0e
Executable
lensonlovescode Feb 16, 2025
09e993e
Let's try again
lensonlovescode Feb 16, 2025
21544e8
updated init
dmuchai Feb 16, 2025
f2d01c9
updated init
dmuchai Feb 16, 2025
9b56e9c
update on init
dmuchai Feb 16, 2025
f6b8b97
pycache
lensonlovescode Feb 16, 2025
acbb78d
update tasks
dmuchai Feb 16, 2025
07a55cb
Merge branch 'master' of https://github.com/lensonlovescode/AirBnB_cl…
dmuchai Feb 16, 2025
8bde63c
update tasks6
dmuchai Feb 16, 2025
6c679ee
update tasks7
dmuchai Feb 16, 2025
ccaa84f
update tasks
dmuchai Feb 16, 2025
97b328e
update tasks67
dmuchai Feb 16, 2025
0fbf400
update gitignore
dmuchai Feb 16, 2025
a9bc501
users
lensonlovescode Feb 16, 2025
14972a7
users init
lensonlovescode Feb 16, 2025
143a1e5
updates on init file
dmuchai Feb 16, 2025
b79f2db
updates to places
dmuchai Feb 16, 2025
f76ed11
update task 10 place
dmuchai Feb 16, 2025
37ae4fa
tests
lensonlovescode Feb 16, 2025
9d2dcc4
Authors, Readme
lensonlovescode Feb 16, 2025
4fd1338
Ignore __pycache__ directories
dmuchai Feb 16, 2025
b18fffd
Strict Slashes
lensonlovescode Feb 17, 2025
f1de84b
Documentation
lensonlovescode Feb 17, 2025
eda6a48
Let's try again
lensonlovescode Feb 17, 2025
09b80fe
amenities API
lensonlovescode Feb 17, 2025
49d6238
init, the problem
lensonlovescode Feb 17, 2025
d4a4499
init, the problems, solved?
lensonlovescode Feb 17, 2025
cd3dbc0
Changed the order of imports
lensonlovescode Feb 17, 2025
3d18173
Changed the order of import
lensonlovescode Feb 17, 2025
fa3b2aa
Removed datetime immport
lensonlovescode Feb 17, 2025
4cef0b3
Removed amenities
lensonlovescode Feb 17, 2025
3f3d8fb
Added users
lensonlovescode Feb 17, 2025
f18cef9
update changes
dmuchai Feb 17, 2025
369d801
Corrections
lensonlovescode Feb 17, 2025
a8f89aa
Removed users
lensonlovescode Feb 17, 2025
a7af20e
setattr corrections
lensonlovescode Feb 17, 2025
d61175d
updated user
lensonlovescode Feb 17, 2025
6a2e9e0
CORS
lensonlovescode Feb 17, 2025
d2e1733
More documentation
lensonlovescode Feb 17, 2025
2404832
Document
lensonlovescode Feb 17, 2025
20d89ee
Documentation
lensonlovescode Feb 17, 2025
ab48f63
Task 11. Reviews
dmuchai Feb 17, 2025
acfb639
Task 11. Reviews
dmuchai Feb 17, 2025
6b454e4
place reviews
lensonlovescode Feb 17, 2025
829e1f3
place review
lensonlovescode Feb 17, 2025
1742668
Task 15. Search
dmuchai Feb 18, 2025
54c073c
updates to places
dmuchai Feb 18, 2025
96133e3
updates to file storage
dmuchai Feb 18, 2025
c9f4b1e
updates to test db storage
dmuchai Feb 18, 2025
2d0186a
updates to test dbstorage
dmuchai Feb 18, 2025
3925d97
updates to states api
dmuchai Feb 18, 2025
d7b5b8a
update task 6. State
dmuchai Feb 18, 2025
116fff6
Updates for task 7. City
dmuchai Feb 18, 2025
9c17c77
Updates for task 7.City
dmuchai Feb 18, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hbnbv3_venv/
hbnb_venv/
*.pyc
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file lists all individuals having contributed content to the repository.


Lenson Mutugi <lensonisinparis@gmail.com>
Jennifer Huang <133@holbertonschool.com>
Alexa Orrico <210@holbertonschool.com>
Joann Vuong <130@holbertonschool.com>
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# AirBnB Clone - The Console
The console is the first segment of the AirBnB project at Holberton School that will collectively cover fundamental concepts of higher level programming. The goal of AirBnB project is to eventually deploy our server a simple copy of the AirBnB Website(HBnB). A command interpreter is created in this segment to manage objects for the AirBnB(HBnB) website.
# AirBnB Clone

The goal of AirBnB project is to eventually deploy our server a simple copy of the AirBnB Website(HBnB).
A command interpreter is created to manage objects for the AirBnB(HBnB) website.
A fron-end is built using HTML and CSS
A database is created and mapped to objects using sqlalchemy
Flask is used as the first method to expose the backend to the frontend
A RESTful API is built as a second methos to expose the backend to the frontend

#### Functionalities of this command interpreter:
* Create a new object (ex: a new User or a new Place)
Expand Down Expand Up @@ -154,6 +160,7 @@ EOF all create destroy help quit show update
No known bugs at this time.

## Authors
Lenson Mutugi - [Github](https://github.com/lensonlovescode) / [Twitter](https://github.com/alexaorrico)
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)

Expand Down
1 change: 1 addition & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This Directory contins restful api work for the AirBnB clone project
Empty file added api/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions api/v1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This Directory contins restful api work for the AirBnB clone project
An app that comprises of flask blueprints for managing AirBnB assets
Empty file added api/v1/__init__.py
Empty file.
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
"""
Creates a flask app comprising many flask blueprints
as part of api building
"""
from flask import Flask, jsonify
from models import storage
from api.v1.views import app_views
from os import getenv


app = Flask(__name__)
app.register_blueprint(app_views)


@app.teardown_appcontext
def close_db_session(exception=None):
"""
Closes the database session
"""
storage.close()


@app.errorhandler(404)
def not_found(error):
"""
Handle 404 errors and return JSON response
"""
return jsonify({"error": "Not found"}), 404


if __name__ == '__main__':

host = getenv('HBNB_API_HOST', default='0.0.0.0')
port = int(getenv('HBNB_API_PORT', default=5000))
app.run(host=host, port=port, threaded=True)
2 changes: 2 additions & 0 deletions api/v1/views/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*~
__pycache__/
1 change: 1 addition & 0 deletions api/v1/views/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This Directory contins restful api work for the AirBnB clone project
17 changes: 17 additions & 0 deletions api/v1/views/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/python3
"""
Contains a python script that creates a flask blueprint
named app_views as part of a larger flask application
contains the folllowing views: index, states, cities
amenities, uusers and places
"""
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.users import *
from api.v1.views.places import *
from api.v1.views.places_reviews import *
100 changes: 100 additions & 0 deletions api/v1/views/amenities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/python3
"""
Creates API endpoints for acessing, creating, deleting and
updating Amenity resources, it uses the app_views blueprint
"""
from api.v1.views import app_views
from models import storage
from models.amenity import Amenity
from flask import jsonify, request, abort


@app_views.route('/amenities', strict_slashes=False,
methods=['GET'])
def get_amenities():
"""
Retrieves all amenity objects and returns the JSON
representation of the dictionary
"""
amenities = []
all_amenities = storage.all(Amenity)

for amenity in all_amenities.values():
amenities.append(amenity.to_dict())
return (jsonify(amenities))


@app_views.route('/amenities/<amenity_id>', strict_slashes=False,
methods=['GET'])
def get_an_amenity(amenity_id):
"""
Retrieves a specific amenity based on it's id
404 error if the amenity does not exist
"""
amenity = storage.get(Amenity, amenity_id)

if amenity is not None:
return (jsonify(amenity.to_dict()))
abort(404)


@app_views.route('/amenities/<amenity_id>', strict_slashes=False,
methods=['DELETE'])
def delete_amenity(amenity_id):
"""
Deletes an amenity based on it's id
Returns an empty dictionary plus 200ok status on success
or 404 error page on failure
"""
amenity = storage.get(Amenity, amenity_id)
if amenity is None:
abort(404)
storage.delete(amenity)
storage.save()

return (jsonify({})), 200


@app_views.route('/amenities', strict_slashes=False, methods=['POST'])
def create_amenity():
"""
Creates an amenity and returns the dictionary representation of the
amenity, or an error dictionary
"""
data = request.get_json()
if not isinstance(data, dict):
return (jsonify({'error': 'Not a JSON'}))
if 'name' not in data.keys():
return (jsonify({'error': 'Missing name'}))

name = data.get('name')
amenity = Amenity(name=f'{data.get('name')}')
storage.new(amenity)
storage.save()
return (jsonify(amenity.to_dict())), 201


@app_views.route('/amenities/<amenity_id>', strict_slashes=False,
methods=['PUT'])
def update_amenity(amenity_id):
"""
Updates an amenity based on the id, returns a code 201
on success or an error dictionary
"""
data = request.get_json()

if not isinstance(data, dict):
return (jsonify({'error': 'Not a JSON'}))

amenity = storage.get(Amenity, amenity_id)

if amenity is None:
abort(404)

exclude = ['id', 'created_at', 'updated_at']
for k, v in data.items():
if k not in exclude:
setattr(amenity, k, v,)

amenity.save()
return (jsonify(amenity.to_dict())), 200
103 changes: 103 additions & 0 deletions api/v1/views/cities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/python3
"""
Cities API view for handling RESTful actions
"""

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


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


@app_views.route('/cities/<city_id>', methods=['GET'], strict_slashes=False)
def get_city(city_id):
"""
Retrieve a single city identified by ID
"""
city = storage.get(City, city_id)
if not city:
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 new City in a given State
"""
state = storage.get(State, state_id)
if not state:
abort(404)

if request.content_type != 'application/json':
return jsonify({"error": "Not a JSON"}), 400

data = request.get_json()
if not data:
abort(400, description="Not a JSON")

if 'name' not in data:
abort(400, description="Missing name")

new_city = City(name=request.json['name'], state_id=state_id)
new_city.save()
return jsonify(new_city.to_dict()), 201


@app_views.route('/cities/<city_id>', methods=['PUT'], strict_slashes=False)
def update_city(city_id):
"""
Update a City object idenfified by valid city id
"""
city = storage.get(City, city_id)
if not city:
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

ignored_keys = ["id", "created_at", "updated_at"]
for key, value in data.items():
if key not in ignored_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):
"""
Delete a City object identified by city id
"""
city = storage.get(City, city_id)
if not city:
abort(404)

storage.delete(city)
storage.save()
return jsonify({}), 200
39 changes: 39 additions & 0 deletions api/v1/views/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/python3
"""
Contains app route for /status in the blueprint app_views
It returns an okay status code for the api
"""
from flask import jsonify
from api.v1.views import app_views
from models import storage
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


@app_views.route('/status', methods=['GET'])
def status():
"""
Returns the status of the api
"""
return (jsonify({'status': 'OK'}))


@app_views.route("/stats", methods=["GET"])
def stats():
"""
Returns the number of each object type
"""
classes = {
"amenities": Amenity,
"cities": City,
"places": Place,
"reviews": Review,
"states": State,
"users": User
}
counts = {key: storage.count(value) for key, value in classes.items()}
return jsonify(counts)
Loading