Skip to content

outintech/nbjc-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

Development setup

  • Install ruby-2.7.2

You will have to install this specific version. To do so, use whatever ruby version manager you want (both rvm and rbenv will work). If you run into any issues finding this version, make sure ruby-builder is up to date.

Dependencies

  • Install the dependencies. Installation is OS dependent. You can use brew if using a MacOS. On Ubuntu you can use sudo apt-get install.
    • Node
    • Yarn
    • Postgres
    • Redis

❗ On Ubuntu and probably other linux distributions

Yarn: curl --compressed -o- -L https://yarnpkg.com/install.sh | bash

Postgres:

  • Install postgresql-contrib and libpq-dev along with postgresql, see tutorial.

Redis:

  • Install redis-server
  • Edit the supervised directive to systemd, see tutorial. Follow the tutorial to the end of step 3, don't set a redis password.
  • Create a new user with the password see config/database.yml.
    • Open the postgres console psql postgres
    • Check all your users and roles using the \du; postgres command
    • If you don't have a user you can create one by using the postgres command CREATE USER new_user with PASSWORD 'your_super_secret_password';
    • Create the role and password for the app using CREATE ROLE nbjc_app LOGIN SUPERUSER PASSWORD 'YOUR_PASSWORD_HERE';

❗ NOTE: You will have to then upde config/local_env.yml.example file with the password used for the role nbjc_app in the last step, otherwise it will think your database password is literally 'password' as that is the assumed default password in config/database.yml

  • Start the services.

    If you installed these with brew, you can start them with brew services start <SERVICE>. If you're using Ubuntu, you can check the status of these services with the sudo systemctl status <SERVICE_NAME> bash command.

    • Postgres
    • Redis
  • Install gems with bundle install

    • Make sure the dependencies listed above are installed first to avoid errors when running bundle install
  • Check your local env setup with config/local_env.yml.example

    • Copy config/local_env.yml.example to config/local_env.yml
    • Update config/local_env.yml with correct variables

Start up the app

  • Get the database up and running: rake db:create

    • You may need to rename config/local_env.yml.example to config/local_env.yml
    • You may need to uncomment the line NBJC_APP_DATABASE_PASSWORD: and set the password to the one used when creating the nbjc_app role
  • Get the schema setup: rake db:migrate

Note: if you make a change in a migration file that has not been committed and do not see the change reflected in the schema run rake db:rollback and rerun the migration.

  • Seed the database" rake db:seed

If you need to drop the database and reseed use rake db:reset

  • Start the app: rails s

Seeding the database

  • All CSV files under db/seed_data/ will automatically be used to seed the DB
  • To add seeding data for a new table, create a new file under the mentioned directory that matches the table name
  • All CSV files in the directory must contain a header row and columns matching (at least) all required fields
  • See db/seed_data/languages.csv (which will seed the languages table) for an example

Test the routes

  • To get a full list of available routes check rails routes
Mocked routes

Adding and removing a new model

  • If you need to remove a model, first migrate down the relevant version
rails db:migrate:down VERSION=<NUMBER>
  • Then destroy the model
rails destroy model <MODEL_NAME>
Spaces
Endpoint Description Payload (JSON) Example Resonse
POST /api/v1/spaces
Create a new space, for a list of the fields and their types, refer to the schema and descriptions [here][schema-sheet]
{
    "space": {
        "provider_urn": "yelp:bxU7CnSO9cFhq_1tQyX40A",
        "provider_url": "https://www.yelp.com/biz/name",
        "name": "787 Coffee",
        "price_level": 2, 
        "address_attributes": {
            "address_1": "131 E 7th St",
            "address_2": "",
            "city": "New York",
            "postal_code": "10009",
            "country": "US",
            "state": "NY"
        },
        "languages_attributes": [
            {
                "name": "Polish"
            }
        ],
        "indicators_attributes": [
            {
                "id": 2
            }
        ],
        "photos_attributes": [
            {
                "url": "https://s3-media2.fl.yelpcdn.com/photo.jpg",
                "cover": true
            }
        ],
        "reviews_attributes": [
            {
                "anonymous": true,
                "vibe_check": 3,
                "rating": 4,
                "content": "This is a great place."
            }
        ],
        "phone": "+16466492774",
        "hours_of_op": {
            "open": [
                {
                    "is_overnight": false,
                    "start": "0800",
                    "end": "1500",
                    "day": 0
                }
            ]
        }
    }
}
      
201 success
GET /api/v1/spaces/:space_id
Get a space's details Includes all possible fields See the mock response for a fake space
/spaces/1
GET /api/vi/spaces?search=terms and filtering
Get all spaces with the search terms in their names The search terms should be the values for the "search" key, the price between 1-4 and the indicators should be an array of indicator ids.
			  {
				  "search": "bakery",
				  "filtering": {
					  "price": 2,
					  "indicators": [1, 2]
				  }
			  }
		  
See this the mock for
api/v1/spaces?price=3&search=bakery
PUT /api/v1/spaces/:space_id Update a space's details See the POST route for available fields for update 202 Success
DELETE /api/v1/spaces/:space_id Deletes a space Only admins will be able to delete a space 204 Success

Authentication and Authorization

Auth0

Diagram for login here

Testing

  • To get a bearer token for testing, login to the auth0 dashboard, navigate to the nbjc-app API and on the testing tab follow the instructions.

Running tests

rspec

Deployment

You can find the build pipeline in the circleci dashboard. Reach out in Slack for the pipeline link. Deployments only happen for tagged versions. See the circleci config in the .circleci folder.

  • See the tagging guidelines here

Contribution

  • A PR can only be merged when both build and test circleci jobs pass.

Authentication and Authorization

Auth0

Diagram for login here

Testing

  • To get a bearer token for testing, login to the auth0 dashboard, navigate to the nbjc-app API and on the testing tab follow the instructions.