GithubHelp home page GithubHelp logo

abdullaqudrat / truck-trackr-be Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kathleenscriver/truck-trackr-be

0.0 1.0 0.0 269 KB

API built in rails for TruckTrakr app

Ruby 98.97% HTML 1.03%

truck-trackr-be's Introduction

Truck Trackr API

CircleCI Maintainability

Table of Contents

Purpose

Core Members

Technologies Used

Testing

Cloning this Repo

Purpose

This project provide the back-end support for the Truck Trackr app. This app is aimed at making it easier for Breweries and Food Trucks to coordinate their schedules. When a Brewery posts a new brewery_event, a Food Truck can then contact that Brewery to fill that need. A Food Truck can also create an open_date where they are available to provide their services for the day.

The back-end is an API that our detached front-end interacts with to access the database of Breweries and Food Trucks.

Visit deployed api at https://truck-trackr-api.herokuapp.com/ (This is the base URL for all api endpoints.)

Visit the front-end repo at https://github.com/Haub/truck-trackr-fe

Core Members

Technologies Used

  • Rails 5.2.2
  • Ruby 2.4.1
  • PostgreSQL Database
  • Fast_JsonAPI (for Serializers)
  • CircleCI (for Continuous Integration)
  • Heroku (for deployment)
  • Sidekiq & Redis (visit our Sidekiq Dashboard at https://truck-trackr-api.herokuapp.com/sidekiq)
  • SendGrid (for sending emails)
  • CarrierWave (for image/file upload)

Testing

This API was driven by TDD and uses SimpleCov to measure test coverage. (90% as of 1/3/19)

  • Other testing tools used:
  • RSpec
  • Shoulda-Matchers
  • Factory_bot_rails
  • Mailcatcher

Cloning this repo

git clone https://github.com/KathleenYruegas/truck-trackr-be.git
bundle
rake db:{create,migrate}
  • Additionally, you can run rake db:seed to get test data into your local testing environment.

API Endpoints

Logging In Endpoints

POST /login

  • This endpoint will login a Food Truck or Brewery account.

    Request Format

{
  "account_type": "food_truck",
  "uid": "8ngng833ng393g8n"
}
  • Account Type attribute can be either food_truck or brewery.
  • Both attributes are required in the body of the request.

Response

  • Successful response will return status code: 201
  • Unsuccessful response will return status code: 404

/api/v1/food_trucks Endpoints

GET /api/v1/food_trucks

  • This endpoint will return a list of all food-trucks in the database along with their name.
[
  {
    "data": [
      {
        "id": "1",
        "type": "food_truck",
        "attributes": {
          "name": "Hot Pasta"
        }
      },
      {
        "id": "2",
        "type": "food_truck",
        "attributes": {
            "name": "Hell On Wheels",
        }
      }
    ]
  }
]

GET /api/v1/food_trucks/:id

  • This endpoint will return a selected food truck in the database along with it's attributes when an id is given
{
  "data": [
    {
      "id": "1",
      "type": "food_truck",
      "attributes": {
        "name": "Hot Pasta",
        "food_type": "Risotto with Seafood",
        "contact_name": "Pamala",
        "phone": "344.694.9247",
        "email": "[email protected]",
        "website": "http://hopo.com",
        "logo_image": "https://pigment.github.io/fake-logos/logos/medium/color/11.png"
      }
    }
  ]
}

POST /api/v1/food_trucks

  • This endpoint will add a new food truck to the database.

Expected Request Format:

{
  "name": "name_of_food_truck", (required)
  "food_type": "mexican fusion",  (required)
  "contact_name": "for booking events",  (required)
  "phone": "who can they call?",  (required)
  "email": "who can they email?",  (required)
  "logo_image": "WIP, ok to leave blank",
  "website": "ok to leave this blank if not available",
  "uid": "12345" (required)
}
  • A successful request will return status code: 201.
  • An unsuccessful request will return status code: 404 and
{
  "message": "Failed"
}

PUT /api/v1/food_trucks/:id

  • This endpoint will allow you to edit the food_truck.

Expected Request Format:

{
 "name": "name_of_food_truck", (required)
  "food_type": "mexican fusion",  (required)
  "contact_name": "for booking events",  (required)
  "phone": "who can they call?",  (required)
  "email": "who can they email?",  (required)
  "logo_image": "WIP, ok to leave blank",
  "website": "ok to leave this blank if not available",
  "uid": "food_truck_uid" (required)
}
  • A successful request will return status code: 200.
  • An unsuccessful request will return status code: 404 with
{
  "message": "Food Truck not found with ID #{params[:id]}"
}

DELETE /api/v1/food_trucks/:id

  • This endpoint will delete the specified food_truck.

Request Format

{
  "uid": "food_truck_uid" (required)
}
  • If successful, will return status code: 204.
  • If unsuccessful, will return status code: 404 with
{
  "message": "Food Truck not found with ID #{params[:id]}"
}

/api/v1/breweries Endpoints

GET /api/v1/breweries

  • Will return a list of all breweries in the database along with their name.
{
    "data": [
              {
                "id": "1",
                "type": "brewery",
                "attributes": {
                    "name": "Lockman Inc"
                }
              },
              {
                "id": "2",
                "type": "brewery",
                "attributes": {
                    "name": "Cremin, Nikolaus and Volkman"
                }
              }
            ]
}

GET /api/v1/breweries/:id

  • This endpoint will return a selected brewery in the database along with it's attributes when an id is given
{
  "data": [
    {
      "id": "1",
      "type": "brewery",
      "attributes": {
        "name": "Heads Of State",
        "address": "123 Main St, Denver, CO 80203",
        "contact_name": "Pamala",
        "phone": "344.694.9247",
        "email": "[email protected]",
        "website": "http://hosbeer.com",
        "logo_image": "https://pigment.github.io/fake-logos/logos/medium/color/11.png"
      }
    }
  ]
}

POST /api/v1/breweries

  • This endpoint will create a new brewery to add to the database.

Expected Request Format:

{
  "name": "Heads Of State",  (required)
  "address": "123 Main St, Denver, CO 80203",  (required)
  "contact_name": "Pamala",  (required)
  "phone": "344.694.9247",  (required)
  "email": "[email protected]",  (required)
  "website": "http://hosbeer.com",
  "logo_image": "https://pigment.github.io/fake-logos/logos/medium/color/11.png",
  "uid": "12345" (required)
 }
  • A successful requet will return status code: 201.
  • An unsuccessful request will return status code: 404 with
{
  "message": "Failed"
}

PUT /api/v1/breweries/:id

  • This endpoint will allow you to edit an existing brewery.

Expected Request Format:

{
  "name": "Heads Of State",  (required)
  "address": "123 Main St, Denver, CO 80203",  (required)
  "contact_name": "Pamala",  (required)
  "phone": "344.694.9247",  (required)
  "email": "[email protected]",  (required)
  "website": "http://hosbeer.com",
  "logo_image": "https://pigment.github.io/fake-logos/logos/medium/color/11.png",
  "uid": "brewery_uid" (required)
}
  • A successful requet will return status code: 200.
  • An unsuccessful request will return status code: 404 with
{
  "message": "Brewery not found with ID #{params[:id]}"
}

DELETE /api/v1/breweries/:id

  • This endpoint will delete the specified brewery from the database.

Expected Request Format

{
  "uid": "brewery_uid" (required)
}

- A successful request will return `status code: 204`.
- An unsuccessful request will return `status code: 404` with
```json
{
  "message": "Brewery not found with ID #{params[:id]}"
}

/api/v1/food_trucks/:food_truck_id/open_dates Endpoints

GET /api/v1/food_trucks/:food_truck_id/open_dates

Lists all listed open_dates for a given food truck.

Example Response

{
   "data": {
        "id": "22",
        "type": "food_truck",
        "attributes": {
            "name": "Skeeter",
            "food_type": "Katsu Curry",
            "contact_name": "Rosalia",
            "phone": "1-267-595-6285",
            "email": "[email protected]",
            "website": null,
            "logo_image": "https://pigment.github.io/fake-logos/logos/medium/color/10.png"
        },
        "relationships": {
            ...
        }
    },
    "included": [
        {
            "id": "1",
            "type": "open_date",
            "attributes": {
                "id": 1,
                "date": "2019-02-24",
                "booked?": true
            }
        },
        {
            "id": "3",
            "type": "open_date",
            "attributes": {
                "id": 3,
                "date": "2019-04-07",
                "booked?": false
            }
        }
      ]
}

Error Response

If the truck cannot be located, the response will include status: 400 with "message": "Sorry, that food truck does not exist, please try again."

GET /api/v1/food_trucks/:food_truck_id/open_dates/:id

  • This endpoint will return the specified Open Date for the food truck.

Example Response

{
    "data": {
        "id": "2",
        "type": "open_date",
        "attributes": {
            "id": 2,
            "date": "2019-01-01",
            "booked?": false
        }
    }
}

Error Response

  • If either the food truck or the Open Date do not exist, the response will include status code: 404 with
{
  "message": "Could not locate resource"
}

POST /api/v1/food_trucks/:food_truck_id/open_dates

-This will create a new open_date object for the truck specified in the path.

Request Format:

{
  "date": "Tue, 16 Apr 2019",
  "uid": "food_truck_uid" (required)
}

*Note: The date format does not need the day of the week. Can also be in YY-MM-DD format or YYYY-MM-DD.

The attribute of booked? will default to false. If you want to create the open_date with booked? set to true, you can send it as an additional parameter in the request.

{
  "date": "Tue, 16 Apr 2019",
  "booked?": true,
  "uid": "food_truck_uid" (required)
}

Example Response

  • If successful, response will return status code: 201.

  • If not successful, response will return status code: 404 with

{
  "message": "Could not save, please try again."
}

PUT /api/v1/food_trucks/:food_truck_id/open_dates/:id

  • This endpoint will allow the user to edit the specified open date.

Request Format:

{
 "date": "Tue, 16 Apr 2019",
 "booked?": true,
 "uid": "food_truck_uid" (required)
}

*Note: The date format does not need the day of the week. Can also be in YY-MM-DD format or YYYY-MM-DD.

(Request can include one or both of the above listed attributes.)

Example Response

  • If successful, response will return status code: 200.

  • If not successful, response will return status code: 404 with

{
  "message": "Could not update, please try again."
}

DELETE /api/v1/food_trucks/:food_truck_id/open_dates/:id

  • This endpoint will delete the specified open date for a specified food truck from the database.

Expected Request Format

{
  "uid": "food_truck_uid" (required)
}
  • A successful request will return status code: 204.
  • An unsuccessful request will return status code: 404 with
{
  "message": "Could not delete Open Date. Please try again."
}

/api/v1/breweries/:brewery_id/brewery_events Endpoints

GET /api/v1/breweries/:brewery_id/brewery_events

Lists all listed brewery events for a given brewery.

Example Response

{
   "data": {
        "id": "1",
        "type": "brewery",
        "attributes": {
          "name": "Heads Of State",
          "address": "Risotto with Seafood",
          "contact_name": "Pamala",
          "phone": "344.694.9247",
          "email": "[email protected]",
          "website": "http://hosbeer.com",
          "logo_image": "https://pigment.github.io/fake-logos/logos/medium/color/11.png"
        },
        "relationships": {
            ...
        }
    },
    "included": [
        {
            "id": "1",
            "type": "brewery_event",
            "attributes": {
                "id": 1,
                "date": "2019-02-24",
                "truck_booked?": true
            }
        },
        {
            "id": "3",
            "type": "brewery_event",
            "attributes": {
                "id": 3,
                "date": "2019-04-07",
                "truck_booked?": false
            }
        }
      ]
}

Error Response

If the brewery cannot be located, the response will include status: 400 with "message": "Sorry, that brewery does not exist, please try again."

GET /api/v1/breweries/:brewery_id/brewery_events/:id

  • This endpoint will return the specified brewery event for the brewery.

Example Response

{
    "data": {
        "id": "2",
        "type": "brewery_event",
        "attributes": {
            "id": 2,
            "date": "2019-01-01",
            "truck_booked?": false
        }
    }
}

Error Response

  • If either the brewery or the brewery event do not exist, the response will include status code: 404 with
{
  "message": "Could not locate resource"
}

POST /api/v1/breweries/:brewery_id/brewery_events

-This will create a new brewery event object for the brewery specified in the path.

Request Format:

{
  "date": "Tue, 16 Apr 2019",
  "uid": "brewery_uid" (required)
}

*Note: The date format does not need the day of the week. Can also be in YY-MM-DD format or YYYY-MM-DD.

The attribute of truck_booked? will default to false. If you want to create the open_date with truck_booked? set to true, you can send it as an additional parameter in the request.

{
  "date": "Tue, 16 Apr 2019",
  "truck_booked?": true
}

Example Response

  • If successful, response will return status code: 201.

  • If not successful, response will return status code: 404 with

{
  "message": "Could not save, please try again."
}

PUT /api/v1/breweries/:brewery_id/brewery_events/:id

  • This endpoint will allow the user to edit the specified brewery event of a specified brewery.

Request Format:

{
 "date": "Tue, 16 Apr 2019",
 "truck_booked?": true,
 "uid": "brewery_uid" (required)
}

*Note: The date format does not need the day of the week. Can also be in YY-MM-DD format or YYYY-MM-DD.

(Request can include one or both of the above listed attributes.)

Example Response

  • If successful, response will return status code: 200.
  • If not successful, response will return If the brewery cannot be located, the response will include status: 404 with "message": "Brewery not found with ID --"
  • If the event cannot be located, the response will include status: 404 with "message": "Event ID -- not found with associated brewery ID --"

DELETE /api/v1/breweries/:brewery_id/brewery_events/:id

  • This endpoint will delete the specified brewery event for a specified brewery from the database.

Expected Request Format

{
  "uid": "brewery_uid" (required)
}
  • If successful, response will return status code: 200.
  • If not successful, response will return If the brewery cannot be located, the response will include status: 404 with "message": "Brewery not found with ID --"
  • If the event cannot be located, the response will include status: 404 with "message": "Event ID -- not found with associated brewery ID --"

truck-trackr-be's People

Contributors

abdullaqudrat avatar kathleenscriver avatar

Watchers

James Cloos avatar

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.