| 1234567891011121314151617181920212223242526272829 |
- <?php
- namespace Controllers;
- use Libs\ResponseLib;
- use Models\CategoryModel;
- use Psr\Http\Message\ServerRequestInterface;
- class CategoryCreateController
- {
- private CategoryModel $model;
- public function __construct()
- {
- $this->model = new CategoryModel();
- }
- public function __invoke(ServerRequestInterface $request)
- {
- $body = json_decode((string)$request->getBody(), true) ?? [];
- $companyId = $body['company_id'] ?? null;
- $created = $this->model->createCategory(
- $body['category_name'],
- $companyId,
- $body['category_is_kitchen'] ?? false
- );
- return $created ? ResponseLib::sendOk(['created' => true]) : ResponseLib::sendFail("Failed to Create Category", [], "E_VALIDATE")->withStatus(402);
- }
- }
|