This is the beginning part of our team project to develop a clone copy of the AirBnB website. In this part, we've created a backend interface, like a control panel, to handle program information. With commands in the control panel, users can make, modify, or remove things and handle file storage. We use a system called JSON to keep data saved even when you close and reopen the program.
The AirBnB project is a project to implement a full web application that mimics the AirBnB web application. This is no a 100% replica of the site but an implementation with fundamental functions. The aim was to provide us the students with a learning opportunity to grasp fundamental concepts.
The console is the first step towards building our first full web application: the AirBnB clone.
The very first step is involved and is important because it laid the foundation for subsequent projects:
- HTML/CSS templatinig
- Database storage
- API
- Front-end integration
For the console project, the major part was building a command interpreter. You think of this like a mini-shell implmented within python, using python's cmd module.
This interpreter is to be used to manage objects for the project - implementing CRUD.
- Create a new
- Retrieve an object from file
- Update object attributes
- Destroy an object
- Do operations on the data saved
Running the interpreter is straight forward. Look for the file name 'console.py' in the directory. It is already executable.
./console.py or python3 console.py should start the interpreter for you.
The interpreter comes with a 'help' command that provides information about every other command implemented. When you prompt is displayed :
- prompt: help + ENTER - prints information and all commands avialble
- prompt: help - prints information about the command
- prompt: - runs command on given argument
- prompt: quit - ends the interpreter session
- prompt: ctrl+D - same as quit
- prompt: count <class_name> - prints number of instances
Explore ....
To build this part of the project; AirBnB clone, the project was broken into tasks. The different tasks when implemented, together resulted to an amazing piece of work.
Tasks 0 to 2 involved good practices requirements
- Writing this README as well as AUTHORS file
- Ensuring my python3 code compplies with pycodestyl
- Writing test cases for the entire project
We started the project by implemeting this class that served as the base class for every other class in the project.
The class defines all common attributes and methods to be inherited by other classes.
One of the methods implemented in the BaseModel class, converted class instances to dcitionary representation. In this task, we did the reverse, from dictionary representation, we recreated the instance.
Here, we implemented data persistence using serialization and deserialization of data to and from JSON file. Prior to this stage, every data we handle would be lost when the interpreter session is ended. Here we serialize to JSON - writing to file in JSON format and deserialize - reading from file in dictionary representation.
We implemented FileStorage class to handle the process explained above.
Here we started the implemetation of the command interpreter. At this stage the interpreter is able to handle basic commands.
All of these commands have to do with class instances:
- creating an instance
- reading from file
- updating instances
- destroying instances
- printing instances etc
By now, you must have deduced we are using OOP. We implemented User as well as other classes to handle very objects in the project. Among these classes, we have city, place, amenity review etc.
All these classes inherit from BaseModel which is the base class in this project.
Here we updated our file storage class.
This class is responsible fr serialization and deseriaization, but so far it dioes so only for BaseModel and User classes. Here, we updated it to handle data from every other class.
Our interpreter has a command that prints all existing instances.
In this task, we updated, that command and made it class-specific.
Now, it prints instances by class name.
Here, we introduced a new command, count that returns the number of existing instances of a given class.
We implemented the show command to retrieve class instances. In this task, we make ID specific. Using Id and class name, this command retrieves instances.
We pretty much implemented the same thing here as in task 13.
This is the end of the first part of implementing the AirBnB clone.