Skip to content

untalinfo/AirBnB_clone_v2

 
 

Repository files navigation

HBNB - MySQL

This repository contains the third stage of a student project to build a clone of the AirBnB website. This stage implements the inclusion of a database storage feature on the backend interface, or console, managin the program data as in a file storage as in the database system. Console commands allow the user to create, update, and destroy objects, as well as manage file and database storage.

A JSON serialization/deserialization is used for the file storage system. The storage is persistent between sessions. As for the database storage, the library SQLAlchemy was used to manage an MySQL database.


Repository Contents

Files Description
AUTHORS Project authors
N/A All code is pep8 compliant
/tests All class-defining modules are unittested
/models/base_model.py Defines a parent class to be inherited by all model classes
/models/base_model.py Add functionality to recreate an instance of a class from a dictionary representation
/models/engine/file_storage.py /models/_ init _.py /models/base_model.py Defines a class to manage persistent file storage system
console.py Add basic functionality to console program, allowing it to quit, handle empty lines and ^D
console.py Update the console with methods allowing the user to create, destroy, show, and update stored data
console.py /models/engine/file_storage.py /models/user.py Dynamically implements a user class
/models/user.py /models/place.py /models/city.py /models/amenity.py /models/state.py /models/review.py Dynamically implements more classes
console.py /models/engine/file_storage.py Update the console and file storage system to work dynamically with all classes update file storage


Previous Requierements

This repository was created with:

  • Ubuntu 14.04 LTS
  • Python 3.4.3
  • MySQL server 5.7

    Install MySQL 5.7 in Ubuntu 14.04 LTS

    $ echo 'deb http:https://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7-dmr' | sudo tee -a /etc/apt/sources.list
    $ sudo apt-get update
    $ sudo apt-get install mysql-server-5.7
    ...
    $ mysql --version
    mysql Ver 14.14 Distrib 5.7.8-rc, for Linux (x86_64) using EditLine wrapper
    $

  • Python's SQLAlchemy module version 1.2.x

    Install SQLAlchemy module version 1.2.x

    $ pip3 install SQLAlchemy==1.2.5
    ...
    $ python3
    >>> import sqlalchemy
    >>> sqlalchemy.version
    '1.2.5'

General Use

  1. First clone this repository.

  2. Once the repository is cloned locate the "console.py" file and run it as follows:

/AirBnB_clone_V2$ ./console.py
  1. When this command is run the following prompt should appear:
(hbnb)
  1. This prompt designates you are in the "HBnB" console. There are a variety of commands available within the console program.
Commands
* create - Creates an instance based on given class

* destroy - Destroys an object based on class and UUID

* show - Shows an object based on class and UUID

* all - Shows all objects the program has access to, or all objects of a given class

* update - Updates existing attributes an object based on class name and UUID

* quit - Exits the program (EOF will as well)
Alternative Syntax

Users are able to issue a number of console command using an alternative syntax:

Usage: <class_name>.<command>([<id>[name_arg value_arg]|[kwargs]])

Advanced syntax is implemented for the following commands:

* all - Shows all objects the program has access to, or all objects of a given class

* count - Return number of object instances by class

* show - Shows an object based on class and UUID

* destroy - Destroys an object based on class and UUID

* update - Updates existing attributes an object based on class name and UUID


Examples

Primary Command Syntax

Example 0: Create an object

Usage: create <class_name>

(hbnb) create BaseModel
(hbnb) create BaseModel
3aa5babc-efb6-4041-bfe9-3cc9727588f8
(hbnb)                   
Example 1: Show an object

Usage: show <class_name> <_id>

(hbnb) show BaseModel 3aa5babc-efb6-4041-bfe9-3cc9727588f8
[BaseModel] (3aa5babc-efb6-4041-bfe9-3cc9727588f8) {'id': '3aa5babc-efb6-4041-bfe9-3cc9727588f8', 'created_at': datetime.datetime(2020, 2, 18, 14, 21, 12, 96959), 
'updated_at': datetime.datetime(2020, 2, 18, 14, 21, 12, 96971)}
(hbnb)  
Example 2: Destroy an object

Usage: destroy <class_name> <_id>

(hbnb) destroy BaseModel 3aa5babc-efb6-4041-bfe9-3cc9727588f8
(hbnb) show BaseModel 3aa5babc-efb6-4041-bfe9-3cc9727588f8
** no instance found **
(hbnb)   
Example 3: Update an object

Usage: update <class_name> <_id>

(hbnb) update BaseModel b405fc64-9724-498f-b405-e4071c3d857f first_name "person"
(hbnb) show BaseModel b405fc64-9724-498f-b405-e4071c3d857f
[BaseModel] (b405fc64-9724-498f-b405-e4071c3d857f) {'id': 'b405fc64-9724-498f-b405-e4071c3d857f', 'created_at': datetime.datetime(2020, 2, 18, 14, 33, 45, 729889), 
'updated_at': datetime.datetime(2020, 2, 18, 14, 33, 45, 729907), 'first_name': 'person'}
(hbnb)

Alternative Syntax

Example 0: Create with attributes

Usage: create <class_name> <att_name>=<att_value>

(hbnb) create State name='California'
f430bb1d-e14e-478a-9ef4-f017e4ce9c08
(hbnb)
Example 1: Show all User objects

Usage: <class_name>.all()

(hbnb) User.all()
["[User] (99f45908-1d17-46d1-9dd2-b7571128115b) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 34, 92071), 'id': '99f45908-1d17-46d1-9dd2-b7571128115b', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 34, 92056)}", "[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"]
Example 2: Destroy a User

Usage: <class_name>.destroy(<_id>)

(hbnb) User.destroy("99f45908-1d17-46d1-9dd2-b7571128115b")
(hbnb)
(hbnb) User.all()
(hbnb) ["[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"]
Example 3: Update User (by attribute)

Usage: <class_name>.update(<_id>, <attribute_name>, <attribute_value>)

(hbnb) User.update("98bea5de-9cb0-4d78-8a9d-c4de03521c30", name "Todd the Toad")
(hbnb)
(hbnb) User.all()
(hbnb) ["[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'name': 'Todd the Toad', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"]
Example 4: Update User (by dictionary)

Usage: <class_name>.update(<_id>, )

(hbnb) User.update("98bea5de-9cb0-4d78-8a9d-c4de03521c30", {'name': 'Fred the Frog', 'age': 9})
(hbnb)
(hbnb) User.all()
(hbnb) ["[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'name': 'Fred the Frog', 'age': 9, 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 44.5%
  • HTML 36.0%
  • CSS 19.0%
  • Shell 0.5%