Skip to content

Focal-App/focal-api

Repository files navigation

FocalApi

Focal API is a Phoenix/Elixir API that pairs with Focal App.

Local Development Setup

To start your Phoenix server:

  1. Clone the project git clone https://github.com/Focal-App/focal-api.git
  2. Navigate to project cd focal-api
  3. Install dependencies with mix deps.get
  4. Create and migrate your database with mix ecto.setup
  5. Setup Environment Variables. Create a .env file in your project folder root and add the following
export GOOGLE_CLIENT_ID="Get from Teammate"
export GOOGLE_CLIENT_SECRET="Get from Teammate"
export CLIENT_HOST=http://localhost:<client_port>
  1. Start Phoenix endpoint
source .env
mix phx.server
  1. Run tests
source .env
mix text
  1. Optional - See all routes mix phx.routes. Note that all routes are authenticated except for /api/users, which I purposely left public for demonstration purposes.

Now you can visit localhost:4000 from your browser.

Testing Routes with Postman

Running routes with Postman is easiest on the local development.

  1. On your browser, open your developer console to the network tab
  2. Run the local frontend application and log in with google
  3. Move around the site until you see a cookie header pop up in the network tab image
  4. Copy this into your Postman Request, COOKIE header image
  5. Proceed with any requests

Routes

Clients

Packages

Events

Workflows

Tasks

Troubleshooting

Dropping the Entire FocalAPI Database

mix ecto.drop --repo FocalApi.Repo
mix ecto.create
mix ecto.migrate
mix run priv/repo/seeds.exs

Dropping the Clients Table

mix ecto.rollback
mix ecto.migrate
mix run priv/repo/seeds.exs

Resetting the Test Database after a schema change

dropdb focal_api_test
mix ecto.migrate

Deploying to Heroku from CLI

git push heroku <branch_name>:master

Resetting Deployed Heroku Databases

heroku pg:info // get db_name from add-on field. 
heroku pg:reset DB_NAME
heroku run MIX_ENV=prod mix ecto.migrate
heroku run MIX_ENV=prod mix run priv/repo/seeds.exs
heroku restart

Updating a schema triggers errors

  1. Update schema and create new migration record
  2. Update any views related to the schema
  3. Drop Test database
  4. Run migration
  5. Run all tests

Migrations, when run, cannot be updated. If you need to make any updates to the migration changes you just made, you will need to either delete the migration file and create a new one with all correct changes. Or, create a new migration file specifying the changes you missed.