BestBuy / api-playground

The Best Buy API Playground is an API training tool for students, educators and other learners to explore the possibilities of a fully functional RESTful API in a simple, non-production environment.
Other
260 stars 104 forks source link

Add ability to associate products with categories #10

Open roelvan opened 7 years ago

roelvan commented 7 years ago

How would the api call look like?

BrandesEric commented 7 years ago

Hi @roelvan,

No need for a separate call to get categories for a product or services for specific stores. By default, any product or store call will return the associated categories or services.

For example, if you make the following product call: http://localhost:3030/products?id=43900

You'll see as part of the JSON response a categories property that contains a list of all categories that product is associated with

{
  "total": 1,
  "limit": 10,
  "skip": 0,
  "data": [
    {
      "id": 43900,
      "name": "Duracell - AAA Batteries (4-Pack)",
      "type": "HardGood",
      "price": 5.49,
      "upc": "041333424019",
      "shipping": 0,
      "description": "Compatible with select electronic devices; AAA size; DURALOCK Power Preserve technology; 4-pack",
      "manufacturer": "Duracell",
      "model": "MN2400B4Z",
      "url": "http://www.bestbuy.com/site/duracell-aaa-batteries-4-pack/43900.p?id=1051384074145&skuId=43900&cmp=RMXCC",
      "image": "http://img.bbystatic.com/BestBuy_US/images/products/4390/43900_sa.jpg",
      "createdAt": "2016-11-17T17:58:03.298Z",
      "updatedAt": "2016-11-17T17:58:03.298Z",
      "categories": [
        {
          "id": "abcat0208002",
          "name": "Alkaline Batteries",
          "createdAt": "2016-11-17T17:57:04.285Z",
          "updatedAt": "2016-11-17T17:57:04.285Z"
        },
        {
          "id": "pcmcat248700050021",
          "name": "Housewares",
          "createdAt": "2016-11-17T17:57:05.399Z",
          "updatedAt": "2016-11-17T17:57:05.399Z"
        },
        {
          "id": "pcmcat303600050001",
          "name": "Household Batteries",
          "createdAt": "2016-11-17T17:57:04.285Z",
          "updatedAt": "2016-11-17T17:57:04.285Z"
        },
        {
          "id": "pcmcat312300050015",
          "name": "Connected Home & Housewares",
          "createdAt": "2016-11-17T17:57:04.285Z",
          "updatedAt": "2016-11-17T17:57:04.285Z"
        }
      ]
    }
  ]
}

The same applies for store queries. Any query will return the services associated with that store under the services property.

For example, if you go to http://localhost:3030/stores

You'll get a response that contains a list of stores, and for each store the list of services at that store:


  "total": 1561,
  "limit": 10,
  "skip": 0,
  "data": [
    {
      "id": 4,
      "name": "Minnetonka",
      "type": "BigBox",
      "address": "13513 Ridgedale Dr",
      "address2": "",
      "city": "Hopkins",
      "state": "MN",
      "zip": "55305",
      "lat": 44.969658,
      "lng": -93.449539,
      "hours": "Mon: 10-9; Tue: 10-9; Wed: 10-9; Thurs: 10-9; Fri: 10-9; Sat: 10-9; Sun: 10-8",
      "createdAt": "2016-11-17T17:57:05.708Z",
      "updatedAt": "2016-11-17T17:57:05.708Z",
      "services": [
        {
          "id": 1,
          "name": "Geek Squad Services",
          "createdAt": "2016-11-17T17:56:35.881Z",
          "updatedAt": "2016-11-17T17:56:35.881Z",
          "storeservices": {
            "createdAt": "2016-11-17T17:57:09.213Z",
            "updatedAt": "2016-11-17T17:57:09.213Z",
            "storeId": 4,
            "serviceId": 1
          }
        },
        {
          "id": 2,
          "name": "Best Buy Mobile",
          "createdAt": "2016-11-17T17:56:35.881Z",
          "updatedAt": "2016-11-17T17:56:35.881Z",
          "storeservices": {
            "createdAt": "2016-11-17T17:57:09.213Z",
            "updatedAt": "2016-11-17T17:57:09.213Z",
            "storeId": 4,
            "serviceId": 2
          }
        },
// truncated

Does that sort of answer what you were looking for?

roelvan commented 7 years ago

Hi @BrandesEric thanks for the quick reply. Sorry next time I should explain my question in detail, my mistake. What I meant was, now all associations are already in the database. What if I want to do a call to link a new category to a product? There are calls to create standalone products, services, categories,... but how could I create a new connection between two entities. Eg. I want to add the category "Apple Devices" to the product "iMac" because that category hasn't been linked yet to that specific product. I am very curious how that could be implemented in Restful way. Btw, I really love this repo. I am learning a lot from it!

BrandesEric commented 7 years ago

Ah yes! I see what you mean :) Unfortunately there is nothing exposed today that will link them for you. While you can currently create categories and products, there aren't any calls that modify the productcategory table in the database at this time. I'll talk to the team about it and see if that's something that we're planning on exposing!

roelvan commented 7 years ago

Would love to see that :) Thanks for your time and effort!

Flet commented 7 years ago

@roelvan - I think its a great idea to add this functionality; do you mind if we keep this issue open for tracking?

roelvan commented 7 years ago

👌

On Mon, Dec 12, 2016, 23:43 Dan Flettre notifications@github.com wrote:

@roelvan https://github.com/roelvan - I think its a great idea to add this functionality; do you mind if we keep this issue open for tracking?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/BestBuy/api-playground/issues/10#issuecomment-266481822, or mute the thread https://github.com/notifications/unsubscribe-auth/ACdtHV3bbn9gtgnix8z1Q-rAawOrMyClks5rHXnNgaJpZM4LKX-- .