Code Monkey home page Code Monkey logo

freefrom-compensation-api's Introduction

Freefrom Compensation Backend

Overview

FreeFrom is a nonprofit dedicated to helping survivors of domestic violence achieve financial stability. On their website they have a compensation tool where users can answer a series of questions in order to get information about financial resources that are available to them depending on their state.

This repository contains the new Rails backend for the compensation tool and the CMS that allows FreeFrom administrators to change the content in the tool.

Local Development Setup

Install Ruby

Make sure you have ruby version 2.6.3 installed on your local machine, or install it using this guide: https://www.ruby-lang.org/en/documentation/installation/

Install PostgreSQL

Install and run a PostgreSQL version 11.4.

Set up database roles

  1. Start a Postgres client session: psql
  2. Create a new user: create user "freefrom-compensation-api-user";
  3. Give that user special permissions: alter user "freefrom-compensation-api-user" with superuser;
  4. Exit out of the client session: exit

Install Rails

Run the command gem install rails (make sure rails --version returns 5.2.3)

Set up app

  1. Clone this repository onto your local machine
  2. cd into the freefrom-compensation-api folder
  3. Run bundle install to install the app's dependencies (run gem install bundler if that doesn't work)
  4. Run rake db:setup to create the test and development databases
  5. Run rake db:migrate to set up the necessary database tables
  6. Run bundle exec rake import_data to import the seed data
  7. Run bundle exec rails s to start the server

API Documentation

Resource Categories

POST /resource_categories**

Creates a new Resource Category.

Request Payload: This endpoint does not require any request payload.

Response Payload: On success, this endpoint will return a 201 Created status and a new resource category object in the response body.

{
  "id": 1,
  "name": null,
  "short_description": null,
  "description": null,
  "icon": null,
  "seo_title": null,
  "seo_description": null,
  "seo_keywords": [],
  "share_image": null,
  "created_at": "2019-08-02T16:16:36.282Z",
  "updated_at": "2019-08-02T16:16:36.282Z"
}

PUT /resource_categories/:id**

Updates an existing Resource Category.

Request Payload: The request payload may include any of the following fields. To leave a field unchanged, just do not include it in the request payload. (Including a field and setting it's value to null in the request payload will erase that field value from the Resource Category.)

Field name Type
short_description string
name string
description string
icon binary
seo_title string
seo_description string
seo_keywords array[string]
share_image binary

Response Payload: On success, this endpoint will return a 200 Success response and the updated Resource Category in the response body. If the request was unauthorized, it will return a 302 Redirected status. If the Resource Category doesn't exist, it will return a 404 Not Found response.

DELETE /resource_categories/:id**

Deletes an existing Resource Category.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 204 No Content response and an empty response body. If the request was unauthorized, it will return a 302 Redirected status. If the Resource Category doesn't exist, it will return a 404 Not Found response.

GET /resource_categories/:id

Fetches an existing Resource Category.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 200 Success status and a Resource Category in the response body. If the Resource Category doesn't exist, it will return a 404 Not Found response.

GET /resource_categories/

Fetches all existing Resource Category.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 200 Success status and an array of Resource Categories in the response body.

Resources

POST /resource_categories/:id/resources?state=:state**

Creates a new Resource.

Request Params: This endpoint requires that a valid US state code (e.g. "NY" or "ME") be passed in with the state param.

Response Payload: On success, this endpoint will return a 201 Created status and a new resource object in the response body.

{
  "id": 1,
  "state": "NY",
  "time": null,
  "cost": null,
  "award": null,
  "likelihood": null,
  "safety": null,
  "story": null,
  "challenges": null,
  "resource_category_id": 2,
  "who": null,
  "when": null,
  "covered_expenses": null,
  "attorney": null,
  "tips": null,
  "created_at": "2019-08-02T16:36:09.933Z",
  "updated_at": "2019-08-02T16:36:09.933Z"
}

If the request was unauthorized, it will return a 302 Redirected status. If the Resource Category ID or state parameter are invalid, this endpoint will return a 400 Bad Request response, along with an error message explaining what went wrong.

PUT /resources/:id**

Updates an existing Resource.

Request Payload: The request payload may include any of the following fields. To leave a field unchanged, just do not include it in the request payload. (Including a field and setting it's value to null in the request payload will erase that field value from the Resource.)

Field name Type
state string
time string
cost string
award string
likelihood string
safety string
story string
challenges string
who string
when string
covered_expenses string
attorney string
tips array[string]
resource_category_id int

Response Payload: On success, this endpoint will return a 200 Success response and the updated Resource in the response body. If the request was unauthorized, it will return a 302 Redirected status. If the Resource doesn't exist, it will return a 404 Not Found response.

DELETE /resources/:id**

Deletes an existing Resource.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 204 No Content response and an empty response body. If the request was unauthorized, it will return a 302 Redirected status. If the Resource doesn't exist, it will return a 404 Not Found response.

GET /resources/:id

Fetches an existing Resource.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 200 Success status and a Resource in the response body. If the Resource doesn't exist, it will return a 404 Not Found response.

GET /mindsets/:mindset_id/resources?state=:state

Fetches a resource for a particular mindset and state.

Request Payload: This endpoint requires that a valid US state code (e.g. "NY" or "ME") be passed in with the state param.

Response Payload: On success, this endpoint will return a 200 Success status and a Resource in the response body. If the Mindset or Resource doesn't exist, the endpoint will return a 404 Not Found response.

Mindsets

POST /resource_categories/:id/mindsets**

Creates a new Mindset.

Request Params: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 201 Created status and a new Mindset in the response body.

{
  "id": 1,
  "description": null,
  "name": null,
  "resource_category_id": 1,
  "created_at": "2019-08-02T16:55:56.098Z",
  "updated_at": "2019-08-02T16:55:56.098Z"
}

If the request was unauthorized, it will return a 302 Redirected status. If the ResourceCategory ID is invalid, this endpoint will return a 400 Bad Request response, along with an error message explaining what went wrong.

PUT /mindsets/:id**

Updates an existing Mindset.

Request Payload: The request payload may include any of the following fields. To leave a field unchanged, just do not include it in the request payload. (Including a field and setting its value to null in the request payload will erase that field value from the Mindset.)

Field name Type
name string
description string
resource_category_id int

Response Payload: On success, this endpoint will return a 200 Success response and the updated Mindset in the response body. If the request was unauthorized, it will return a 302 Redirected status. If the Mindset doesn't exist, it will return a 404 Not Found response.

DELETE /mindsets/:id**

Deletes an existing Mindset.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 204 No Content response and an empty response body. If the request was unauthorized, it will return a 302 Redirected status. If the Mindset doesn't exist, it will return a 404 Not Found response.

GET /mindsets/:id

Fetches an existing Mindset.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 200 Success status and a Mindset in the response body. If the Mindset doesn't exist, it will return a 404 Not Found response

GET /mindsets

Fetches all existing Mindsets.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 200 Success status and an array of Mindsets (or an empty array if no Mindsets exist) in the response body.

QuizQuestions

POST /quiz_questions/**

Creates a new Quiz Question.

Request Params: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 201 Created status and a new Quiz Question in the response body.

{
  "id": 1,
  "title": null,
  "description": null,
  "created_at": "2019-08-02T16:55:56.098Z",
  "updated_at": "2019-08-02T16:55:56.098Z"
}

If the request was unauthorized, it will return a 302 Redirected status.

PUT /quiz_questions/:id**

Updates an existing QuizQuestion.

Request Payload: The request payload may include any of the following fields. To leave a field unchanged, just do not include it in the request payload. (Including a field and setting its value to null in the request payload will erase that field value from the QuizQuestion.)

Field name Type
title string
description string

Response Payload: On success, this endpoint will return a 200 Success response and the updated Quiz Question in the response body. If the request was unauthorized, it will return a 302 Redirected status. If the Quiz Question doesn't exist, it will return a 404 Not Found response.

DELETE /quiz_questions/:id**

Deletes an existing Quiz Question.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 204 No Content response and an empty response body. If the request was unauthorized, it will return a 302 Redirected status. If the Quiz Question doesn't exist, it will return a 404 Not Found response.

GET /quiz_questions/:id

Fetches an existing Quiz Question.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 200 Success status and a Quiz Question in the response body. If the Quiz Question doesn't exist, it will return a 404 Not Found response

GET /quiz_questions

Fetches all existing QuizQuestions.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 200 Success status and an array of QuizQuestions

GET /quiz_questions/quiz_responses

Fetches all QuizResponses associated with a QuizQuestion.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 200 Success status and a list of Quiz Responses in the response body. If the Quiz Question doesn't exist, it will return a 404 Not Found response.

QuizResponses

POST /quiz_questions/:id/quiz_responses**

Creates a new QuizResponse.

Request Params: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 201 Created status and a new QuizResponse in the response body.

{
  "id": 1,
  "text": null,
  "quiz_question_id": 1,
  "created_at": "2019-08-02T16:55:56.098Z",
  "updated_at": "2019-08-02T16:55:56.098Z"
}

If the request was unauthorized, it will return a 302 Redirected status. If the QuizQuestion ID is invalid, this endpoint will return a 400 Bad Request response, along with an error message explaining what went wrong.

PUT /quiz_responses/:id**

Updates an existing QuizResponse.

Request Payload: The request payload may include any of the following fields. To leave a field unchanged, just do not include it in the request payload. (Including a field and setting its value to null in the request payload will erase that field value from the QuizResponse.)

Field name Type
text string
quiz_question_id int
mindset_ids array[int]

Response Payload: On success, this endpoint will return a 200 Success response and the updated QuizResponse in the response body. If the request was unauthorized, it will return a 302 Redirected status. If the QuizResponse doesn't exist, it will return a 404 Not Found response.

DELETE /quiz_responses/:id**

Deletes an existing QuizResponse.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 204 No Content response and an empty response body. If the request was unauthorized, it will return a 302 Redirected status. If the QuizResponse doesn't exist, it will return a 404 Not Found response.

GET /quiz_responses/:id

Fetches an existing QuizResponse.

Request Payload: This endpoint requires no request payload.

Response Payload: On success, this endpoint will return a 200 Success status and a QuizResponse in the response body. If the QuizResponse doesn't exist, it will return a 404 Not Found respons (or an empty array if no QuizQuestions exist) in the response body.

** Requires a user logged in

Contributing

To contribute, see CONTRIBUTING.md

freefrom-compensation-api's People

Contributors

dependabot[bot] avatar dryan avatar danielkim1 avatar sarahgreen avatar

Stargazers

 avatar

Watchers

James Cloos avatar Jill Huchital avatar Scott Schaffter avatar Noah avatar  avatar  avatar Emily Samp avatar Grant Stromgren avatar

Forkers

jmkoni

freefrom-compensation-api's Issues

Editing Mindsets via Resource Categories doesn't work

Describe the bug
When you edit information about a mindset on the Resource Categories page, any changes you make to the mindset are not saved.

Expected behavior
I expect that changes to the mindset should be saved, OR the mindset shouldn't be editable on that page.

Replace README

  • Add a description of the project
  • Link to CONTRIBUTING.md
  • Document how to build the project locally, including any environment variables that need to be set

Update models based on sample content

FreeFrom provided us with some sample content (check pinned messages in the #proj-free-from Slack). We need to update the existing models to match the slight discrepancies in the sample content.

Editing lists of text is broken in the CMS

Describe the bug
Editing certain fields in the CMS breaks text formatting. This happens with any field on a Resource that is a list of text (e.g. "Challenges").

To Reproduce
Steps to reproduce the behavior:

  1. In the CMS, edit and update a resource.
  2. In the Compensation Compass, view your changes and notice that the formatting for list fields is broken.

Expected behavior
I expect that the formatting of all fields is preserved by the CMS unless explicitly changed by a user.

Update CONTRIBUTING.md

  • Check for anything that isn't relevant to this project and remove it
  • Document how to write tests for the project
  • Document any style guides that should be followed for this project

Link to GitHub issues page in CMS

Is your feature request related to a problem? Please describe.
When Amy and the team want to submit a bug report or feature request, they need to create a new GitHub issue. It would be easier for everyone if they could just click a link and be taken straight to the "Create a New Issue" page.

Describe the solution you'd like
Add a link to the CMS that goes straight to creating a new GitHub issue.

Clean up Gemfile

Go through the Gemfile and make sure we only load gems that are actually being used.

Link CMS Instructions Document in the CMS

Is your feature request related to a problem? Please describe.
I have a hard time finding the instructions document and I would like an easy place to find it whenever I am editing data.

Describe the solution you'd like
I would like the document to be linked from the CMS.

Create Resource model and controller

Fields:

  • id: primary key
  • category: foreign key to resource category model
  • state: one of 50 state codes
  • time: text
  • cost: text
  • award: text
  • likelihood: text
  • safety: text
  • story: text
  • challenges: text

Create ResourceCategory model and controller

Fields:

  • id: Primary key
  • name: char
  • short_description: char
  • description: text
  • icon: this was marked as a file in the data structures document, but it might be worth it to make this a url pointing to a file that we host somewhere else on the server or maybe in a CDN?
  • seo_title: char
  • seo_description: char
  • seo_keywords: array[char] (maybe? Not quite sure what this is.)
  • share_image: see icon

Redirect http -> https when on Heroku

We should redirect insecure requests to the https version when not running locally. RACK_ENV would suffice as a flag for when to do this I believe.

Ideally we could also add HSTS headers to the API without the subdomain flag and set to expire after one year.

Implement admin authentication for CMS

Requirements

For now, there will be no user accounts for the quiz itself, but we will have to have some way of authenticating admins in the CMS.

Possible Solutions

I can think of two potential ways to do this:

  1. Use an authentication gem to set up a User model and authentication scheme (for example, Knock) but only create one user in the database and give it an admin role.
  2. Store one set of login credentials in an environment variable, and roll our own lightweight JWT authentication implementation.

Notes

I'm leaning towards number one, which would be easily extensible if they wanted more than one admin user for the CMS.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.