Skip to content

Bik-n-Bru/BE-Bik-n-Bru

Repository files navigation

Bīk-n-Brü API

Deschutes Brewery GIF

This repo is the Back End portion of the Bīk-n-Brü project built by Mod 3 students at Turing School of Software and Design.

The purpose of this app is to encourage people to ride their bikes to bars to decrease their carbon footprint by gamifying the exercise/bar experience!

Visit our Bīk-n-Brü Site! Or check out the Front End Github Repo.

Table of Contents

Database Schema

db schema

Tech and Tools

  • Ruby 2.7.4
  • Rails 5.2.8.1
  • RSpec 3.12.0
  • PostgreSQL
  • Heroku
  • Circle Ci

Developer Setup

If you would like to demo this API on your local machine:

  1. Ensure you have Ruby 2.7.4 and Rails 5.2.8 installed
  2. Fork and clone down this repo and navigate to the root folder cd BE-Bik-n-Bru
  3. Run bundle install
  4. Run rails db:{drop,create,migrate,seed}
  5. (Optional) To run the test suite, run bundle exec rspec spec
  6. Run rails s
You should now be able to hit the API endpoints using Postman or a similar tool.
Default host is http://localhost:3000

Endpoints

Get User by Bīk-n-Brü id
  • GET "/api/v1/users/:id"
  • Sample response body:
      {
        "data": {
            "id": "2",
            "type": "user",
            "attributes": {
                "username": "testcase",
                "token": "12345abcde",
                "athlete_id": "12345",
                "city": "Not a city",
                "state": "Not a state"
              }
          }
      }
    
Get User by Strava Athlete id
  • GET "/api/v1/users/:athlete_id?q=athlete_id"
  • Sample response body:
      {
        "data": {
            "id": "2",
            "type": "user",
            "attributes": {
                "username": "testcase",
                "token": "12345abcde",
                "athlete_id": "12345",
                "city": "Not a city",
                "state": "Not a state"
              }
          }
      }
    
Get Leaderboard Information
  • GET "/api/v1/leaderboard"
  • Sample response body:
      {
        "data": [
          {
              "id": "",
              "type": "leader",
              "attributes": {
                  "username": "Muzgash",
                  "miles": 3039.5499999999997,
                  "beers": 363,
                  "co2_saved": 2735.6200000000003
              }
          },
          {
              "id": "",
              "type": "leader",
              "attributes": {
                  "username": "Eofor",
                  "miles": 3027.1300000000006,
                  "beers": 365,
                  "co2_saved": 2724.4199999999996
              }
          },
          {
              "id": "",
              "type": "leader",
              "attributes": {
                  "username": "Gléowine",
                  "miles": 3021.000000000001,
                  "beers": 360,
                  "co2_saved": 2718.93
              }
          },
          {...},
          {...},
        ...
        ]
      }
    
Update a User's Information
  • PATCH "/api/v1/users/:user_id"
  • Sample request body:
       {
          "user": {
              "data": {
                          "city":"Eugene", 
                          "state":"Oregon"
                      }
          }
      }
    
  • Sample response body:
      {
        :data=>{
            :id=>"5",
            :type=>"user",
            :attributes=>{
                :username=>"testcase",
                :token=>"12345abcde",
                :athlete_id=>"12345",
                :city=>"Eugene",
                :state=>"Oregon"
                }, 
                  :relationships=>
                    {:activities=>{
                      :data=>[]
                  }
              }
          }
      }
    
Create A New User
  • POST "/api/v1/users"
  • Sample request body:
       {
          "user": {
              "data": {
                          "athlete_id":"12345678910112", 
                          "username":"testcase5", 
                          "token":"12345abcde"
                      }
          }
      }
    
  • Sample response body:
      {
        :data=>{
            :id=>"5",
            :type=>"user",
            :attributes=>{
                :username=>"testcase5",
                :token=>"12345abcde",
                "athlete_id":"12345678910112",
                :city=>"Eugene",
                :state=>"Oregon"
                }, 
                  :relationships=>
                    {:activities=>{
                      :data=>[]
                  }
              }
          }
      }
    
Get Breweries in a User's Local Area
  • GET "/api/v1/breweries/:user_id"
  • Sample response body:
      {
        "data": [
            {
                "id": "10-barrel-brewing-co-denver-denver",
                "type": "brewery",
                "attributes": {
                    "name": "10 Barrel Brewing Co - Denver",
                    "street_address": "2620 Walnut St",
                    "city": "Denver",
                    "state": "Colorado",
                    "zipcode": "80205-2231",
                    "phone": "7205738992",
                    "website_url": null
                }
            },
            {
                "id": "14er-brewing-company-denver",
                "type": "brewery",
                "attributes": {
                    "name": "14er Brewing Company",
                    "street_address": "2801 Walnut St",
                    "city": "Denver",
                    "state": "Colorado",
                    "zipcode": "80205-2235",
                    "phone": "7207731437",
                    "website_url": "http://www.14erBrewing.com"
                }
            },
            {
                "id": "aero-craft-brewing-denver",
                "type": "brewery",
                "attributes": {
                    "name": "Aero Craft Brewing",
                    "street_address": null,
                    "city": "Denver",
                    "state": "Colorado",
                    "zipcode": "80212-2199",
                    "phone": "3039185446",
                    "website_url": "http://www.aerocraft.beer"
                }
            },
            {...},
            {...},
          ...
        ]
      }
    
Get Index of User Activities
  • GET "/api/v1/users/:user_id/activities"
  • Sample response body:
      {
        "data": [
            {
                "id": "701",
                "type": "activity",
                "attributes": {
                    "brewery_name": "Mirella Jenkins",
                    "distance": 92.64,
                    "calories": 2779,
                    "num_drinks": 11,
                    "drink_type": "Racer 5 India Pale Ale, Bear Republic Bre",
                    "dollars_saved": 14.74,
                    "lbs_carbon_saved": 83.38,
                    "created_at": "2023-01-10T13:18:37.335Z",
                    "user_id": 15
                },
                "relationships": {
                    "user": {
                        "data": {
                            "id": "15",
                            "type": "user"
                        }
                    }
                }
            },
            {
                "id": "702",
                "type": "activity",
                "attributes": {
                    "brewery_name": "Henry Adams",
                    "distance": 65.33,
                    "calories": 1959,
                    "num_drinks": 8,
                    "drink_type": "Stone IPA",
                    "dollars_saved": 10.39,
                    "lbs_carbon_saved": 58.8,
                    "created_at": "2023-01-10T13:18:37.354Z",
                    "user_id": 15
                },
                "relationships": {
                    "user": {
                        "data": {
                            "id": "15",
                            "type": "user"
                        }
                    }
                }
            },
            {...},
            {...},
          ...
        ]
      }
    
Get Activity by Bīk-n-Brü Activity id
  • GET "/api/v1/acitivities/:activity_id"
  • Sample response body:
      {
          "data": {
              "id": "701",
              "type": "activity",
              "attributes": {
                  "brewery_name": "Mirella Jenkins",
                  "distance": 92.64,
                  "calories": 2779,
                  "num_drinks": 11,
                  "drink_type": "Racer 5 India Pale Ale, Bear Republic Bre",
                  "dollars_saved": 14.74,
                  "lbs_carbon_saved": 83.38,
                  "created_at": "2023-01-10T13:18:37.335Z",
                  "user_id": 15
              },
              "relationships": {
                  "user": {
                      "data": {
                          "id": "15",
                          "type": "user"
                      }
                  }
              }
          }
      }
    
Create A New Activity
  • POST "/api/v1/activities"
  • Sample request body:
      {
          "activity": {
              "data": {
                          "brewery_name": "Name",
                          "drink_type": "IPA",
                          "user_id": "15"
                      }
          }
      }
    
  • Sample response body:
      {
          "data": {
              "id": "701",
              "type": "activity",
              "attributes": {
                  "brewery_name": "Name",
                  "distance": 92.64,
                  "calories": 2779,
                  "num_drinks": 11,
                  "drink_type": "IPA",
                  "dollars_saved": 14.74,
                  "lbs_carbon_saved": 83.38,
                  "created_at": "2023-01-10T13:18:37.335Z",
                  "user_id": 15
              },
              "relationships": {
                  "user": {
                      "data": {
                          "id": "15",
                          "type": "user"
                      }
                  }
              }
          }
      }
    
Get Index of User Badges
  • GET "/api/v1/users/:user_id/badges"
  • Sample response body:
      {
        "data": [
            {
                "id": "141",
                "type": "badge",
                "attributes": {
                    "title": "Completed 1 Activity"
                },
                "relationships": {
                    "user": {
                        "data": {
                            "id": "15",
                            "type": "user"
                        }
                    }
                }
            },
            {
                "id": "142",
                "type": "badge",
                "attributes": {
                    "title": "Cycled 100 miles"
                },
                "relationships": {
                    "user": {
                        "data": {
                            "id": "15",
                            "type": "user"
                        }
                    }
                }
            },
            {
                "id": "143",
                "type": "badge",
                "attributes": {
                    "title": "Cycled 500 miles"
                },
                "relationships": {
                    "user": {
                        "data": {
                            "id": "15",
                            "type": "user"
                        }
                    }
                }
            },
            {...},
            {...},
          ...
        ]
      }
    
Get Current Gas Price For User
  • GET "/api/v1/gas_price/:user_id"
  • Sample response body:
      {
          "data": {
              "state": "Colorado",
              "gas_price": 3.129
          }
      }
    

Contributors

Project Team:

Amanda Ross
Yuji Kosakowski
Rich Kaht
Gabe Nuñez
Annie Pulzone

Project Manager:

Mike Dao

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published