From fae254c983657637530f452bbc0996c04891e2bc Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Tue, 6 Aug 2024 01:30:29 +0300 Subject: [PATCH 01/16] nw repo --- AUTHORS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 64b26acdc14..7a9ff72f4e4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,4 +3,5 @@ Jennifer Huang <133@holbertonschool.com> Alexa Orrico <210@holbertonschool.com> -Joann Vuong <130@holbertonschool.com> +Joann Vuong <130@holbertonschool.com> +Mark Manani From 01691841ce90b64be66f34d21c8eee1d849d13e8 Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Sun, 11 Aug 2024 23:16:22 +0300 Subject: [PATCH 02/16] api --- api/__init__.py | 0 api/v1/__init__.py | 0 api/v1/app.py | 20 ++++++++++++++++++++ api/v1/views/__init__.py | 9 +++++++++ api/v1/views/index.py | 10 ++++++++++ 5 files changed, 39 insertions(+) create mode 100644 api/__init__.py create mode 100644 api/v1/__init__.py create mode 100644 api/v1/app.py create mode 100644 api/v1/views/__init__.py create mode 100644 api/v1/views/index.py diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/api/v1/__init__.py b/api/v1/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/api/v1/app.py b/api/v1/app.py new file mode 100644 index 00000000000..024bc5faa7b --- /dev/null +++ b/api/v1/app.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 +"""Flask application""" + +from flask import Flask +from models import storage +from api.v1.views import app_views +import os + +app = Flask(__name__) +app.register_blueprint(app_views) + +@app.teardown_appcontext +def teardown(exception): + """Method to handle teardown, closing the storage""" + storage.close() + +if __name__ == "__main__": + host = os.getenv('HBNB_API_HOST', '0.0.0.0') + port = int(os.getenv('HBNB_API_PORT', 5000)) + app.run(host=host, port=port, threaded=True) diff --git a/api/v1/views/__init__.py b/api/v1/views/__init__.py new file mode 100644 index 00000000000..c377a044191 --- /dev/null +++ b/api/v1/views/__init__.py @@ -0,0 +1,9 @@ +#!/usr/bin/python3 +"""Blueprint setup""" + +from flask import Blueprint + +app_views = Blueprint('app_views', __name__, url_prefix='/api/v1') + +# Import routes so they are registered with the Blueprint +from api.v1.views.index import * diff --git a/api/v1/views/index.py b/api/v1/views/index.py new file mode 100644 index 00000000000..48f8d7aab71 --- /dev/null +++ b/api/v1/views/index.py @@ -0,0 +1,10 @@ +#!/usr/bin/python3 +"""Index route for the API""" + +from flask import jsonify +from api.v1.views import app_views + +@app_views.route('/status', methods=['GET']) +def status(): + """Returns the status of the API""" + return jsonify({"status": "OK"}) From e2b4c81ab39c007bf525c8218e3b2023f96917c8 Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Sun, 11 Aug 2024 23:25:05 +0300 Subject: [PATCH 03/16] pycode --- api/v1/app.py | 2 ++ api/v1/views/__init__.py | 5 ++--- api/v1/views/index.py | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/v1/app.py b/api/v1/app.py index 024bc5faa7b..1fe264fdea8 100644 --- a/api/v1/app.py +++ b/api/v1/app.py @@ -9,11 +9,13 @@ app = Flask(__name__) app.register_blueprint(app_views) + @app.teardown_appcontext def teardown(exception): """Method to handle teardown, closing the storage""" storage.close() + if __name__ == "__main__": host = os.getenv('HBNB_API_HOST', '0.0.0.0') port = int(os.getenv('HBNB_API_PORT', 5000)) diff --git a/api/v1/views/__init__.py b/api/v1/views/__init__.py index c377a044191..c26dea4a065 100644 --- a/api/v1/views/__init__.py +++ b/api/v1/views/__init__.py @@ -2,8 +2,7 @@ """Blueprint setup""" from flask import Blueprint +from api.v1.views.index import * -app_views = Blueprint('app_views', __name__, url_prefix='/api/v1') -# Import routes so they are registered with the Blueprint -from api.v1.views.index import * +app_views = Blueprint('app_views', __name__, url_prefix='/api/v1') diff --git a/api/v1/views/index.py b/api/v1/views/index.py index 48f8d7aab71..eda07bd47b5 100644 --- a/api/v1/views/index.py +++ b/api/v1/views/index.py @@ -4,6 +4,7 @@ from flask import jsonify from api.v1.views import app_views + @app_views.route('/status', methods=['GET']) def status(): """Returns the status of the API""" From 2263aa394804ba15cc6cca7d22c200c5198d4911 Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Sun, 11 Aug 2024 23:36:10 +0300 Subject: [PATCH 04/16] docs --- api/v1/views/index.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/v1/views/index.py b/api/v1/views/index.py index eda07bd47b5..85a89e51eb6 100644 --- a/api/v1/views/index.py +++ b/api/v1/views/index.py @@ -1,6 +1,5 @@ #!/usr/bin/python3 -"""Index route for the API""" - +"""Index route for the API documentation""" from flask import jsonify from api.v1.views import app_views From 4b80f24c6b16325112558d656a2f49bfb08e58a2 Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Sun, 11 Aug 2024 23:37:47 +0300 Subject: [PATCH 05/16] index --- api/v1/views/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/v1/views/index.py b/api/v1/views/index.py index 85a89e51eb6..48f8d7aab71 100644 --- a/api/v1/views/index.py +++ b/api/v1/views/index.py @@ -1,9 +1,9 @@ #!/usr/bin/python3 -"""Index route for the API documentation""" +"""Index route for the API""" + from flask import jsonify from api.v1.views import app_views - @app_views.route('/status', methods=['GET']) def status(): """Returns the status of the API""" From f3cdce20fdb24f52633dc4433fa820f93bed8f0f Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Sun, 11 Aug 2024 23:41:19 +0300 Subject: [PATCH 06/16] checker --- api/v1/views/__init__.py | 2 +- api/v1/views/index.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/api/v1/views/__init__.py b/api/v1/views/__init__.py index c26dea4a065..29993249f00 100644 --- a/api/v1/views/__init__.py +++ b/api/v1/views/__init__.py @@ -1,5 +1,5 @@ #!/usr/bin/python3 -"""Blueprint setup""" +"""Blueprint setup documentation""" from flask import Blueprint from api.v1.views.index import * diff --git a/api/v1/views/index.py b/api/v1/views/index.py index 48f8d7aab71..eda07bd47b5 100644 --- a/api/v1/views/index.py +++ b/api/v1/views/index.py @@ -4,6 +4,7 @@ from flask import jsonify from api.v1.views import app_views + @app_views.route('/status', methods=['GET']) def status(): """Returns the status of the API""" From 0b3928664bbe6ce19a8f54d3dfeaa24c7072455b Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Sun, 11 Aug 2024 23:59:45 +0300 Subject: [PATCH 07/16] try --- api/v1/app.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/v1/app.py b/api/v1/app.py index 1fe264fdea8..bc75debdb09 100644 --- a/api/v1/app.py +++ b/api/v1/app.py @@ -1,5 +1,5 @@ #!/usr/bin/python3 -"""Flask application""" +"""Flask application documentation""" from flask import Flask from models import storage @@ -9,13 +9,11 @@ app = Flask(__name__) app.register_blueprint(app_views) - @app.teardown_appcontext def teardown(exception): """Method to handle teardown, closing the storage""" storage.close() - if __name__ == "__main__": host = os.getenv('HBNB_API_HOST', '0.0.0.0') port = int(os.getenv('HBNB_API_PORT', 5000)) From f020196099c28ca0281bd29b530deaf099ae0420 Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Mon, 12 Aug 2024 00:04:16 +0300 Subject: [PATCH 08/16] done --- api/v1/app.py | 1 + api/v1/views/__init__.py | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/api/v1/app.py b/api/v1/app.py index bc75debdb09..734175fa897 100644 --- a/api/v1/app.py +++ b/api/v1/app.py @@ -9,6 +9,7 @@ app = Flask(__name__) app.register_blueprint(app_views) + @app.teardown_appcontext def teardown(exception): """Method to handle teardown, closing the storage""" diff --git a/api/v1/views/__init__.py b/api/v1/views/__init__.py index 29993249f00..06b022dac67 100644 --- a/api/v1/views/__init__.py +++ b/api/v1/views/__init__.py @@ -3,6 +3,4 @@ from flask import Blueprint from api.v1.views.index import * - - app_views = Blueprint('app_views', __name__, url_prefix='/api/v1') From 60d890eae1a6b350e78aaf553ee98c66141a357f Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Mon, 12 Aug 2024 00:06:32 +0300 Subject: [PATCH 09/16] clean --- api/__init__.py | 0 api/v1/__init__.py | 0 api/v1/app.py | 21 --------------------- api/v1/views/__init__.py | 6 ------ api/v1/views/index.py | 11 ----------- 5 files changed, 38 deletions(-) delete mode 100644 api/__init__.py delete mode 100644 api/v1/__init__.py delete mode 100644 api/v1/app.py delete mode 100644 api/v1/views/__init__.py delete mode 100644 api/v1/views/index.py diff --git a/api/__init__.py b/api/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/api/v1/__init__.py b/api/v1/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/api/v1/app.py b/api/v1/app.py deleted file mode 100644 index 734175fa897..00000000000 --- a/api/v1/app.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/python3 -"""Flask application documentation""" - -from flask import Flask -from models import storage -from api.v1.views import app_views -import os - -app = Flask(__name__) -app.register_blueprint(app_views) - - -@app.teardown_appcontext -def teardown(exception): - """Method to handle teardown, closing the storage""" - storage.close() - -if __name__ == "__main__": - host = os.getenv('HBNB_API_HOST', '0.0.0.0') - port = int(os.getenv('HBNB_API_PORT', 5000)) - app.run(host=host, port=port, threaded=True) diff --git a/api/v1/views/__init__.py b/api/v1/views/__init__.py deleted file mode 100644 index 06b022dac67..00000000000 --- a/api/v1/views/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/python3 -"""Blueprint setup documentation""" - -from flask import Blueprint -from api.v1.views.index import * -app_views = Blueprint('app_views', __name__, url_prefix='/api/v1') diff --git a/api/v1/views/index.py b/api/v1/views/index.py deleted file mode 100644 index eda07bd47b5..00000000000 --- a/api/v1/views/index.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/python3 -"""Index route for the API""" - -from flask import jsonify -from api.v1.views import app_views - - -@app_views.route('/status', methods=['GET']) -def status(): - """Returns the status of the API""" - return jsonify({"status": "OK"}) From 30c4c0a29f17b2cbf50f647263ec5848c57cb425 Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Mon, 12 Aug 2024 00:08:55 +0300 Subject: [PATCH 10/16] new1 --- api/__init__.py | 0 api/v1/__init__.py | 0 api/v1/app.py | 22 ++++++++++++++++++++++ api/v1/views/__init__.py | 9 +++++++++ api/v1/views/index.py | 11 +++++++++++ 5 files changed, 42 insertions(+) create mode 100644 api/__init__.py create mode 100644 api/v1/__init__.py create mode 100644 api/v1/app.py create mode 100644 api/v1/views/__init__.py create mode 100644 api/v1/views/index.py diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/api/v1/__init__.py b/api/v1/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/api/v1/app.py b/api/v1/app.py new file mode 100644 index 00000000000..1fe264fdea8 --- /dev/null +++ b/api/v1/app.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 +"""Flask application""" + +from flask import Flask +from models import storage +from api.v1.views import app_views +import os + +app = Flask(__name__) +app.register_blueprint(app_views) + + +@app.teardown_appcontext +def teardown(exception): + """Method to handle teardown, closing the storage""" + storage.close() + + +if __name__ == "__main__": + host = os.getenv('HBNB_API_HOST', '0.0.0.0') + port = int(os.getenv('HBNB_API_PORT', 5000)) + app.run(host=host, port=port, threaded=True) diff --git a/api/v1/views/__init__.py b/api/v1/views/__init__.py new file mode 100644 index 00000000000..c377a044191 --- /dev/null +++ b/api/v1/views/__init__.py @@ -0,0 +1,9 @@ +#!/usr/bin/python3 +"""Blueprint setup""" + +from flask import Blueprint + +app_views = Blueprint('app_views', __name__, url_prefix='/api/v1') + +# Import routes so they are registered with the Blueprint +from api.v1.views.index import * diff --git a/api/v1/views/index.py b/api/v1/views/index.py new file mode 100644 index 00000000000..eda07bd47b5 --- /dev/null +++ b/api/v1/views/index.py @@ -0,0 +1,11 @@ +#!/usr/bin/python3 +"""Index route for the API""" + +from flask import jsonify +from api.v1.views import app_views + + +@app_views.route('/status', methods=['GET']) +def status(): + """Returns the status of the API""" + return jsonify({"status": "OK"}) From eb83cad6b2c22c1ffefeba5ba19d415ca740589e Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Mon, 12 Aug 2024 00:14:06 +0300 Subject: [PATCH 11/16] stats --- api/v1/views/index.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/v1/views/index.py b/api/v1/views/index.py index eda07bd47b5..f5df235282e 100644 --- a/api/v1/views/index.py +++ b/api/v1/views/index.py @@ -2,6 +2,7 @@ """Index route for the API""" from flask import jsonify +from models import storage from api.v1.views import app_views @@ -9,3 +10,17 @@ def status(): """Returns the status of the API""" return jsonify({"status": "OK"}) + + +@app_views.route('/stats', methods=['GET'], strict_slashes=False) +def stats(): + """Retrieves the number of each objects by type""" + stats = { + "amenities": storage.count("Amenity"), + "cities": storage.count("City"), + "places": storage.count("Place"), + "reviews": storage.count("Review"), + "states": storage.count("State"), + "users": storage.count("User") + } + return jsonify(stats) From 16f6f1d7bf69269fd4af6eb5844904980ac54e1e Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Mon, 12 Aug 2024 13:11:41 +0300 Subject: [PATCH 12/16] test --- models/engine/db_storage.py | 11 +++++++ models/engine/file_storage.py | 11 +++++++ .../test_engine/test_db_storage.py | 29 +++++++++++++++++++ .../test_engine/test_file_storage.py | 26 +++++++++++++++++ 4 files changed, 77 insertions(+) diff --git a/models/engine/db_storage.py b/models/engine/db_storage.py index b8e7d291e6f..91565dd820c 100755 --- a/models/engine/db_storage.py +++ b/models/engine/db_storage.py @@ -74,3 +74,14 @@ def reload(self): def close(self): """call remove() method on the private session attribute""" self.__session.remove() + + def get(self, cls, id): + """Retrieve one object""" + if cls and id: + key = "{}.{}".format(cls.__name__, id) + return self.all(cls).get(key, None) + return None + + def count(self, cls=None): + """Count the number of objects in storage""" + return len(self.all(cls)) diff --git a/models/engine/file_storage.py b/models/engine/file_storage.py index c8cb8c1764d..acfa988bba7 100755 --- a/models/engine/file_storage.py +++ b/models/engine/file_storage.py @@ -68,3 +68,14 @@ def delete(self, obj=None): def close(self): """call reload() method for deserializing the JSON file to objects""" self.reload() + + def get(self, cls, id): + """Retrieve one object""" + if cls and id: + key = "{}.{}".format(cls.__name__, id) + return self.all(cls).get(key, None) + return None + + def count(self, cls=None): + """Count the number of objects in storage""" + return len(self.all(cls)) diff --git a/tests/test_models/test_engine/test_db_storage.py b/tests/test_models/test_engine/test_db_storage.py index 766e625b5af..2a8aa9060b9 100755 --- a/tests/test_models/test_engine/test_db_storage.py +++ b/tests/test_models/test_engine/test_db_storage.py @@ -67,6 +67,35 @@ def test_dbs_func_docstrings(self): self.assertTrue(len(func[1].__doc__) >= 1, "{:s} method needs a docstring".format(func[0])) + def test_count(self): + """Test the count method.""" + all_objects_count = storage.count() + state_objects_count = storage.count(State) + city_objects_count = storage.count(City) + + self.assertEqual(all_objects_count, 2) + self.assertEqual(state_objects_count, 1) + self.assertEqual(city_objects_count, 1) + + # Adding another state and testing the count again + new_state = State(name="Nevada") + new_state.save() + self.assertEqual(storage.count(State), 2) + new_state.delete() + + def test_get(self): + """Test the get method.""" + state = storage.get(State, self.state.id) + self.assertIsNotNone(state) + self.assertEqual(state.id, self.state.id) + + city = storage.get(City, self.city.id) + self.assertIsNotNone(city) + self.assertEqual(city.id, self.city.id) + + non_existent = storage.get(State, "non-existent-id") + self.assertIsNone(non_existent) + class TestFileStorage(unittest.TestCase): """Test the FileStorage class""" diff --git a/tests/test_models/test_engine/test_file_storage.py b/tests/test_models/test_engine/test_file_storage.py index 1474a34fec0..88f9ee4f37b 100755 --- a/tests/test_models/test_engine/test_file_storage.py +++ b/tests/test_models/test_engine/test_file_storage.py @@ -67,6 +67,32 @@ def test_fs_func_docstrings(self): self.assertTrue(len(func[1].__doc__) >= 1, "{:s} method needs a docstring".format(func[0])) + def test_count(self): + """Test the count method.""" + all_objects_count = storage.count() + state_objects_count = storage.count(State) + city_objects_count = storage.count(City) + + self.assertEqual(all_objects_count, 2) + self.assertEqual(state_objects_count, 1) + self.assertEqual(city_objects_count, 1) + + # Adding another state and testing the count again + new_state = State(name="Nevada") + new_state.save() + self.assertEqual(storage.count(State), 2) + new_state.delete() + + def test_get(self): + """Test the get method.""" + state = storage.get(State, self.state.id) + self.assertIsNotNone(state) + self.assertEqual(state.id, self.state.id) + + city = storage.get(City, self.city.id) + self.assertIsNotNone(city) + self.assertEqual(city.id, self.city.id) + class TestFileStorage(unittest.TestCase): """Test the FileStorage class""" From a48feeaaca1b483d662d2ac335d3dd79a6bfb65b Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Mon, 12 Aug 2024 13:18:02 +0300 Subject: [PATCH 13/16] 404 error handler --- api/v1/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/v1/app.py b/api/v1/app.py index 1fe264fdea8..fbfabf8820f 100644 --- a/api/v1/app.py +++ b/api/v1/app.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 """Flask application""" -from flask import Flask +from flask import Flask, jsonify from models import storage from api.v1.views import app_views import os @@ -16,6 +16,12 @@ def teardown(exception): storage.close() +@app.errorhandler(404) +def not_found(error): + """Handler for 404 errors that returns a JSON response""" + return jsonify({"error": "Not found"}), 404 + + if __name__ == "__main__": host = os.getenv('HBNB_API_HOST', '0.0.0.0') port = int(os.getenv('HBNB_API_PORT', 5000)) From ce01b7aa58d5700aab1679e2a37d95c31892d445 Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Mon, 12 Aug 2024 16:34:23 +0300 Subject: [PATCH 14/16] state api --- api/v1/views/__init__.py | 1 + api/v1/views/states.py | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 api/v1/views/states.py diff --git a/api/v1/views/__init__.py b/api/v1/views/__init__.py index c377a044191..7ffc6db7ce1 100644 --- a/api/v1/views/__init__.py +++ b/api/v1/views/__init__.py @@ -7,3 +7,4 @@ # Import routes so they are registered with the Blueprint from api.v1.views.index import * +from api.v1.views.states import * diff --git a/api/v1/views/states.py b/api/v1/views/states.py new file mode 100644 index 00000000000..5d36a0a83f0 --- /dev/null +++ b/api/v1/views/states.py @@ -0,0 +1,64 @@ +#!/usr/bin/python3 +"""State view for handling all default RESTful API actions""" +from flask import jsonify, abort, request, make_response +from models import storage +from models.state import State +from api.v1.views import app_views + + +@app_views.route('/states', methods=['GET'], strict_slashes=False) +def get_states(): + """Retrieves the list of all State objects""" + states = storage.all(State).values() + return jsonify([state.to_dict() for state in states]) + + +@app_views.route('/states', methods=['GET'], strict_slashes=False) +def get_state(state_id): + """Retrieves a State object""" + state = storage.get(State, state_id) + if not state: + abort(404) + return jsonify(state.to_dict()) + + +@app_views.route('states/', methods=['DELETE'], strict_slashes=False) +def delete_state(state_id): + """Deletes a State object""" + state = storage.get(State, state_id) + if not state: + abort(404) + storage.delete(state) + storage.save() + return jsonify({}), 200 + + +@app_views.route('/states', methods=['POST'], strict_slashes=False) +def create_state(): + """Creates a State""" + if not request.json: + abort(400, description="Not a JSON") + if 'name' not in request.json: + abort(400, description="Missing name") + new_state = State(**request.get_json()) + storage.new(new_state) + storage.save() + return jsonify(new_state.to_dict()), 201 + + +@app_views.route('/states/', methods=['PUT'], strict_slashes=False) +def update_state(state_id): + """Updates a State object""" + state = storage.get(State, state_id) + if not state: + abort(404) + if not request.json: + abort(400, description="Not a JSON") + + ignore_keys = ['id', 'created_at', 'updated_at'] + data = request.get_json() + for key, value in data.items(): + if key not in ignore_keys: + setattr(state, key, value) + storage.save() + return jsonify(state.to_dict()), 200 From 6462c656b25089e1ddda164373ebe6796b1d8806 Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Mon, 12 Aug 2024 17:28:13 +0300 Subject: [PATCH 15/16] correction --- api/v1/views/states.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api/v1/views/states.py b/api/v1/views/states.py index 5d36a0a83f0..01230c2872e 100644 --- a/api/v1/views/states.py +++ b/api/v1/views/states.py @@ -2,7 +2,7 @@ """State view for handling all default RESTful API actions""" from flask import jsonify, abort, request, make_response from models import storage -from models.state import State +from models.state import State from api.v1.views import app_views @@ -13,7 +13,7 @@ def get_states(): return jsonify([state.to_dict() for state in states]) -@app_views.route('/states', methods=['GET'], strict_slashes=False) +@app_views.route('/states/', methods=['GET'], strict_slashes=False) def get_state(state_id): """Retrieves a State object""" state = storage.get(State, state_id) @@ -38,7 +38,7 @@ def create_state(): """Creates a State""" if not request.json: abort(400, description="Not a JSON") - if 'name' not in request.json: + if 'name' not in request.json(force=True, silent=True): abort(400, description="Missing name") new_state = State(**request.get_json()) storage.new(new_state) @@ -52,7 +52,7 @@ def update_state(state_id): state = storage.get(State, state_id) if not state: abort(404) - if not request.json: + if not request.json(force=True, silent=True): abort(400, description="Not a JSON") ignore_keys = ['id', 'created_at', 'updated_at'] From 7dd13b7caa0f824bbc6c8ba1b0380afd391bd3bb Mon Sep 17 00:00:00 2001 From: Mikonimo Date: Mon, 12 Aug 2024 19:46:38 +0300 Subject: [PATCH 16/16] corr1 --- api/v1/views/states.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/v1/views/states.py b/api/v1/views/states.py index 01230c2872e..c5c74c843c3 100644 --- a/api/v1/views/states.py +++ b/api/v1/views/states.py @@ -52,7 +52,7 @@ def update_state(state_id): state = storage.get(State, state_id) if not state: abort(404) - if not request.json(force=True, silent=True): + if not request.json(): abort(400, description="Not a JSON") ignore_keys = ['id', 'created_at', 'updated_at']