AirBnB Clone

hbnb

Description

The AirbnB clone is a web application project that consists of four(4) different parts:

  • A command interpreter to manipulate data without a visual interface, like in a Shell (perfect for development and debugging)
  • A website (the front-end) that shows the final product to everybody: static and dynamic
  • A database or files that store data (data = objects)
  • An API that provides a communication interface between the front-end and your data (retrieve, create, delete, update them)

The Console

This part of the project is to create a console (a command interpreter) that uses file storage system to manipulate data The goal of the console part fo the project is to:

  • create a data model
  • manage (create, update, destroy, etc) objects via a console / command interpreter
  • store and persist objects to a file (JSON file)

The first piece is to manipulate a powerful storage system. This storage engine will give us an abstraction between “My object” and “How they are stored and persisted”. This means: from your console code (the command interpreter itself) and from the front-end and RestAPI you will build later, you won’t have to pay attention (take care) of how your objects are stored.

This abstraction will also allow you to change the type of storage easily without updating all of your codebase.

The console will be a tool to validate this storage engine.

console

Usage

  • Start the console in interactive mode:
$ ./console.py
(hbnb)
  • Use help to see the available commands:
(hbnb) help

Documented commands (type help <topic>):
========================================
EOF  all  count  create  destroy  help  quit  show  update

(hbnb)
  • Quit the console:
(hbnb) quit
$

Commands

The commands are displayed in the following format Command / usage / example with output

  • Create

Creates a new instance of a given class. The class' ID is printed and the instance is saved to the file file.json.

create <class>
(hbnb) create BaseModel
6cfb47c4-a434-4da7-ac03-2122624c3762
(hbnb)
  • Show
show <class> <id>
(hbnb) show BaseModel 6cfb47c4-a434-4da7-ac03-2122624c3762
[BaseModel] (a) [BaseModel] (6cfb47c4-a434-4da7-ac03-2122624c3762) {'id': '6cfb47c4-a434-4da7-ac03-2122624c3762', 'created_at': datetime.datetime(2021, 11, 14, 3, 28, 45, 571360), 'updated_at': datetime.datetime(2021, 11, 14, 3, 28, 45, 571389)}
(hbnb)
  • Destroy

Deletes an instance of a given class with a given ID. Update the file.json

(hbnb) create User
0c98d2b8-7ffa-42b7-8009-d9d54b69a472
(hbnb) destroy User 0c98d2b8-7ffa-42b7-8009-d9d54b69a472
(hbnb) show User 0c98d2b8-7ffa-42b7-8009-d9d54b69a472
** no instance found **
(hbnb)
  • all

Prints all string representation of all instances of a given class. If no class is passed, all classes are printed.

(hbnb) create BaseModel
e45ddda9-eb80-4858-99a9-226d4f08a629
(hbnb) all BaseModel
["[BaseModel] (4c8f7ebc-257f-4ed1-b26b-e7aace459897) [BaseModel] (4c8f7ebc-257f-4ed1-b26b-e7aace459897) {'id': '4c8f7ebc-257f-4ed1-b26b-e7aace459897', 'created_at': datetime.datetime(2021, 11, 13, 22, 19, 19, 447155), 'updated_at': datetime.datetime(2021, 11, 13, 22, 19, 19, 447257), 'name': 'My First Model', 'my_number': 89}"]
  • count

Prints the number of instances of a given class.

(hbnb) create City
4e01c33e-2564-42c2-b61c-17e512898bad
(hbnb) create City
e952b772-80a5-41e9-b728-6bc4dc5c21b4
(hbnb) count City
2
(hbnb)
  • update

Updates an instance based on the class name, id, and kwargs passed. Update the file.json

(hbnb) create User
1afa163d-486e-467a-8d38-3040afeaa1a1
(hbnb) update User 1afa163d-486e-467a-8d38-3040afeaa1a1 email "azconcept2016@gmail.com"
(hbnb) show User 1afa163d-486e-467a-8d38-3040afeaa1a1
[User] (s) [User] (1afa163d-486e-467a-8d38-3040afeaa1a1) {'id': '1afa163d-486e-467a-8d38-3040afeaa1a1', 'created_at': datetime.datetime(2021, 11, 14, 23, 42, 10, 502157), 'updated_at': datetime.datetime(2021, 11, 14, 23, 42, 10, 502186), 'email': 'azconcept2016@gmail.com'}
(hbnb)