CategoryCreateController.php 867 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace Controllers;
  3. use Libs\ResponseLib;
  4. use Models\CategoryModel;
  5. use Psr\Http\Message\ServerRequestInterface;
  6. class CategoryCreateController
  7. {
  8. private CategoryModel $model;
  9. public function __construct()
  10. {
  11. $this->model = new CategoryModel();
  12. }
  13. public function __invoke(ServerRequestInterface $request)
  14. {
  15. $body = json_decode((string)$request->getBody(), true) ?? [];
  16. $companyId = $body['company_id'] ?? null;
  17. $created = $this->model->createCategory(
  18. $body['category_name'],
  19. $companyId,
  20. $body['category_is_kitchen'] ?? false
  21. );
  22. return $created ? ResponseLib::sendOk(['created' => true]) : ResponseLib::sendFail("Failed to Create Category", [], "E_VALIDATE")->withStatus(402);
  23. }
  24. }