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:
- Display item. An item should have its' brand, category, comments and rating from consumers
- Update item
- Delete item
- User registration
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"
}
]
VISITOR
- Permissions: GET
'/categories'
, GET'/items'
ADMIN
- Permissions: GET
'/categories'
, GET'/items'
, DELETE'/items/<int:item_id>'
, PATCH'/items/<int:item_id>'
-
Python 3.9 - Follow instructions to install the latest version of python for your platform in the python docs
-
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
-
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
-
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.py
and can referencemodels.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
withjwt
provided bypython-jose
. Please avoid usingpython-jose-cryptodome
because it's not compatible to heroku's python environment.
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
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
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
- 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.
-
Set up database Create a database using
bit.io
and save the database url. Initiate databse using psql. -
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.
-
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