Skip to content

Commit

Permalink
Adding mealtimes in Menu includes (#61)
Browse files Browse the repository at this point in the history
* Adding mealtimes in Menu includes

* fix styleCI error

Signed-off-by: Sam Poyigi <[email protected]>

* Add docs

Signed-off-by: Sam Poyigi <[email protected]>

Co-authored-by: Sam Poyigi <[email protected]>
  • Loading branch information
vahnmarty and sampoyigi authored Dec 4, 2021
1 parent a8c0ced commit a2d0a74
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
14 changes: 14 additions & 0 deletions apiresources/transformers/MealtimeTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Igniter\Api\ApiResources\Transformers;

use Admin\Models\Mealtimes_model;
use League\Fractal\TransformerAbstract;

class MealtimeTransformer extends TransformerAbstract
{
public function transform(Mealtimes_model $mealTime)
{
return array_merge($mealTime->toArray(), []);
}
}
10 changes: 10 additions & 0 deletions apiresources/transformers/MenuTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MenuTransformer extends TransformerAbstract
'media',
'categories',
'menu_options',
'mealtimes',
];

public function transform(Menus_model $menuItem)
Expand Down Expand Up @@ -45,4 +46,13 @@ public function includeMenuOptions(Menus_model $menuItem)
'menu_options'
);
}

public function includeMealtimes(Menus_model $menuItem)
{
return $this->collection(
$menuItem->mealtimes,
new MealtimeTransformer,
'mealtimes'
);
}
}
7 changes: 5 additions & 2 deletions docs/menus.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The endpoint responses are formatted according to the [JSON:API specification](h
| `order_restriction` | `string` | Has the value `delivery` if the menu is only available for delivery orders, the value `collection` if the menu is only available for pick-up orders, or the value `0` if the menu is available for both pick-up and delivery. |
| `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 |

#### Menu object example

Expand Down Expand Up @@ -108,7 +109,7 @@ GET /api/menus
| `location` | `integer` | The id of the location you wan to return menu items for |
| `category` | `integer` | The id of the category you wan to return menu items for |
| `search` | `string` | The phrase to search for in the menu item name and decsription |
| `include` | `string` | What relations to include in the response. Options are `media`, `categories`, `menu_options`. To include multiple seperate by comma (e.g. ?include=categories,menu_options) |
| `include` | `string` | What relations to include in the response. Options are `media`, `categories`, `mealtimes`, `menu_options`. To include multiple seperate by comma (e.g. ?include=categories,menu_options) |

#### Response

Expand Down Expand Up @@ -229,6 +230,7 @@ POST /api/menus
| `order_restriction` | `string` | Has the value `delivery` if the menu is only available for delivery orders, the value `collection` if the menu is only available for pick-up orders, or the value `0` if the menu is available for both pick-up and delivery. |
| `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 |

#### Payload example

Expand Down Expand Up @@ -284,7 +286,7 @@ GET /api/menus/:menu_id

| Key | Type | Description |
| -------------------- | --------- | ------------------------------------------------------------ |
| `include` | `string` | What relations to include in the response. Options are `media`, `categories`, `menu_options`. To include multiple seperate by comma (e.g. ?include=categories,menu_options) |
| `include` | `string` | What relations to include in the response. Options are `media`, `mealtimes`, `categories`, `menu_options`. To include multiple seperate by comma (e.g. ?include=categories,menu_options) |

#### Response

Expand Down Expand Up @@ -360,6 +362,7 @@ PATCH /api/menus/:menu_id
| `order_restriction` | `string` | Has the value `delivery` if the menu is only available for delivery orders, the value `collection` if the menu is only available for pick-up orders, or the value `0` if the menu is available for both pick-up and delivery. |
| `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 |

#### Payload example

Expand Down

0 comments on commit a2d0a74

Please sign in to comment.