Giter Club home page Giter Club logo

rails_engine's People

Contributors

megroth2 avatar s2an avatar

Watchers

 avatar

Forkers

s2an

rails_engine's Issues

Section 2: find all items based on search criteria

This endpoints will follow the same rules as the “find” endpoint.

The JSON response will always be an array of items, even if zero matches or only one match is found.

It should not return a 404 if no matches are found.

Example JSON response for GET /api/v1/merchants/find_all?name=ring:

{
  "data": [
    {
      "id": "4",
      "type": "merchant",
      "attributes": {
        "name": "Ring World"
      }
    },
    {
      "id": "1",
      "type": "merchant",
      "attributes": {
        "name": "Turing School"
      }
    }
  ]
}

Section 1: create an item

This endpoint should:

  • create a record and render a JSON representation of the new Item record.
  • follow this pattern: POST /api/v1/items
  • accept the following JSON body with only the following fields:
    {
      "name": "value1",
      "description": "value2",
      "unit_price": 100.99,
      "merchant_id": 14
    }
    (Note that the unit price is to be sent as a numeric value, not a string.)
  • return an error if any attribute is missing
  • should ignore any attributes sent by the user which are not allowed

Example JSON response for the Item resource:

{
  "data": {
    "id": "16",
    "type": "item",
    "attributes": {
      "name": "Widget",
      "description": "High quality widget",
      "unit_price": 100.99,
      "merchant_id": 14
    }
  }
}

Section 1: get an Item's Merchant

get the merchant data for a given item ID

The relationship endpoint you should expose is: GET /api/v1/items/:id/merchant

  • return the merchant associated with an item
  • return a 404 if the item is not found

Section 1: get one merchant

This endpoint should:

  • render a JSON representation of the corresponding record, if found
  • follow this pattern: GET /api/v1/<resource>/:id

Example JSON response for the Item resource:

{
  "data": {
    "id": "1",
    "type": "item",
    "attributes": {
      "name": "Super Widget",
      "description": "A most excellent widget of the finest crafting",
      "unit_price": 109.99
    }
  }
}

Note that the unit_price is sent as numeric data, and not string data.

Section 1: get one item

This endpoint should:

  • render a JSON representation of the corresponding record, if found
  • follow this pattern: GET /api/v1/<resource>/:id

Example JSON response for the Item resource:

{
  "data": {
    "id": "1",
    "type": "item",
    "attributes": {
      "name": "Super Widget",
      "description": "A most excellent widget of the finest crafting",
      "unit_price": 109.99
    }
  }
}

Note that the unit_price is sent as numeric data, and not string data.

Section 1: get all merchants

This “index” endpoint should:

  • render a JSON representation of all records of the requested resource
  • always return an array of data, even if one or zero resources are found
  • NOT include dependent data of the resource (e.g., if you’re fetching merchants, do not send any data about merchant’s items or invoices)
  • follow this pattern: GET /api/v1/<resource>

Example JSON response for the Merchant resource:

{
  "data": [
    {
      "id": "1",
        "type": "merchant",
        "attributes": {
          "name": "Mike's Awesome Store",
        }
    },
    {
      "id": "2",
      "type": "merchant",
      "attributes": {
        "name": "Store of Fate",
      }
    },
    {
      "id": "3",
      "type": "merchant",
      "attributes": {
        "name": "This is the limit of my creativity",
      }
    }
  ]
}

Section 1: get a Merchant's Items

get all items for a given merchant ID

The relationship endpoint you should expose is: GET /api/v1/merchants/:id/items

  • return all items associated with a merchant.
  • return a 404 if merchant is not found

Section 1: edit an item

This endpoint should:

  • update the corresponding Item (if found) with whichever details are provided by the user
  • render a JSON representation of the updated record.
  • follow this pattern: PATCH /api/v1/items/:id
  • accept the following JSON body with one or more of the following fields: The body should follow this pattern:
    {
      "name": "value1",
      "description": "value2",
      "unit_price": 100.99,
      "merchant_id": 7
    }
    (Note that the unit price is to be sent as a numeric value, not a string.)

Example JSON response for the Item resource:

{
  "data": {
    "id": "1",
    "type": "item",
    "attributes": {
      "name": "New Widget Name",
      "description": "High quality widget, now with more widgety-ness",
      "unit_price": 299.99,
      "merchant_id": 7
    }
  }
}

Section 1: delete an item

This endpoint should:

  • destroy the corresponding record (if found) and any associated data
  • destroy any invoice if this was the only item on an invoice
  • NOT return any JSON body at all, and should return a 204 HTTP status code
  • NOT utilize a Serializer (Rails will handle sending a 204 on its own if you just .destroy the object)

Section 2: find one merchant based on search criteria

This endpoint should:

  • return a single merchant, if found
  • return the first merchant in the database in case-insensitive alphabetical order if multiple matches are found
    • e.g., if “Ring World” and “Turing” exist as merchant names, “Ring World” would be returned, even if “Turing” was created first
  • allow the user to specify a ‘name’ query parameter:
    • for merchants, the user can send ?name=ring and it will search the name field in the database table
    • the search data in the name query parameter should require the database to do a case-insensitive search for text fields
      • e.g., searching for ‘ring’ should find ‘Turing’ and ‘Ring World’

Valid examples:

  • GET /api/v1/merchants/find?name=Mart
  • GET /api/v1/items/find?name=ring
  • GET /api/v1/items/find?min_price=50
  • GET /api/v1/items/find?max_price=150
  • GET /api/v1/items/find?max_price=150&min_price=50

Invalid examples:

  • GET /api/v1/<resource>/find - parameter cannot be missing
  • GET /api/v1/<resource>/find?name= - parameter cannot be empty
  • GET /api/v1/items/find?name=ring&min_price=50 - cannot send both name and min_price
  • GET /api/v1/items/find?name=ring&max_price=50 - cannot send both name and max_price
  • GET /api/v1/items/find?name=ring&min_price=50&max_price=250 - cannot send both name and min_price and max_price

Example JSON response for GET /api/v1/merchants/find?name=ring:

{
  "data": {
    "id": 4,
    "type": "merchant",
    "attributes": {
      "name": "Ring World"
    }
  }
}

Section 1: get all items

This "index” endpoint should:

  • render a JSON representation of all records of the requested resource
  • always return an array of data, even if one or zero resources are found
  • NOT include dependent data of the resource (e.g., if you’re fetching merchants, do not send any data about merchant’s items or invoices)
  • follow this pattern: GET /api/v1/<resource>

Example JSON response for the Merchant resource:

{
  "data": [
    {
      "id": "1",
        "type": "merchant",
        "attributes": {
          "name": "Mike's Awesome Store",
        }
    },
    {
      "id": "2",
      "type": "merchant",
      "attributes": {
        "name": "Store of Fate",
      }
    },
    {
      "id": "3",
      "type": "merchant",
      "attributes": {
        "name": "This is the limit of my creativity",
      }
    }
  ]
}

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.