GithubHelp home page GithubHelp logo

airbnb_clone's Introduction

0x00. AirBnB clone - The console

Command interpreter to manage objects in AirBnB clone.

This is the first step to build a web application: the AirBnB clone. This will be used during this project and all other following projects: HTML/CSS templating, database storage, API, front-end integration…

Each task is linked and will:

  • Put in place a parent class (called BaseModel) to take care of the initialization, serialization and deserialization of your future instances.
  • Create a simple flow of serialization/deserialization: Instance <-> Dictionary <-> JSON string <-> file.
  • Create all classes used for AirBnB (User, State, City, Place, Anemity and Review) that inherit from BaseModel.
  • Create the first abstracted storage engine of the project: File storage.
  • Create all unittests to validate all classes and storage engine.

What’s a command interpreter?

It’s like a shell but limited to a specific use-case. In this case, to be able to manage the objects of the full project:

  • Create a new object (ex: a new User or a new Place)
  • Retrieve an object from a file, a database etc…
  • Do operations on objects (count, compute stats, etc…)
  • Update attributes of an object
  • Destroy an object

Requirements

Python Scripts

  • Allowed editors: vi, vim, emacs
  • All your files will be interpreted/compiled on Ubuntu 14.04 LTS using python3 (version 3.4.3)
  • All your files should end with a new line
  • The first line of all your files should be exactly #!/usr/bin/python3
  • A README.md file, at the root of the folder of the project, is mandatory
  • Your code should use the PEP 8 style (version 1.7 or more)
  • All your files must be executable
  • The length of your files will be tested using wc
  • All your modules should have a documentation (python3 -c 'print(import("my_module").doc)')
  • All your classes should have a documentation (python3 -c 'print(import("my_module").MyClass.doc)')
  • All your functions (inside and outside a class) should have a documentation (python3 -c 'print(import("my_module").my_function.doc)' and python3 -c 'print(import("my_module").MyClass.my_function.doc)')

Python Unit Tests

  • Allowed editors: vi, vim, emacs
  • All your files should end with a new line
  • All your test files should be inside a folder tests
  • You have to use the unittest module
  • All your test files should be python files (extension: .py)
  • All your test files and folders should start by test_
  • Your file organization in the tests folder should be the same as your project e.g., For models/base_model.py, unit tests must be in: tests/test_models/test_base_model.py e.g., For models/user.py, unit tests must be in: tests/test_models/test_user.py
  • All your tests should be executed by using this command: python3 -m unittest discover tests
  • You can also test file by file by using this command: python3 -m unittest tests/test_models/test_base_model.py
  • All your modules should have a documentation (python3 -c 'print(import("my_module").doc)')
  • All your classes should have a documentation (python3 -c 'print(import("my_module").MyClass.doc)')
  • All your functions (inside and outside a class) should have a documentation (python3 -c 'print(import("my_module").my_function.doc)' and python3 -c 'print(import("my_module").MyClass.my_function.doc)') We strongly encourage you to work together on test cases, so that you don’t miss any edge case

How to use

The console works in interactive mode:

$ ./console.py
(hbnb) help

Documented commands (type help <topic>):
========================================
EOF  help  quit

(hbnb) 
(hbnb) 
(hbnb) quit
$

But also in non-interactive mode: (like a Shell)

$$ echo "help" | ./console.py
(hbnb)

Documented commands (type help <topic>):
========================================
EOF  help  quit
(hbnb) 
$
$ cat test_help
help
$
$ cat test_help | ./console.py
(hbnb)

Documented commands (type help <topic>):
========================================
EOF  help  quit
(hbnb) 
$

How the program works

Commands Description Usage
create Create new instance, saves it (to JSON file) and prints the id. create <class_name>
all Prints all string representation of all instances based or not on. all [class_name]
destroy Deletes an instance based on the class name and id. destroy <class_name> < id >
help List available commands with "help" or detailed help with "help cmd". help [command]
show Prints string representation of an instance. show <class_name> < id >
update Updates an instance based on the class name and id by adding or updating attribute (save the change into the JSON file). update < ClassName > < id > <attr_name> "<attr_value>"
quit Quit the program! quit

Other files and folders

  • models: classes implemented .
  • models\engine: classes for serialization and deserialization in JSON file.
  • test: test cases.
  • README.md: This readme file.

Examples

(hbnb) 
(hbnb) help

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

(hbnb) help all

Prints all string representation of all instances based or not on

        the class name.

        -> Usage: (hbnb) all <class_name>

        -> Usage: (hbnb) all

(hbnb) all
(hbnb) create
** class name missing **
(hbnb) 
(hbnb) create Base
** class doesn't exist **
(hbnb) 
(hbnb) create BaseModel
9c95b576-fa67-4e7e-b341-2a9ff80c7422
(hbnb) 
(hbnb) create User
7782e0e3-14d4-4270-85a1-9a15ea5ffa86
(hbnb) 
(hbnb) all
["[BaseModel] (9c95b576-fa67-4e7e-b341-2a9ff80c7422) {'id': '9c95b576-fa67-4e7e-b341-2a9ff80c7422', 'created_at': '2020-02-19T10:39:00.987137', 'updated_at': '2020-02-19T10:39:00.987175', '__class__': 'BaseModel'}", "[User] (7782e0e3-14d4-4270-85a1-9a15ea5ffa86) {'id': '7782e0e3-14d4-4270-85a1-9a15ea5ffa86', 'created_at': '2020-02-19T10:39:06.809685', 'updated_at': '2020-02-19T10:39:06.809721', '__class__': 'User'}"]
(hbnb) 
(hbnb) all User
["[User] (7782e0e3-14d4-4270-85a1-9a15ea5ffa86) {'id': '7782e0e3-14d4-4270-85a1-9a15ea5ffa86', 'created_at': '2020-02-19T10:39:06.809685', 'updated_at': '2020-02-19T10:39:06.809721', '__class__': 'User'}"]
(hbnb) 
(hbnb) destroy
** class name missing **
(hbnb) 
(hbnb) destroy Base
** class doesn't exist **
(hbnb) 
(hbnb) destroy BaseModel
** instance id missing **
(hbnb) 
(hbnb) destroy BaseModel 1
** no instance found **
(hbnb) 
(hbnb) destroy BaseModel 9c95b576-fa67-4e7e-b341-2a9ff80c7422
(hbnb) 
(hbnb) all
["[User] (7782e0e3-14d4-4270-85a1-9a15ea5ffa86) {'id': '7782e0e3-14d4-4270-85a1-9a15ea5ffa86', 'created_at': '2020-02-19T10:39:06.809685', 'updated_at': '2020-02-19T10:39:06.809721', '__class__': 'User'}"]
(hbnb) 
(hbnb) create City
b6759f36-d7dc-4eeb-a625-736c70844313
(hbnb) 
(hbnb) all
["[User] (7782e0e3-14d4-4270-85a1-9a15ea5ffa86) {'id': '7782e0e3-14d4-4270-85a1-9a15ea5ffa86', 'created_at': '2020-02-19T10:39:06.809685', 'updated_at': '2020-02-19T10:39:06.809721', '__class__': 'User'}", "[City] (b6759f36-d7dc-4eeb-a625-736c70844313) {'id': 'b6759f36-d7dc-4eeb-a625-736c70844313', 'created_at': '2020-02-19T10:40:06.817788', 'updated_at': '2020-02-19T10:40:06.817824', '__class__': 'City'}"]
(hbnb) 
(hbnb) show
** class name missing **
(hbnb) 
(hbnb) show City
** instance id missing **
(hbnb) 
(hbnb) show City b6759f36-d7dc-4eeb-a625-736c70844313
[City] (b6759f36-d7dc-4eeb-a625-736c70844313) {'id': 'b6759f36-d7dc-4eeb-a625-736c70844313', 'created_at': '2020-02-19T10:40:06.817788', 'updated_at': '2020-02-19T10:40:06.817824', '__class__': 'City'}
(hbnb) 
(hbnb) update
** class name missing **
(hbnb) 
(hbnb) update City
** instance id missing **
(hbnb) 
(hbnb) update City name
** no instance found **
(hbnb) 
(hbnb) update City b6759f36-d7dc-4eeb-a625-736c70844313
** attribute name missing **
(hbnb) 
(hbnb) update City b6759f36-d7dc-4eeb-a625-736c70844313 name
** value missing **
(hbnb) 
(hbnb) update City b6759f36-d7dc-4eeb-a625-736c70844313 name Pereira
(hbnb) 
(hbnb) show City b6759f36-d7dc-4eeb-a625-736c70844313
[City] (b6759f36-d7dc-4eeb-a625-736c70844313) {'id': 'b6759f36-d7dc-4eeb-a625-736c70844313', 'created_at': '2020-02-19T10:40:06.817788', 'updated_at': '2020-02-19T10:40:06.817824', 'name': 'Pereira', '__class__': 'City'}
(hbnb) 
(hbnb) quit
$

Classes implemented

class User
Public class attributes:
    email: string - empty string
    password: string - empty string
    first_name: string - empty string
    last_name: string - empty string

class State
Public class attributes:
    name: string - empty string

class City
Public class attributes:
    state_id: string - empty string: it will be the State.id
    name: string - empty string

class Amenity
Public class attributes:
    name: string - empty string

class Place
Public class attributes:
    city_id: string - empty string: it will be the City.id
    user_id: string - empty string: it will be the User.id
    name: string - empty string
    description: string - empty string
    number_rooms: integer - 0
    number_bathrooms: integer - 0
    max_guest: integer - 0
    price_by_night: integer - 0
    latitude: float - 0.0
    longitude: float - 0.0
    amenity_ids: list of string - empty list: it will be the list of Amenity.id later

class Review
Public class attributes:
    place_id: string - empty string: it will be the Place.id
    user_id: string - empty string: it will be the User.id
    text: string - empty string

Authors

02/19/2020

airbnb_clone's People

Contributors

leocjj avatar vik407 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.