diff --git a/api/BusinessLogic/Categories/CategoryHandler.php b/api/BusinessLogic/Categories/CategoryHandler.php new file mode 100644 index 00000000..ca315998 --- /dev/null +++ b/api/BusinessLogic/Categories/CategoryHandler.php @@ -0,0 +1,28 @@ +categoryGateway = $categoryGateway; + } + + /** + * @param $category Category + * @param $heskSettings array + */ + function createCategory($category, $heskSettings) { + $this->categoryGateway->createCategory($category, $heskSettings); + } + + function editCategory($category, $heskSettings) { + + + } +} \ No newline at end of file diff --git a/api/Controllers/Categories/CategoryController.php b/api/Controllers/Categories/CategoryController.php index e376afef..bb729ca7 100644 --- a/api/Controllers/Categories/CategoryController.php +++ b/api/Controllers/Categories/CategoryController.php @@ -4,6 +4,7 @@ namespace Controllers\Categories; use BusinessLogic\Categories\CategoryRetriever; use BusinessLogic\Exceptions\ApiFriendlyException; +use Controllers\JsonRetriever; class CategoryController { function get($id) { @@ -28,4 +29,18 @@ class CategoryController { return $categoryRetriever->getAllCategories($hesk_settings, $userContext); } + + function post() { + //-- TODO: Create Category + $data = JsonRetriever::getJsonData(); + + } + + function put($id) { + //-- TODO: Edit category + } + + function delete($id) { + //-- TODO: Delete category + } } \ No newline at end of file diff --git a/api/DataAccess/Categories/CategoryGateway.php b/api/DataAccess/Categories/CategoryGateway.php index 4fd35c7b..fde6f824 100644 --- a/api/DataAccess/Categories/CategoryGateway.php +++ b/api/DataAccess/Categories/CategoryGateway.php @@ -40,4 +40,23 @@ class CategoryGateway extends CommonDao { return $results; } + + /** + * @param $category Category + * @param $heskSettings array + */ + function createCategory($category, $heskSettings) { + $this->init(); + + $sql = "INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` () + VALUES ()"; + + $this->close(); + } + + function updateCategory($category, $heskSettings) { + $this->init(); + + $this->close(); + } } \ No newline at end of file diff --git a/api/Tests/BusinessLogic/Categories/CategoryHandlerTest.php b/api/Tests/BusinessLogic/Categories/CategoryHandlerTest.php new file mode 100644 index 00000000..32b5f99c --- /dev/null +++ b/api/Tests/BusinessLogic/Categories/CategoryHandlerTest.php @@ -0,0 +1,37 @@ +categoryGateway = $this->createMock(CategoryGateway::class); + + $this->categoryHandler = new CategoryHandler($this->categoryGateway); + $this->heskSettings = array(); + } + + function testCreateCallsTheGatewayWithTheCategory() { + //-- Arrange + $category = new Category(); + + //-- Assert + $this->categoryGateway->expects($this->once())->method('createCategory')->with($category, $this->heskSettings); + + //-- Act + $this->categoryHandler->createCategory($category, $this->heskSettings); + } +}