| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace Controllers;
- use Libs\ResponseLib;
- use Psr\Http\Message\ServerRequestInterface;
- use Models\KitchenModel;
- use Respect\Validation\Validator as v;
- use Respect\Validation\Exceptions\ValidationException;
- class KitchenGetController
- {
- private KitchenModel $model;
- public function __construct()
- {
- $this->model = new KitchenModel();
- }
- public function __invoke(ServerRequestInterface $request)
- {
- $body = json_decode((string) $request->getBody(), true) ?? [];
- try {
- v::key('company_id', v::intType()->positive())->assert($body);
- } catch (ValidationException $e) {
- return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
- }
- $companyId = (int) $body['company_id'];
- $orders = $this->model->getKitchenOrders($companyId);
- if (!$orders) {
- return ResponseLib::sendFail("No kitchen orders found", [], "E_NO_DATA")->withStatus(204);
- }
- return ResponseLib::sendOk($orders);
- }
- }
|