brewhops / api

API for the brewhops fermentation tracking system
https://brewhops-api.now.sh
0 stars 0 forks source link

Brewhops API CircleCI codecov

Purpose of the API:

The general purpose of the API is to keep track of how a batch of beer is being brewed over time. There are some peripheral information pieces such as employees that are working on the system, the tanks that the batches are being brewed in, actions associated with those tanks, and the recipes for a brew.

Requirements

Startup

Both development and production environments require the use of a .env file to get environment variables. This .env file should never be committed, you can rename the example.env file in the project to .env and it will work.

It contains the following environment variables that are all required for local development with Docker.

For more information on the PG environment variables, check out the official postgres docker container docs

Development

  1. cp example.env .env will enable the default configuration.
  2. npm ci will install all of the dependencies.
  3. Run npm run watch-ts in a different terminal, this will trigger the typescript compiler to watch the source files for changes and re-transpile them.
  4. npm run build-images will run docker-compose, build new images, and run the api.
  5. npm run dev will run docker-compose, and run the api.

Postman

The postman collections at the root of this repo contains documentation for all of the avaiable api endpoints. It contains .collection.json and .environment.json that will need to be imported into postman so that authentication is automated for all requests.

Test Data

Once the application has started the init(small data set) or init-live(large data set) endpoint needs to be hit to initialize the test data for the application. Once hit (after success) this can take between 10 seconds to a minute to load all of the data.

Our Postman collections contain these routes, aptly named init and init-live.

If you prefer, the following curl commands can be used to hit both endpoints:

curl -X POST http://localhost:3000/init
curl -X POST http://localhost:3000/init-live

Checking the database (manually)

NOTE: for the automatic psql instance check the npm commands section.

To connect to the docker container and interact directly with the database, follow these steps

  1. Start up the postgreSQL docker container if it is not already running
  2. Open up a terminal window
  3. docker ps to get the name of the running DB docker container
  4. docker exec -it {name of DB container} bash -l
  5. psql -U {PGUSER} -d {database name}

You should now be logged into the psql program on the docker container

A few things to note:

npm commands