AirBnB_clone_v2 icon indicating copy to clipboard operation
AirBnB_clone_v2 copied to clipboard

Add get and count Methods to DBStorage and FileStorage with Unit Tests

Open paxxchal opened this issue 9 months ago • 3 comments

This pull request introduces two new methods, get and count, to both the DBStorage and FileStorage classes. These methods enhance the functionality of our storage engines by allowing the retrieval of specific objects by ID and counting the total number of objects in storage.

Changes in This Pull Request: DBStorage (models/engine/db_storage.py)

Added get(self, cls, id) method to retrieve an object based on its class and ID. Added count(self, cls=None) method to count the number of objects in storage, either for a specific class or for all objects if no class is specified. FileStorage (models/engine/file_storage.py)

Added get(self, cls, id) method to retrieve an object based on its class and ID. Added count(self, cls=None) method to count the number of objects in storage, either for a specific class or for all objects if no class is specified. Unit Tests

Created tests/test_models/test_engine/test_db_storage.py to test the new methods in DBStorage. Created tests/test_models/test_engine/test_file_storage.py to test the new methods in FileStorage. Testing: get method: Validated that the method correctly retrieves objects by their ID and returns None for non-existent IDs. count method: Ensured the method returns the correct count of objects in storage, both for specific classes and for all objects. Why These Changes? These enhancements are crucial for improving the efficiency and capabilities of our storage system, particularly in the context of developing a robust and scalable RESTful API for the AirBnB clone project.

Next Steps: Review the code for any potential improvements. Merge the pull request after ensuring all tests pass successfully. Please review these changes and provide your feedback. Thank you!

paxxchal avatar May 27 '24 17:05 paxxchal