Some sort of progress on category endpoint
This commit is contained in:
parent
e8c029186e
commit
68308b02a5
28
api/BusinessLogic/Categories/CategoryHandler.php
Normal file
28
api/BusinessLogic/Categories/CategoryHandler.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Categories;
|
||||||
|
|
||||||
|
|
||||||
|
use DataAccess\Categories\CategoryGateway;
|
||||||
|
|
||||||
|
class CategoryHandler {
|
||||||
|
/* @var $categoryGateway CategoryGateway */
|
||||||
|
private $categoryGateway;
|
||||||
|
|
||||||
|
function __construct($categoryGateway) {
|
||||||
|
$this->categoryGateway = $categoryGateway;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $category Category
|
||||||
|
* @param $heskSettings array
|
||||||
|
*/
|
||||||
|
function createCategory($category, $heskSettings) {
|
||||||
|
$this->categoryGateway->createCategory($category, $heskSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
function editCategory($category, $heskSettings) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ namespace Controllers\Categories;
|
|||||||
|
|
||||||
use BusinessLogic\Categories\CategoryRetriever;
|
use BusinessLogic\Categories\CategoryRetriever;
|
||||||
use BusinessLogic\Exceptions\ApiFriendlyException;
|
use BusinessLogic\Exceptions\ApiFriendlyException;
|
||||||
|
use Controllers\JsonRetriever;
|
||||||
|
|
||||||
class CategoryController {
|
class CategoryController {
|
||||||
function get($id) {
|
function get($id) {
|
||||||
@ -28,4 +29,18 @@ class CategoryController {
|
|||||||
|
|
||||||
return $categoryRetriever->getAllCategories($hesk_settings, $userContext);
|
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
|
||||||
|
}
|
||||||
}
|
}
|
@ -40,4 +40,23 @@ class CategoryGateway extends CommonDao {
|
|||||||
|
|
||||||
return $results;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
37
api/Tests/BusinessLogic/Categories/CategoryHandlerTest.php
Normal file
37
api/Tests/BusinessLogic/Categories/CategoryHandlerTest.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace BusinessLogic\Categories;
|
||||||
|
|
||||||
|
|
||||||
|
use DataAccess\Categories\CategoryGateway;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class CategoryHandlerTest extends TestCase {
|
||||||
|
/* @var $categoryGateway \PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $categoryGateway;
|
||||||
|
|
||||||
|
/* @var $categoryHandler CategoryHandler */
|
||||||
|
private $categoryHandler;
|
||||||
|
|
||||||
|
/* @var $heskSettings array */
|
||||||
|
private $heskSettings;
|
||||||
|
|
||||||
|
protected function setUp() {
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user