Should be able to create categories now...
This commit is contained in:
parent
f7d03f66cd
commit
1185785dbd
@ -3,6 +3,7 @@
|
||||
namespace BusinessLogic\Categories;
|
||||
|
||||
|
||||
use BusinessLogic\Exceptions\ValidationException;
|
||||
use BusinessLogic\ValidationModel;
|
||||
use DataAccess\Categories\CategoryGateway;
|
||||
|
||||
@ -17,11 +18,20 @@ class CategoryHandler {
|
||||
/**
|
||||
* @param $category Category
|
||||
* @param $heskSettings array
|
||||
* @return Category The newly created category with ID
|
||||
* @throws ValidationException When validation fails
|
||||
*/
|
||||
//TODO Test
|
||||
function createCategory($category, $heskSettings) {
|
||||
$validationModel = $this->validate($category, $heskSettings);
|
||||
|
||||
if (count($validationModel->errorKeys) > 0) {
|
||||
throw new ValidationException($validationModel);
|
||||
}
|
||||
|
||||
$this->categoryGateway->createCategory($category, $heskSettings);
|
||||
$category->id = $this->categoryGateway->createCategory($category, $heskSettings);
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,7 +40,8 @@ class CategoryHandler {
|
||||
* @param $creating bool
|
||||
* @return ValidationModel
|
||||
*/
|
||||
function validate($category, $heskSettings, $creating = true) {
|
||||
//TODO Test
|
||||
private function validate($category, $heskSettings, $creating = true) {
|
||||
$validationModel = new ValidationModel();
|
||||
if (!$creating && $category->id < 1) {
|
||||
$validationModel->errorKeys[] = 'ID_MISSING';
|
||||
|
@ -2,8 +2,11 @@
|
||||
|
||||
namespace Controllers\Categories;
|
||||
|
||||
use BusinessLogic\Categories\Category;
|
||||
use BusinessLogic\Categories\CategoryHandler;
|
||||
use BusinessLogic\Categories\CategoryRetriever;
|
||||
use BusinessLogic\Exceptions\ApiFriendlyException;
|
||||
use BusinessLogic\Helpers;
|
||||
use Controllers\JsonRetriever;
|
||||
|
||||
class CategoryController {
|
||||
@ -31,9 +34,37 @@ class CategoryController {
|
||||
}
|
||||
|
||||
function post() {
|
||||
//-- TODO: Create Category
|
||||
global $hesk_settings, $applicationContext;
|
||||
|
||||
$data = JsonRetriever::getJsonData();
|
||||
|
||||
$category = $this->buildCategoryFromJson($data);
|
||||
|
||||
/* @var $categoryHandler CategoryHandler */
|
||||
$categoryHandler = $applicationContext->get[CategoryHandler::class];
|
||||
|
||||
$category = $categoryHandler->createCategory($category, $hesk_settings);
|
||||
|
||||
return output($category);
|
||||
}
|
||||
|
||||
private function buildCategoryFromJson($json) {
|
||||
$category = new Category();
|
||||
|
||||
$category->id = Helpers::safeArrayGet($json, 'id');
|
||||
$category->autoAssign = Helpers::safeArrayGet($json, 'autoassign');
|
||||
$category->backgroundColor = Helpers::safeArrayGet($json, 'backgroundColor');
|
||||
$category->catOrder = Helpers::safeArrayGet($json, 'order');
|
||||
$category->description = Helpers::safeArrayGet($json, 'description');
|
||||
$category->displayBorder = Helpers::safeArrayGet($json, 'displayBorder');
|
||||
$category->foregroundColor = Helpers::safeArrayGet($json, 'foregroundColor');
|
||||
$category->manager = Helpers::safeArrayGet($json, 'manager');
|
||||
$category->name = Helpers::safeArrayGet($json, 'name');
|
||||
$category->priority = Helpers::safeArrayGet($json, 'priority');
|
||||
$category->type = Helpers::safeArrayGet($json, 'type');
|
||||
$category->usage = Helpers::safeArrayGet($json, 'usage');
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
function put($id) {
|
||||
|
10
api/RequestMethod.php
Normal file
10
api/RequestMethod.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
class RequestMethod {
|
||||
const GET = 'GET';
|
||||
const POST = 'POST';
|
||||
const PUT = 'PUT';
|
||||
const DELETE = 'DELETE';
|
||||
const PATCH = 'PATCH';
|
||||
const ALL = [self::GET, self::POST, self::PUT, self::DELETE, self::PATCH];
|
||||
}
|
@ -187,7 +187,7 @@ Link::before('globalBefore');
|
||||
|
||||
Link::all(array(
|
||||
// Categories
|
||||
'/v1/categories' => action(\Controllers\Categories\CategoryController::class . '::printAllCategories'),
|
||||
'/v1/categories' => action(\Controllers\Categories\CategoryController::class . '::printAllCategories', [RequestMethod::GET]),
|
||||
'/v1/categories/{i}' => action(\Controllers\Categories\CategoryController::class),
|
||||
// Tickets
|
||||
'/v1/tickets' => action(\Controllers\Tickets\CustomerTicketController::class),
|
||||
@ -225,8 +225,14 @@ Link::all(array(
|
||||
'404' => 'handle404'
|
||||
));
|
||||
|
||||
function action($class, $securityHandler = SecurityHandler::AUTH_TOKEN) {
|
||||
return [$class, $class, $securityHandler];
|
||||
/**
|
||||
* @param $class object|string The class name (and optional static method)
|
||||
* @param $requestMethods array The accepted request methods for this endpoint
|
||||
* @param $securityHandler string The proper security handler
|
||||
* @return array The configured path
|
||||
*/
|
||||
function action($class, $requestMethods = RequestMethod::ALL, $securityHandler = SecurityHandler::AUTH_TOKEN) {
|
||||
return [$class, $class, $securityHandler, $requestMethods];
|
||||
}
|
||||
|
||||
class SecurityHandler {
|
||||
|
Loading…
x
Reference in New Issue
Block a user