Giter VIP home page Giter VIP logo

airbnb_clone's Introduction

AirBnB clone - The console

The project

The AirBnB clone (hbnb), is a project in which the students of Holberton deploy on a server a simple copy of the AirBnB website, in order to cover all fundamental concepts of the higher level programming track.

The web application is composed by:

  • 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

The console is a command line interpreter but limited to a specific use-case. In this case it will be able to manage the objects of our AirBnb clone 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

Execution (How to start it?)

The shell works like this in interactive mode:

$ ./console.py
(hbnb)

But also in non-interactive mode:

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

How to use it?

NOTE: you can use the help option with all the commands implemented to see the respective documentation.

(hbnb) help

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

i.e.

(hbnb) help quit
Quit command to exit the program
  • quit and EOF to exit the program

i.e.

$ ./console.py
(hbnb) quit 
$
  • create: Creates a new instance of BaseModel, saves it (to the JSON file) and prints the id.

Syntax: $ create [CLASS]

i.e.

(hbnb) create BaseModel
49faff9a-6318-451f-87b6-910505c55907
  • show: Prints the string representation of an instance based on the class name and id.

Syntax: $ show [CLASS] [ID]

i.e.

(hbnb) show BaseModel 49faff9a-6318-451f-87b6-910505c55907
[BaseModel] (49faff9a-6318-451f-87b6-910505c55907) {'created_at': datetime.datetime(2017, 10, 2, 3, 10, 25, 903293), 'id': '49faff9a-6318-451f-87b6-910505c55907', 'updated_at': datetime.datetime(2017, 10, 2, 3, 10, 25, 903300)}
  • destroy: Deletes an instance based on the class name and id (save the change into the JSON file).

Syntax: $ destroy [CLASS] [ID]

i.e.

(hbnb) destroy BaseModel 49faff9a-6318-451f-87b6-910505c55907
  • all: Prints all string representation of all instances based or not on the class name.

Syntax: $ all [CLASS] or $ all

i.e.

(hbnb) all BaseModel
["[BaseModel] (2dd6ef5c-467c-4f82-9521-a772ea7d84e9) {'id': '2dd6ef5c-467c-4f82-9521-a772ea7d84e9', 'created_at': datetime.datetime(2017, 10, 2, 3, 11, 23, 639717), 'updated_at': datetime.datetime(2017, 10, 2, 3, 11, 23, 639724)}", "[BaseModel] (49faff9a-6318-451f-87b6-910505c55907) {'first_name': 'Betty', 'id': '49faff9a-6318-451f-87b6-910505c55907', 'created_at': datetime.datetime(2017, 10, 2, 3, 10, 25, 903293), 'updated_at': datetime.datetime(2017, 10, 2, 3, 11, 3, 49401)}"]
  • update: Updates an instance based on the class name and id by adding or updating attribute (save the change into the JSON file).

Syntax: $ update [CLASS] [ID] [ATTRIBUTE] [VALUE]

i.e.

(hbnb) update BaseModel 49faff9a-6318-451f-87b6-910505c55907 first_name "Betty"

If a command is missing an argument or it does not exist, a message will be displayed:

i.e.

(hbnb) all MyModel
** class doesn't exist **
(hbnb) destroy
** class name missing **

Authors

  • Emma Juliana Gachancipa Castelblanco... alt textalt textalt textalt text

  • Juan Sebastian Montealegre Calle............. alt textalt textalt textalt text

airbnb_clone's People

Contributors

julgachancipa avatar sebastiancalle avatar

Watchers

 avatar

airbnb_clone's Issues

Console v.3

Update your command interpreter (console.py) to allow show, create, destroy, update and all used with User.

City v.1

Create class City (models/city.py):
Public class attributes:
state_id: string - empty string: it will be the State.id
name: string - empty string

BaseModel v.2

Update models/base_model.py:

init(self, *args, **kwargs):
you will use *args, **kwargs arguments for the constructor of a BaseModel. More detail
*args won’t be used
if kwargs is not empty:
each key of this dictionary is an attribute name
each value of this dictionary is the value of this attribute name
Warning: created_at and updated_at are strings in this dictionary, but inside your BaseModel instance is working with datetime object. You have to convert these strings into datetime object. Tip: you know the string format of these datetime
otherwise:
create id and created_at as you did previously (new instance)

FileStorage v.1

Write a class FileStorage that serializes instances to a JSON file and deserializes JSON file to instances:

models/engine/file_storage.py
Private class attributes:
__file_path: string - path to the JSON file (ex: file.json)
__objects: dictionary - empty but will store all objects by .id (ex: to store a BaseModel object with id=12121212, the key will be BaseModel.12121212)
Public instance methods:
all(self): returns the dictionary __objects
new(self, obj): sets in __objects the obj with key .id
save(self): serializes __objects to the JSON file (path: __file_path)
reload(self): deserializes the JSON file to __objects (only if the JSON file (__file_path) exists ; otherwise, do nothing. If the file doesn’t exist, no exception should be raised)
Update models/init.py: to create a unique FileStorage instance for your application

BaseModel v.1

Write a class BaseModel that defines all common attributes/methods for other classes:

models/base_model.py
Public instance attributes:
id: string - assign with an uuid when an instance is created:
you can use uuid.uuid4() to generate unique id but don’t forget to convert to a string
the goal is to have unique id for each BaseModel
created_at: datetime - assign with the current datetime when an instance is created
updated_at: datetime - assign with the current datetime when an instance is created and it will be updated every time you change your object
str: should print: [] (<self.id>) <self.dict>
Public instance methods:
save(self): updates the public instance attribute updated_at with the current datetime
to_dict(self): returns a dictionary containing all keys/values of dict of the instance:
by using self.dict, only instance attributes set will be returned
a key class must be added to this dictionary with the class name of the object
created_at and updated_at must be converted to string object in ISO format:
format: %Y-%m-%dT%H:%M:%S.%f (ex: 2017-06-14T22:31:03.285259)
you can use isoformat() of datetime object
This method will be the first piece of the serialization/deserialization process: create a dictionary representation with “simple object type” of our BaseModel

State v.1

Create class State (models/state.py):
Public class attributes:
name: string - empty string

Unittests

Write unitettest for all clases and functions for test the program

Console v.1

Write a program called console.py that contains the entry point of the command interpreter:
You must use the module cmd
Your class definition must be: class HBNBCommand(cmd.Cmd):
Your command interpreter should implement:
quit and EOF to exit the program
help (this action is provided by default by cmd but you should keep it updated and documented)
a custom prompt: (hbnb)
an empty line + ENTER shouldn’t execute anything
Your code should not be executed when imported

FileStore v.2

Update FileStorage to manage correctly serialization and deserialization of all our new classes: Place, State, City, Amenity and Review

User v.1

Write a class User that inherits from BaseModel:

models/user.py
Public class attributes:
email: string - empty string
password: string - empty string
first_name: string - empty string
last_name: string - empty string
Update FileStorage to manage correctly serialization and deserialization of User.

Place v.1

Create class Place (models/place.py):
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

Console v.2

Update your command interpreter (console.py) to have these commands:

create: Creates a new instance of BaseModel, saves it (to the JSON file) and prints the id. Ex: $ create BaseModel
If the class name is missing, print ** class name missing ** (ex: $ create)
If the class name doesn’t exist, print ** class doesn't exist ** (ex: $ create MyModel)
show: Prints the string representation of an instance based on the class name and id. Ex: $ show BaseModel 1234-1234-1234.
If the class name is missing, print ** class name missing ** (ex: $ show)
If the class name doesn’t exist, print ** class doesn't exist ** (ex: $ show MyModel)
If the id is missing, print ** instance id missing ** (ex: $ show BaseModel)
If the instance of the class name doesn’t exist for the id, print ** no instance found ** (ex: $ show BaseModel 121212)
destroy: Deletes an instance based on the class name and id (save the change into the JSON file). Ex: $ destroy BaseModel 1234-1234-1234.
If the class name is missing, print ** class name missing ** (ex: $ destroy)
If the class name doesn’t exist, print ** class doesn't exist ** (ex:$ destroy MyModel)
If the id is missing, print ** instance id missing ** (ex: $ destroy BaseModel)
If the instance of the class name doesn’t exist for the id, print ** no instance found ** (ex: $ destroy BaseModel 121212)
all: Prints all string representation of all instances based or not on the class name. Ex: $ all BaseModel or $ all.
The printed result must be a list of strings (like the example below)
If the class name doesn’t exist, print ** class doesn't exist ** (ex: $ all MyModel)
update: Updates an instance based on the class name and id by adding or updating attribute (save the change into the JSON file). Ex: $ update BaseModel 1234-1234-1234 email "[email protected]".
Usage: update ""
Only one attribute can be updated at the time
You can assume the attribute name is valid (exists for this model)
The attribute value must be casted to the attribute type
If the class name is missing, print ** class name missing ** (ex: $ update)
If the class name doesn’t exist, print ** class doesn't exist ** (ex: $ update MyModel)
If the id is missing, print ** instance id missing ** (ex: $ update BaseModel)
If the instance of the class name doesn’t exist for the id, print ** no instance found ** (ex: $ update BaseModel 121212)
If the attribute name is missing, print ** attribute name missing ** (ex: $ update BaseModel existing-id)
If the value for the attribute name doesn’t exist, print ** value missing ** (ex: $ update BaseModel existing-id first_name)
All other arguments should not be used (Ex: $ update BaseModel 1234-1234-1234 email "[email protected]" first_name "Betty" = $ update BaseModel 1234-1234-1234 email "[email protected]")
id, created_at and updated_at cant’ be updated. You can assume they won’t be passed in the update command
Only “simple” arguments can be updated: string, integer and float. You can assume nobody will try to update list of ids or datetime
Let’s add some rules:

You can assume arguments are always in the right order
Each arguments are separated by a space
A string argument with a space must be between double quote
The error management starts from the first argument to the last one

Console v.4

Update your command interpreter (console.py) to allow those actions: show, create, destroy, update and all with all classes created previously.

Amenty v.1

Create class Amenity (models/amenity.py):
Public class attributes:
name: string - an empty string

BaseModel v.3

Update models/base_model.py: to link your BaseModel to FileStorage by using the variable storage

import the variable storage
in the method save(self):
call save(self) method of storage
init(self, *args, **kwargs):
if it’s a new instance (not from a dictionary representation), add a call to the method new(self) on storage

Review v.1

create class Review (models/review.py):
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

README, AUTHORS

Write a readme that has a description of the project, the command interpreter and the file AUTHORS whit the name and email.

File init of models

import file_storage.py
create the variable storage, an instance of FileStorage
call reload() method on this variable

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.