Skip to content

Backend code for the Calgary Distress Center project.

License

Notifications You must be signed in to change notification settings

uwblueprint/cdc-backend

Repository files navigation

Getting Started (Contributors Only)

  1. Clone this repo and the frontend repo (cdc-frontend)
  2. Grab the secrets
  3. Follow steps below in Python setup section if you haven't done so before
  4. Follow steps below in Running the backend repo section

About Distress Centre Calgary

The Distress Centre Calgary (DCC) is an organization dedicated towards providing crisis support for Calgary and southern Alberta residents. DCC provides various programs to reach all population segments who are in need of help, including a 24 hour crisis line and counselling. The organization has also provided several services for teenagers given the increasing prevalence of mental health issues among this population demographic.

Team

F21 and W22

FYDP: Jay Dhulia, Dhruvin Balar, Amolik Singh, Ahmed Hamodi

W21 and S21

Project Lead: Ahmed Hamodi
Product Manager: Aaron Abraham
Designers: Jack Zhang, Kouthar Waled
Developers: Jay Dhulia, Dhruvin Balar, Amolik Singh, Vivian Liu, Kevin Hu


Local Development Setup

Frontend

See cdc-frontend for frontend setup.

Backend

Python setup

  1. Ensure that you have Python 3.9.1 on your system by running python3 --version. If you don't, please upgrade your Python.
  2. If you don't have an environment setup already within the repo: python3 -m venv env
    • Note: you will only need to do the above command once.
  3. Activate the virtual environment.
    • On a mac operating system, use: . ./env/bin/activate
    • On a windows operating system, use: source ./env/Scripts/activate
  4. Install Postgres - Version 12. Choose user "Postgres" with blank password for local development.
    • On Mac, the recommended tool for managing your Postgres installation is Postgres App
    • On Windows, download Postgres from here and then use the script in scripts/PSQL Server Management.bat to start/stop your Postgres Server
  5. Once Postgres is installed, create a database with the name: postgres_cdc_dev
  6. Install the requirements, and setup Postgres: make install

Note: Every time you run git commit in this repo, it will run some lint checks. It won't let you commit unless the lint checks pass. Note that this means you may have to run git commit multiple times, as each git commit will attempt to fix the files! Some files may fail to auto-fix, in which case, you will have to ensure you fix them.

Once you have the requirements installed, you should be able to develop by just activating the environment (step 2).

Python - adding a new requirement

  1. Update the file requirements.in with the name of the library that you want to add.
  2. Install pip-compile if you don't have it already - pip install pip-tools.
  3. Run pip-compile requirements.in
  4. Download the updated packages pip install -r requirements.txt
  5. Check locally to ensure that you haven't broken anything

Running the backend repo

PyCharm

  1. The run configurations should automatically be loaded and working, select the dev environment and hit the play button. Contact Jay if you have trouble setting this up.

Mac

  1. Ensure you are in the root directory, and your virtual env is activated. Also make sure your Postgres is running.
  2. Run export PYTHONPATH=.
  3. Run export CONFIG_PATH=configs/dev-config.yaml if running locally, or export CONFIG_PATH=configs/dev-aws-config.yaml if running with AWS (S3) backend.
  4. If you have not done so recently, run make install as it will update any schema changes.
  5. Run python app/__main__.py
  6. You should see a SERVER STARTED message along with configuration details

Note, if you get a "port 5432 in use" error on the postgres app, do the following:

  1. Find the pid of the process using that port: sudo lsof -n -i :5432
  2. Kill the process by using the PID from above result: sudo kill -9 <PID>

If that does not work, you can run sudo pkill -u postgres to clear the port and then restart postgres.

Windows

  1. Ensure you are in the root directory, and your virtual env is activated. Also make sure your Postgres is running.
  2. Run set PYTHONPATH=.. Note: if you are using bash on Windows you will have to use export instead of set
  3. Run set CONFIG_PATH=configs/dev-config.yaml, if running locally, or set CONFIG_PATH=configs/dev-aws-config.yaml if running with AWS (S3) backend. Note: if you are using bash on Windows you will have to use export instead of set
  4. If you have not done so recently, run the scripts to create and populate the database:
       python scripts/create-tables.py
       python scripts/insert_data.py
    
  5. Run python app/__main__.py
  6. You should see a SERVER STARTED message along with configuration details

To call any APIs that require authentication without the frontend running (ex. using curl or Postman), you'll need an access token. You can generate a token for your account this with the command:

todo

This script will output a JSON object – you can use the idToken value and provide it as a bearer token to your API calls. This token expires every hour, and you can rerun this script to generate a new one.

Minifying JS files

  1. Open https://jscompress.com/
  2. Go to the Upload Javascript Files tab
  3. Upload all the files under app/public/static/js/components/
  4. Upload app/public/static/js/libraries/TransformControls.js
  5. Check the box in the top right corner for ECMAScript 2021 (via babel-minify)
  6. Hit Compress
  7. Download the file as component.min.js and place it in app/public/static/js/
  8. Update the repo https://github.com/jaydhulia/blueprint-cdc-static

Deployment

todo