Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahmadyousif89/airbnb_clone_v2
https://github.com/ahmadyousif89/airbnb_clone_v2
Last synced: about 6 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/ahmadyousif89/airbnb_clone_v2
- Owner: AhmadYousif89
- Created: 2024-04-18T03:10:13.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-07T16:23:53.000Z (5 months ago)
- Last Synced: 2024-06-07T17:55:33.453Z (5 months ago)
- Language: Python
- Size: 1.38 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Authors: AUTHORS
Awesome Lists containing this project
README
HBNB - The Console
![project_logo](./assets/hbnb.png)
## Introduction
The AirBnB clone is a full-stack web application that integrats a database storage, a back-end API, and a front-end interface.
This project is part of the (Alx) Holberton School Software Engineering program.This repository contains the initial stage of a student project to build a clone of the AirBnB website. This stage implements a backend interface, or console, to manage program data. Console commands allow the user to create, update, and destroy objects, as well as manage file storage. Using a system of JSON serialization/deserialization, storage is persistent between sessions.
---
Repository Contents by Project Task
| Tasks | Files | Description |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| 0: Authors/README File | [AUTHORS](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/AUTHORS) | Project authors |
| 1: Pep8 | N/A | All code is pep8 compliant |
| 2: Unit Testing | [/tests](https://github.com/AhmadYousif89/AirBnB_clone_v2/tree/main/tests) | All class-defining modules are unittested |
| 3. Make BaseModel | [/models/base_model.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/base_model.py) | Defines a parent class to be inherited by all model classes |
| 4. Update BaseModel w/ kwargs | [/models/base_model.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/base_model.py) | Add functionality to recreate an instance of a class from a dictionary representation |
| 5. Create FileStorage class | [/models/engine/file_storage.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/engine/file_storage.py) [/models/\_ _init_ \_.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/__init__.py) [/models/base_model.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/base_model.py) | Defines a class to manage persistent file storage system |
| 6. Console 0.0.1 | [console.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/console.py) | Add basic functionality to console program, allowing it to quit, handle empty lines and ^D |
| 7. Console 0.1 | [console.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/console.py) | Update the console with methods allowing the user to create, destroy, show, and update stored data |
| 8. Create User class | [console.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/console.py) [/models/engine/file_storage.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/engine/file_storage.py) [/models/user.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/user.py) | Dynamically implements a user class |
| 9. More Classes | [/models/user.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/user.py) [/models/place.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/place.py) [/models/city.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/city.py) [/models/amenity.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/amenity.py) [/models/state.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/state.py) [/models/review.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/review.py) | Dynamically implements more classes |
| 10. Console 1.0 | [console.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/console.py) [/models/engine/file_storage.py](https://github.com/AhmadYousif89/AirBnB_clone_v2/blob/main/models/engine/file_storage.py) | Update the console and file storage system to work dynamically with all classes update file storage |
## Get Started
1. Start by cloning this project:
```sh
git clone https://github.com/AhmadYousif89/AirBnB_clone.git
cd AirBnB_clone
```2. Once the repository is cloned locate the "console.py" file and run it as follows:
```sh
/AirBnB_clone$ ./console.py
```4. When this command is run the following prompt should appear:
```sh
Welcome to Airbnb console. Type help or ? to list commands.(hbnb)
```5. 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
-> 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 or adds new to an object based on its class name and id
-> destroy - Destroys an object based on class and UUID
-> count - Counts the number of created objects for a given class or all classes
-> 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: .([[name_arg value_arg]|[kwargs]])
Advanced syntax is implemented for the following commands:
* create
* all
* count
* show
* destroy
* update## Project Overview
This is an overview diagram representing the project workflow.
![diagram](./assets/diagram.png)
Examples
Examples of using the console both interactively and non-interactively:
- Interactive mode:
```sh
$ ./console.py
Welcome to the airbnb console. Type help or ? to list commands.(hbnb) help
Documented commands (type help ):
========================================
EOF all count create destroy help quit show update(hbnb) help create
Creates a class of any type
[Usage]: create(hbnb) quit
$
```- Non-interactive mode:
```sh
$ echo 'help' | ./console.py
Welcome to the airbnb console. Type help or ? to list commands.(hbnb)
Documented commands (type help ):
========================================
EOF all count create destroy help quit show update(hbnb)
$
``````sh
$ echo 'help create' | ./console.py
Welcome to the airbnb console. Type help or ? to list commands.Creates a class of any type
[Usage]: create(hbnb)
$
```
Primary Command Syntax
###### Example 0: Create an object
Usage: create
```sh
(hbnb) create BaseModel
``````sh
(hbnb) create BaseModel
3aa5babc-efb6-4041-bfe9-3cc9727588f8
(hbnb)
```###### Example 1: Show an object
Usage: show <\_id>
```sh
(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 <\_id>
```sh
(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 <\_id>
```sh
(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: Show all User objects
Usage: .all()
```sh
(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 1: Destroy a User
Usage: .destroy(<\_id>)
```sh
(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 2: Update User (by attribute)
Usage: .update(<\_id>, , )
```sh
(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 3: Update User (by dictionary)
Usage: .update(<\_id>, )
```sh
(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)}"]
```
## Testing
```sh
$ python3 -m unittest discover tests/
```