/love_fern_be

An app to help cultivate relationships with anyone in your life, backend service

Primary LanguageRuby

๐Ÿชด Love Fern [Back End] ๐Ÿชด

๐Ÿ‘‹ Welcome to Love Fern!

We believe that strong relationships are the foundation of a happy and fulfilling life. That's why we've created a tool that empowers you to build and maintain meaningful connections with the people you care about most. Try Love Fern today and see how it can transform your relationships!

๐Ÿ”— Links

โšก๏ธ Production Website

๐Ÿ”Œ Fernando (Our Backend Service)

๐Ÿชก Front End Repository

๐Ÿงต Back End Repository

Table of Contents

Description

Love Fern is an application that allows the user to cultivate their relationships with others in their lives, by taking care of a fern. This is the backend service of the application.

Getting Started

This is a Ruby on Rails application which establishes API endpoints to be called in the love_fern_fe repository. To run the application locally, both frontend and backend repositories will need to be cloned and set up fully with required gems and environment variables.

Installation

To install gems, run:

bundle install

Then to establish a database, run:

rails db:create

Because this is the back end repository, database migration is also necessary, run:

rails db:migrate

Inspect the /db/schema.rb and compare to the 'Schema' section below to ensure this migration has been done successfully.

RSpec Suite

Once love_fern_be is correctly installed, run tests locally to ensure the repository works as intended.

To test the entire spec suite, run:

bundle exec rspec spec/

All tests should be passing if installation is successful.

Calling APIs

  • APIs can be called locally using a program like Postman.

Available Endpoints

Note: Necessary parameters marked with {}

Create a New User

Note: pass name, google_id, & email in request body

POST '/api/v1/users'

Response:

{
  "data":
  {
    "id":"USER_ID",
    "type":"user",
    "attributes":
    {
      "name":"USER_NAME",
      "email":"USER_EMAIL",
      "google_id":"USER_GOOGLE_ID"
    }
  }
}

Return all ferns for user

GET '/api/v1/users/{google_id}/ferns'

Response:

{
  "data":
  [{
    "id":"FERN_ID",
    "type":"fern",
    "attributes":
    {
      "name":"FERN_NAME",
      "health":FERN_HEALTH,
      "preferred_contact_method":"FERN_CONTACT_METHOD"
    },
    "relationships":
    {
      "shelf":
      {
        "data":
        {
          "id":"SHELF_ID",
          "type":"shelf"
        }
      },
      "user":
      {
        "data":
        {
          "id":"USER_ID",
          "type":"user"
        }
      },
      "interactions":
      {
        "data":
        [...]
      }
    }
  },
  ...
  ]
}

Create a New Fern

Note: pass name, shelf, & preferred_contact_method in request body

POST '/api/v1/users/{google_id}/ferns'

Response:

{
  "data":
  {
    "id":"FERN_ID",
    "type":"fern",
    "attributes":
    {
      "name":"FERN_NAME",
      "health":7, **DEFAULT IS 7**
      "preferred_contact_method":"FERN_CONTACT_METHOD"
    },
    "relationships":
    {
      "shelf":
      {
        "data":
        {
          "id":"SHELF_ID",
          "type":"shelf"
        }
      },
    "user":
    {
      "data":
      {
        "id":"USER_ID",
        "type":"user"
      }
    },
    "interactions":{
      "data":
        []
      }
    }
  }
}

Return Single Fern (Fern Show)

GET '/api/v1/users/{google_id}/ferns/{fern_id}'

Response:

{
  "data":
  {
    "id":"9",
    "type":"fern",
    "attributes":
    {
      "name":"FERN_NAME",
      "health":FERN_HEALTH,
      "preferred_contact_method":"FERN_CONTACT_METHOD"
    },
    "relationships":
    {
      "shelf":
      {
        "data":
        {
          "id":"SHELF_ID",
          "type":"shelf"
        }
      },
      "user":
      {
        "data":
        {
          "id":"USER_ID",
          "type":"user"
        }
      },
      "interactions":
      {
        "data":
        [{
          "id":"INTERACTION_ID",
          "type":"interaction"
          }]
      }
    }
  },
  "included":
  [{
    "id":"INTERACTION_ID",
    "type":"interaction",
    "attributes":
    {
      "evaluation":"Positive",
      "description":"message",
      "created_at":"DATETIME"
    },
    "relationships":
    {
      "fern":
      {
        "data":
        {
          "id":"FERN_ID",
          "type":"fern"
        }
      }
    }
    },
    {
      "id":"USER_ID",
      "type":"user",
      "attributes":
      {
        "name":"USER_NAME",
        "email":"USER_EMAIL",
        "google_id":"USER_GOOGLE_ID"
      }
    }]
}

Update Fern Status (Water Fern)

Note: pass interaction as the message to be analyzed in response body

PATCH '/api/v1/users/{google_id}/ferns/{fern_id}'

Response:

{
  "data":
  {
    "id":"FERN_ID",
    "type":"fern",
    "attributes":
    {
      "name":"FERN_NAME",
      "health":FERN_HEALTH,
      "preferred_contact_method":"FERN_CONTACT_METHOD"
    },
    "relationships":
    {
      "shelf":
      {
        "data":
        {
          "id":"SHELF_ID",
          "type":"shelf"
        }
      },
      "user":
      {
        "data":
        {
          "id":"USER_ID",
          "type":"user"
        }
      },
      "interactions":
      {
        "data":
        [{
          "id":"INTERACTION_ID",
          "type":"interaction"
        },
        ...
        ]
      }
    }
  }
}

Update Fern Information [Name / Shelf / Contact Method]

Note: pass name, shelf, or preferred_contact_method in request body

PATCH '/api/v1/users/{google_id}/ferns/{fern_id}'

Delete Fern

DELETE '/api/v1/users/{google_id}/ferns/{fern_id}'

Response:

{
  "data":
  {
    "id":"FERN_ID",
    "type":"fern",
    "attributes":
    {
      "name":"FERN_NAME",
      "health":FERN_HEALTH,
      "preferred_contact_method":"FERN_CONTACT_METHOD"
    },
    "relationships":
    {
      "shelf":
      {
        "data":
        {
          "id":"SHELF_ID",
          "type":"shelf"
        }
      },
      "user":
      {
        "data":
        {
          "id":"USER_ID",
          "type":"user"
        }
      },
      "interactions":
      {
        "data":[]
      }
    }
  }
}

Get All Shelves & Ferns

GET '/api/v1/users/{google_id}/shelves'

Response:

{
  "data":
  [{
    "id":"SHELF_ID",
    "type":"shelf",
    "attributes":
    {
      "name":"SHELF_NAME"
    },
    "relationships":
    {
      "user":
      {
        "data":
        {
          "id":"USER_ID",
          "type":"user"
        }
      },
      "ferns":
      {
        "data":
        [{
          "id":"FERN_ID",
          "type":"fern"
        },
        ...
        ]}
      }
    },
    ...]
}

Get One Random Activity Suggestion

GET '/api/v1/activities'

Response:

{
  "activity":"RANDOM_ACTIVITY"
}

Goals

Love Fern was germinated to satisfy the requirements (and beyond) for a Turing Backend Mod 3 group project, Consultancy. See official project requirements.

Learning Goals

  • Design easily consumable API end-points to create accessible, robust backend service.
  • Implement a secure connection between front and backend services deployed to Heroku.
  • Interact with two unique external APIs with efficient data processing and caching.

Future Goals

  • Implement "Soil Moisture" which indicates how often a user wishes to interact with their fern before the soil is completely dry. Dry soil will reduce the plant health until it is watered again.
  • Add the ability to search for a fern by name and order ferns by health.
  • Suggest multiple activities and gestures corresponding to varying levels of care needed for the fern.
  • Implement a homegrown sentiment analysis feature to pair with Google's services, eventually reducing dependence on external services.

Known Issues

  • In current state, sentiment analysis has linear affect on fern status.
  • No automated system for generating secret keys to authenticate new FE services.

Database & Schema

screenshot_2023-03-02_at_9 28 56_am_480

Authors & Acknowledgments

๐Ÿ‘ค Samuel Cox

๐Ÿ‘ค Drew Layton

๐Ÿ‘ค Anthony Ongaro

๐Ÿ‘ค Brady Rohrig

๐Ÿ‘ค J Seymour

๐Ÿ‘ค Anthony Blackwell Tallent