Catalog Project for Udacity Full Stack Nanodegree.
This project is a python/flask application that supports CRUD operations against a sqlite database. The database contains items that might be stocked by a sporting goods store. The items can be filtered by category (Baseball, Football etc.) and the application allows users to add/edit/delete items as necessary. All changes to the data are persisted to the sqlite database using POST operations on the flask endpoints.
The database that this program queries contains three tables: user, categories and items. Categories and items have a foriegn key relationship to the user table, and items has a foriegn key relationship to the categories table.
The definitions of these tables is as follows:
id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
email = Column(String(250), nullable=False)
picture = Column(String(250))
id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=False)
user_id = Column(Integer, ForeignKey('user.id'))
user = relationship(User)
id = Column(Integer, primary_key=True)
title = Column(String(250), nullable=False)
description = Column(String(500))
cat_id = Column(Integer, ForeignKey('categories.id'))
user_id = Column(Integer, ForeignKey('user.id'))
user = relationship(User)
categories = relationship(Categories)
This project uses a virtual machine (VM) to run a SQL database server.
- If you don't already have virtual box on your machine, you can download it here:
- Download and install Vagrant (if you do not already have it installed). This is the software that configures the VM and allows the host (your machine) to talk to the VM:
- https://www.vagrantup.com/downloads.html
- you should be able to run
$ vagrant --version
after installation to see the version that was installed.
- Clone this repository: https://github.com/jkolden/catalog.git to a directory on your local machine and then cd into this directory.
- cd into the vagrant subdirectory
- Bring the VM up with the command
vagrant up
- Log into the VM with
vagrant ssh
- This application will come with a prepopulated database named sportingequipment.db
- If required for this assignment you can delete the sportingequipment.db file from the catalog subdirectory and recreate it by running the following commands at the command line:
- cd into the vagrant/catalog directory
- vagrant@vagrant:/vagrant/catalog$ python database_setup1.py
- vagrant@vagrant:/vagrant/catalog$ python categories.py
- You should now see the sportingequipment.db file created inside your vagrant/catalog subdirectory.
- At the
vagrant@vagrant:~$
prompt, cd into: /vagrant/catalog. - In the /vagrant/catalog subdirectory run the project file:
- vagrant@vagrant:/vagrant/catalog$ python project.py
- You can now access the running application on http://localhost:8000/
- The recommended browser is Google Chrome.
- The application homepage provides a list of categories and their respective items.
- Before you can perform any operations you will need to click the
login
link in the upper right corner.
- You can login with your google sign in.
- After successfully signing in you will be redirected to the catalog app homepage and your username will appear in the upper right corner.
- Select a category on the left to see the items that are in that category. The items will be displayed on the right.
- Select an item to see the details of that item.
- Click the
create new item
link to add a new item. You will be recorded as the owner of the item and you will have priviledges to edit and/or delete this item as well. - To logout, simply click the
logout
link in the upper right corner.
This catalog app provides three JSON endpoints that can be consumed as a GET request in any other application:
- The first endpoint is http://localhost:8000/catalog.json/ and the response payload will be an object of all categories with an array of items belonging to that category.
- The second endpoint is /<category_name>/catalog.json (e.g. http://localhost:8000/Football/catalog.json) and this provides a list of items within a given catalog.
- The third and final endpoint is /<category_name>/<item_name>/catalog.json (e.g. http://localhost:8000/Football/Riddell%20Speedflex%20Helmet/catalog.json) and this provides item detail for a specific item.