Giter Club home page Giter Club logo

fsnd-capstone's Introduction

FSND Final Project

Gourmet App

As a foreigner living in the country, who also likes snacks, I often have problems choosing a good snack in front of numorous options. As a result, I developed this app that gathers comments from consumers to help people like me find the right snack they want. Gourmet App is used to display various kinds of items by categories, as with comments from consumers. The application function includes:

  1. Display item. An item should have its' brand, category, comments and rating from consumers
  2. Update item
  3. Delete item
  4. User registration

APIs

GET '/categories'

  • Fetches a dictionary of categories in which the keys are the ids and the value is the corresponding string of the category
  • Request Arguments: None
  • Returns: An object with a single key, categories, that contains an object of id: category_string key: value pairs.
  • Example:
{
    "1": "Chips",
    "2": "Cookies",
    "3": "Dried Fruits",
    "4": "Popcorn",
    "5": "Pretzels"
}

GET '/items'

  • Fetches all items in database with id as key
  • Request Arguments: None
  • Returns: A list of items with id, title, brand, category and comment
  • Example:
"items": [
        {
            "brand": "belVita",
            "category": 2,
            "comment": "Perfect for Breakfast on the Go",
            "id": 2,
            "title": "Cranberry Orange Breakfast Biscuits"
        }
]

DELETE '/items/<int:item_id>'

  • Delete the item with the given item_id from database
  • Request Arguments: item_id
  • Returns: The deleted item with id, title, brand, category and comment
  • Example:
"items": [
        {
            "brand": "belVita",
            "category": 2,
            "comment": "Perfect for Breakfast on the Go",
            "id": 2,
            "title": "Cranberry Orange Breakfast Biscuits"
        }
]

PATCH '/items/<int:item_id>'

  • Update the item with the given item_id
  • Request Arguments: item_id
  • Returns: The updated item with id, title, brand, category and comment
  • Example:
"items": [
        {
            "brand": "belVita",
            "category": 2,
            "comment": "Perfect for Breakfast on the Go",
            "id": 2,
            "title": "Cranberry Orange Breakfast Biscuits"
        }
]

Roles

VISITOR

  • Permissions: GET '/categories', GET '/items'

ADMIN

  • Permissions: GET '/categories', GET '/items', DELETE '/items/<int:item_id>', PATCH '/items/<int:item_id>'

Backend - Gourmet App

Setting up the Backend

Install Dependencies

  1. Python 3.9 - Follow instructions to install the latest version of python for your platform in the python docs

  2. Virtual Environment - We recommend working within a virtual environment whenever using Python for projects. This keeps your dependencies for each project separate and organized. Instructions for setting up a virual environment for your platform can be found in the python docs

  3. PIP Dependencies - Once your virtual environment is setup and running, install the required dependencies by navigating to the /backend directory and running:

pip3 install -r requirements.txt

Key Pip Dependencies

  • Flask is a lightweight backend microservices framework. Flask is required to handle requests and responses.

  • SQLAlchemy is the Python SQL toolkit and ORM we'll use to handle the lightweight SQL database. You'll primarily work in app.pyand can reference models.py.

  • python-jose The JavaScript Object Signing and Encryption (JOSE) technologies can be used to encrypt and/or sign content using a variety of algorithms. You'll primarily work in auth.py with jwt provided by python-jose. Please avoid using python-jose-cryptodome because it's not compatible to heroku's python environment.

Set up the Database

With Postgres running, create a fsnd database:

createdb fsnd

Populate the database using the fsnd.psql file provided. From the backend folder in terminal run:

export DATABASE_URL=postgresql://localhost:5432/fsnd
psql "$DATABASE_URL" < fsnd.psql

Run the Server

From within the backend folder first ensure you are working using your created virtual environment.

To run the server, execute:

FLASK_APP=app.py FLASK_DEBUG=True flask run

Testing

Write at least one test for the success and at least one error behavior of each endpoint using the unittest library.

To deploy the tests, run

dropdb fsnd_test
createdb fsnd_test
psql fsnd_test < fsnd.psql
python test_fsnd.py

Deploy on Heroku

  1. Create a new app
heroku create -a heroksp
# For example, 
# heroku create myapp-663697908 --buildpack heroku/python
# https://myapp-663697908.herokuapp.com/ | https://git.heroku.com/myapp-663697908.git

This returns a [heroku_remote_git_url] which could be used in the next step.

  1. Set up database Create a database using bit.io and save the database url. Initiate databse using psql.

  2. Set up environment variable Go to your Heroku Dashboard in the browser and access your application's settings. You will have to go to the Heroku dashboard >> Particular App >> Settings >> Reveal Config Vars section to add and set up variables. alt text

  3. Deploy

  • Clone this repository
  • Add Heroku remote
git remote add heroku [heroku_remote_git_url]
  • Push to heroku to trigger automatical build
git push heroku main

fsnd-capstone's People

Contributors

ceciliaruisun avatar jackyren 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.