Skip to content

Commit

Permalink
Use new menu->stocks relationship
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Feb 8, 2022
1 parent 528311b commit 534304b
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 40 deletions.
10 changes: 10 additions & 0 deletions apiresources/transformers/MenuTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MenuTransformer extends TransformerAbstract
'categories',
'menu_options',
'mealtimes',
'stocks',
];

public function transform(Menus_model $menuItem)
Expand Down Expand Up @@ -55,4 +56,13 @@ public function includeMealtimes(Menus_model $menuItem)
'mealtimes'
);
}

public function includeStocks(Menus_model $menuItem)
{
return $this->collection(
$menuItem->stocks,
new StockTransformer,
'stocks'
);
}
}
5 changes: 4 additions & 1 deletion docs/menu_item_option_values.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ The endpoint responses are formatted according to the [JSON:API specification](h
| `subtract_stock` | `boolean` | The price of the option_value default 0 |
| `priority` | `integer` | The currency off the price as code **SET Automaticaly** |
| `is_default` | `boolean` | The default selected Option |
| `stocks` | `array` | The stocks, if any |

#### Option_value object example

```json
Expand All @@ -27,7 +29,8 @@ The endpoint responses are formatted according to the [JSON:API specification](h
"quantity": 0,
"subtract_stock": 0,
"priority": 1,
"is_default": true
"is_default": true,
"stocks": []
}
```

Expand Down
133 changes: 94 additions & 39 deletions docs/menus.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ The endpoint responses are formatted according to the [JSON:API specification](h
| `categories` | `array` | The menu's categories, if any (see [Categories](locations.md)) |
| `menu_options` | `array` | The menu's options, if any |
| `mealtimes` | `array` | The menu's mealtimes, if any |
| `stocks` | `array` | The menu's stocks, if any |

#### Menu object example

Expand Down Expand Up @@ -139,49 +140,93 @@ Status: 200 OK
"media": [
...
],
"categories": [...],
"menu_options": [...]
},
"relationships": {
"categories": {
"data": [...]
},
"menu_options": {
"data": [...]
}
}
},
{
"type": "menus",
"id": "2",
"attributes": {
"menu_name": "Doughnut",
"menu_description": "Deep fried from a flour dough with sweet fillings",
"menu_price": "0.99"
"currency": "GBP",
"menu_photo": null,
"stock_qty": 1000,
"minimum_qty": 1,
"subtract_stock": true,
"mealtime_id": null,
"menu_status": true,
"menu_priority": 0,
"order_restriction": null,
"media": [
"categories": [
...
],
"categories": [...],
"menu_options": [...]
"menu_options": [
...
],
"mealtimes": [
...
],
"stocks": [
...
]
},
"relationships": {
"categories": {
"data": [...]
},
"menu_options": {
"data": [...]
"relationships": {
"categories": {
"data": [
...
]
},
"menu_options": {
"data": [
...
]
},
"mealtimes": {
"data": [
...
]
},
"stocks": {
"data": [
...
]
}
}
},
{
"type": "menus",
"id": "2",
"attributes": {
"menu_name": "Doughnut",
"menu_description": "Deep fried from a flour dough with sweet fillings",
"menu_price": "0.99"
"currency": "GBP",
"minimum_qty": 1,
"menu_status": true,
"menu_priority": 0,
"order_restriction": null,
"media": [
...
],
"categories": [
...
],
"menu_options": [
...
],
"mealtimes": [
...
],
"stocks": [
...
]
},
"relationships": {
"categories": {
"data": [
...
]
},
"menu_options": {
"data": [
...
]
},
"mealtimes": {
"data": [
...
]
},
"stocks": {
"data": [
...
]
}
}
}
}
],
"included": [
...
Expand Down Expand Up @@ -231,6 +276,7 @@ POST /api/menus
| `categories` | `array` | The menu's categories, if any (see [Categories](locations.md)) |
| `menu_options` | `array` | The menu's options, if any |
| `mealtimes` | `array` | The mealtime's options, if any |
| `stocks` | `array` | The stock's options, if any |

#### Payload example

Expand Down Expand Up @@ -317,14 +363,22 @@ Status: 200 OK
...
],
"categories": [...],
"menu_options": [...]
"menu_options": [...],
"mealtimes": [...],
"stocks": [...]
},
"relationships": {
"categories": {
"data": [...]
},
"menu_options": {
"data": [...]
},
"mealtimes": {
"data": [...]
},
"stocks": {
"data": [...]
}
}
}
Expand Down Expand Up @@ -363,6 +417,7 @@ PATCH /api/menus/:menu_id
| `categories` | `array` | The menu's categories, if any (see [Categories](locations.md)) |
| `menu_options` | `array` | The menu's options, if any |
| `mealtimes` | `array` | The mealtime's options, if any |
| `stocks` | `array` | The stock's options, if any |

#### Payload example

Expand Down

0 comments on commit 534304b

Please sign in to comment.