diff --git a/api/controllers/CategoryController.php b/api/controllers/CategoryController.php index cf27e2b8..14cc66ff 100644 --- a/api/controllers/CategoryController.php +++ b/api/controllers/CategoryController.php @@ -11,11 +11,17 @@ namespace Controllers\Category; use BusinessLogic\Category\CategoryRetriever; class CategoryController { - function get($i) { - print json_encode(intval($i)); + function get($id) { + $categories = self::getAllCategories(); + output($categories[$id]); } - static function getAllCategories($hesk_settings) { + static function printAllCategories() { + output(self::getAllCategories()); + } + + private static function getAllCategories() { + global $hesk_settings; require_once(__DIR__ . '/../businesslogic/category/CategoryRetriever.php'); return CategoryRetriever::get_all_categories($hesk_settings); diff --git a/api/index.php b/api/index.php index c7e90a44..5858499e 100644 --- a/api/index.php +++ b/api/index.php @@ -8,27 +8,7 @@ require(__DIR__ . '/../hesk_settings.inc.php'); // Controllers require(__DIR__ . '/controllers/CategoryController.php'); - - -class HomeController -{ - - function get($i){ - echo 'You have got to home :) Val:' . intval($i); - } - - function post(){ - echo 'You have posted to home'; - } - - function put(){ - echo 'You have put to home'; - } - - function delete(){ - echo 'You have deleted the home :('; - } -} +hesk_load_api_database_functions(); function handle404() { http_response_code(404); @@ -43,7 +23,8 @@ function assertApiIsEnabled() { Link::before('assertApiIsEnabled'); Link::all(array( - '/' => 'assertApiIsEnabled', - '/test/{i}' => '\Controllers\Category\CategoryController', + // Categories + '/v1/categories' => '\Controllers\Category\CategoryController::printAllCategories', + '/v1/categories/{i}' => '\Controllers\Category\CategoryController', '404' => 'handle404' )); \ No newline at end of file