Skip to content

RowanDW/snackr_backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snackr

Build Status

Table of contents

Overview

Snackr is a food tracking app that rates users' experience after meals. The app is built using a service oriented architecture. For a more detailed explanation of the user experience, please visit our frontend repo.

APIs

The following are a list of APIs used:

Edamam

Image-Charts

Google OAuth2

Endpoints

Get meals for a user by date

GET /users/:id/meals?date=<DATE IN DATETIME>

Example JSON response:

{
  "data": [
    {
      "id": "1",
        "type": "meal",
        "attributes": {
          "name": "Avocado toast",
          "rank": 8,
          "meal_time": "2012-03-05, 00:00:00"
        }
        "relationships": {
          "food_entries": {
            "data": [
              {
                "id": 1,
                "meal_id": 1,
                "food_id": 12345
                "food_name": "bread"
              },
              {
                "id": 2,
                "meal_id": 1,
                "food_id": 68762
                "food_name": "avocado"
              }
            ]
          }
        }
    },

    ....

  ]
}

Get graphs for user

GET /users/:id/graphs

Returns a list of graph uris.

Example JSON response:

{
  "data": [
    {
      "type": 'graph',
      "attributes": {
        "name": "10_Highest",
        "uri": "https://image-charts.com/chart?...."
      }
    },
    {
      "type": 'graph',
      "attributes": {
        "name": "10_Lowest",
        "uri": "https://image-charts.com/chart?...."
      }
    }
  ]
}

Get foods for user

GET /users/:id/foods

Returns an ordered, paginated list of foods for a user ranked top to bottom by user rating.

Optional parameters { method: method } under construction.

Example JSON response:

{
  "data": [
    {
      "id": "1",
      "type": "food_entry",
      "attributes": {
        "name": "Avocado",
        "average_rank": 8.5
      }
    },
    {
      "id": "8",
      "type": "food_entry",
      "attributes": {
        "name": "Chocolate",
        "average_rank": 8.3
      }
    }
  ]
}

Post a meal for a user

POST /users/:id/meals

Adds a new meal to meals table

Requires the following JSON format:

{
  "data": {
    "attributes": {
      "name": "Spaghetti",
      "meal_time": "2012-03-05, 00:00:00",
      "foods": [
        { 
          "food_name": "pasta",
          "food_id": 1234
        },
        {
          "food_name": "sauce",
          "food_id": 5678
        }
      ]
    }
  }
}

Example JSON Response:

{
  "data": {
    "id": "12",
    "type": "meal",
    "attributes": {
      "name": "Spaghetti",
      "meal_time": "2012-03-05, 00:00:00",
      "rank": -1
    },
    "relationships": {
      "food_entries": {
        "data": {
          "id": 1
          "meal_id": 12
          "food_id": 1234
          "food_name": "pasta"
        },
          "id": 1
          "meal_id": 12
          "food_id": 5678
          "food_name": "sauce"
        }
      }
    }
  }
}

Update a user's meal rank

PATCH /users/:id/meals

Requires the following JSON format:

{
  "rank": 7,
  "meal_id": 12
}

Response from BE:

{
  "data": {
    "id": "12",
    "type": "meal",
    "attributes": {
      "name": "Spaghetti",
      "meal_time": "2012-03-05, 00:00:00",
      "rank": 7
    }
  }
}

Search for a food

GET /foods/search?query=<QUERY>

Example JSON response:

{
  "data": [
    { 
      "id": "food_98u23mokdjfkbqkjsdfjk",
      "type": "food",
      "attributes": {
        "name": "Avocado"
      }
    },
    {
      "id": "food_lkjasdf908uw3rkjbasfkh",
      "type": "food",
      "attributes": {
        "name": "Avocado",
      }
    }
  ]
}

Login a user

GET /users

Requires the following JSON format:

{
  email: <EMAIL>
  name: <NAME>
  access_token: <TOKEN>
}

Example JSON response:

{
  "data": {
    "id": "1",
    "type": "user",
    "attributes": {
      "name": "Donald Duck"
    }
  }
}

Schema

Database schema

Technologies

Versions

  • Ruby 2.7.2
  • Rails 5.2.5

Development

Ruby on Rails Bootstrap Git Atom Faraday Figaro Postico Postman Rubocop

Languages

Ruby ActiveRecord

Deployment

Heroku Travis CI

Testing

RSpec Simplecov VCR Webmock Pry Capybara Launchy Shoulda Matchers

Development Principles

OOP TDD MVC REST

Contributors

LinkedIn

Github

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published