This project is a virtual bookshelf for students. Students are able to add their books to the bookshelf, give them a rating, update the rating and search through book lists.
All backend code follows PEP8 style guidelines.
- Flask
- Flask-CORS
- SQLAlchemy
- JSONify
- Unittest
- Developers using this project should already have Python3, pip and node installed on their local machines.
- Start your virtual environment
From the backend folder run
pip install virtualenv
python -m virtualenv env
# Mac/Linux users
source venv/bin/activate
# Windows users
source env/Scripts/activate
- Install dependencies
From the backend folder run
# All required packages are included in the requirements file.
pip install -r requirements.txt
# In addition, you will need to UNINSTALL the following:
pip uninstall flask-socketio -y
All required packages are included in requirements.txt
file.
- Run the Project
Step 0: Start or Stop the PostgreSQL server
Click here for reference.
Step 1 - Create and Populate the database
-
Verify the database username
Verify that the database user in the/backend/books.psql
,/backend/models.py
, and/backend/test_flaskr.py
files must bepostgres
(default username). -
Create the database and a user
In your terminal, navigate to thebackend
directory, and run the following:
cd backend
# Connect to the PostgreSQL
psql -U postgres
#View all databases
\l
# Create the database, create a user - `student`, grant all privileges to the student
\i setup.sql
# Exit the PostgreSQL prompt
\q
- Create tables
Once your database is created, you can create tables (bookshelf
) and apply contraints,
# Mac users
psql -f books.psql -U postgres -d bookshelf
# Linux users
su - postgres bash -c "psql bookshelf < /path/to/exercise/backend/books.psql"
You can even drop the database and repopulate it, if needed, using the commands above.
Step 2: Start the backend server
Navigate to the /backend/flaskr/__init__.py
file, start your (backend) Flask server by running the command below from the /backend
directory.
export FLASK_APP=flaskr
export FLASK_ENV=development
flask run
These commands put the application in development and directs our application to use the __init__.py
file in our flaskr folder. Working in development mode shows an interactive debugger in the console and restarts the server whenever changes are made. If running locally on Windows, look for the commands in the Flask documentation.
The application will run on http://127.0.0.1:5000/
by default and is set as a proxy in the frontend configuration. Also, the current version of the application does not require authentication or API keys.
(You can start the frontend even before the backend is up!)
From the frontend
folder, run the following commands to start the client:
npm install // only once to install dependencies
npm start
By default, the frontend will run on localhost:3000
. Close the terminal if you wish to stop the frontend server.
If any exercise needs testing, navigate to the /backend
folder and run the following commands:
python test_flaskr.py
The output will looks as:
-------------------
Ran 0 tests in 0.000s
OK
Note:
Once you run the test to delete a particular book, it will delete that book (book_id) from the database. Therefore the same test won't pass again. You can re-run the test with different book_id.
Alternativley, you can repopulate the database anytime by running the following commands from backend
folder. Refer previous "Step 1 - Create and Populate the database" .
See it in this page
You can feel free to expand on the project in any way you can dream up to extend your skills. For instance, you could add additional book information to each entry or create individual book views including more information about the book, your thoughts or when you completed it.