Skip to content

Restaurant happy hour Flask Application for Udacity Fullstack Nanodegree capstone project

Notifications You must be signed in to change notification settings

vdojnov/FSND-Capstone-Project

Repository files navigation

FSND-Capstone-Project

Udacity Fullstack Nanodegree capstone project

https://fsnd-happyhour.herokuapp.com/

The motivation of this project is to practice the skills learned during the Udacity FullStack NanoDegree program. The basis of the app for restaurant managers to be able to post their restraurant and menus for customers to be able to see and make reservations.

  • Link to course click here

  • Link to course syllabus, click here

The Stack

Getting Started

Requirements

Install the necessary requirmenets by running:

    pip install -r requirements.txt

Running on local machine

  1. Open a terminal and cd to the project directory and install requirements:
    cd ~/FSND-Capstone-Project
    # Then
    pip install -r requirements.txt
  1. Set up your DATABASE_URL variable depending on OS:
    export DATABASE_URL="{DATABASE_URL}"

    For Windows use:

    $env:DATABASE_URL="{DATABASE_URL}"
  1. Run ALL three migration commands ONLY on you first set up:
# Run the init command once
    python manage.py db init
    python manage.py db migrate
    python manage.py db upgrade

# Run the last 2 commands if/when you make changes to database structure
  1. Set up Authentication with Auth0.com. You need two roles with different permissions:

Customer:

permissions:
    post:reservation

Restaurant Manager:

permissions:
    post:restaurant
    patch:restaurant
    delete:restaurant
  1. Set up FLASK_APP variable depending on OS:
    export FLASK_APP=app.py

    For Windows use:

    $env:FLASK_APP="app.py"
  1. To run the app use:
    flask run

Endpoints and Error Handlers

ENDPONTS

  1. GET '/restaurants'
  2. GET '/restaurants/int:id'
  3. GET '/restaurants/int:id/menu'
  4. POST '/restaurants/int:id/reservation'
  5. POST '/restaurants'
  6. PATCH '/restaurants/int:id'
  7. DELETE '/restaurants/int:id'
GET '/restaurants'
- No Authorization required
- Gets all the restaurants that are in the database
- Does not take any arguments
- Returns
    {
        'success': True,
        'restaurants': [{
            "id": self.id,
            "name": self.name,
            "address": self.address
            }, ...]
}

GET '/restaurants/<int:id>'
- No Authorization required
- Gets all the info from a selected restaurant
- <int:id> relpaces the ID of the restaurant you want
- Returns:
    {
        'success': True,
        'restaurants': [{
            "id": self.id,
            "name": self.name,
            "address": self.address
            }]
    }

GET '/restaurants/<int:id>/menu'
- No Authorization required
- Gets the menu items that belong to a restaurnt, could be more than one
- <int:id> replaces the ID of restaurant you want to see the menu items 
- Returns:
    {
        'success': True,
        "items": [{
            "name": self.name,
            "description": self.description,
            "price": str(self.price),
            "restaurant_name": self.restaurnt_menu_item.name
            }, ...]
    }

POST '/restaurants/<int:id>/reservation'
- Requred Authorization with 'Customer' role
- Posts a reservation for the restaurant with id in <int:id>
- Required input (data type listed inside brackets):
    {
        "time_of_res": (datetime),
        "num_of_people": (int),
        "name_for_res": (string)
    }
- Returns all upcoming reservation for the customer making the reservation:
    {   
        'success': True,
        'upcoming_reservations': [{
            "time_of_res": self.time_of_res,
            "num_of_people": self.num_of_people,
            "restaurant_name": self.restaurant_name,
        }, ...]
        
    }

POST '/restaurants'
- Requred Authorization with 'Restaurant Manager' role
- Restaurant Manager can post their restaurant
- Required input (data type listed inside brackets):
    {
        "name": (string),
        "address": (string)
    }
- Returns all the restaurants that the user owns:
    {
        "success": True,
        "owned_restaurants": [{
            "id": self.id,
            "name": self.name,
            "address": self.address
        }, ...]
    }

PATCH '/restaurants/<int:id>'
- Requred Authorization with 'Restaurant Manager' role, and the Restaurant manager can only PATCH his/her own restaurnat
- Restaurant manager can edit their restaurants. They can edit the name, the address, or both
- Required input (data type listed inside brackets):
    {
        "name": (string),
        "address": (string)
    }
- Returns the the newly updated restaurant with the new information:
    {
        "name": 'NEW NAME',
        "address": 'NEW ADDRESS'
    }


DELETE '/restaurants/<int:id>'
- Requred Authorization with 'Restaurant Manager' role, and the Restaurant manager can only DELETE his/her own restaurnat
- Deletes the restaurant with id replaced by <int:id>
- Returns Response if deletes succesfully:
    {
        "success": True
    }

ERROR HANDLERS

Error 422 (Unprocessable)
Returns:
    {
      "success": False,
      "error": 422,
      "message": "unprocessable"
    }

Error 404 (Bad Request)
Returns:
    {
        "success": False,
        "error": 404,
        "message": "resource not found"
    }

Error 401 (Resource Not Found)
Returns:
    {
        "success": False,
        "error": 401,
        "message": "Unauthorized Error"
    }

Error 400 (Unauthorized Error)
Returns:
    {
        "success": False,
        "error": 400,
        "message": "Bad Request"
    }

Authentication

Testing

  • Testing instructions
  1. Create a new database for testing (choose and new name ex. new_testing_db)
    createdb new_testing_db
  1. In test_app.py set database_name and database_path from your local machine

  2. In the command line run

    python test_app.py
  1. The tests will run and should all be completed sucessfully

Deployment

This app is deployed on Heroku. For deployment, you need to:

  1. Install Heroku CLI and login to Heroku on the terminal

  2. create a setup.sh file and declare all your variables in the file

  3. Install gunicorn

    pip install gunicorn
  1. Create a Procfile and add the line below. The Procfile instructs Heroku on what to do. Make sure that your app is housed in app.py
    web: gunicorn app:app
  1. Install the following requirements
    pip install flask_script
    pip install flask_migrate
    pip install psycopg2-binary
  1. Freeze your requirements in the requirements.txt file
    pip freeze > requirements.txt
  1. Create Heroku app
    heroku create name_of_your_app
  1. Add git remote for Heroku to local repository
    git remote add heroku heroku_git_url
  1. Add postgresql add on for our database
    heroku addons:create heroku-postgresql:hobby-dev --app name_of_your_application
  1. Add all the Variables in Heroku under settings
    # This should already exist from the last step
    DATABASE_URL
    # Get these from Auth0
    AUTH0_DOMAIN
    ALGORITHMS
    API_AUDIENCE
  1. Push any changes to your GitHub Repository

  2. Push to Heroku

    git push heroku master
  1. Run Migrations to the Heroku database
    heroku run python manage.py db upgrade --app name_of_your_application

Visit your Heroku app on the hosted URL!

Authors

Acknowledgments

Special thanks to:

About

Restaurant happy hour Flask Application for Udacity Fullstack Nanodegree capstone project

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published