diff --git a/server/SHServ/Controllers/DevicesRESTAPIController.php b/server/SHServ/Controllers/DevicesRESTAPIController.php
new file mode 100644
index 0000000..1ad5d05
--- /dev/null
+++ b/server/SHServ/Controllers/DevicesRESTAPIController.php
@@ -0,0 +1,52 @@
+ get_unregistered_devices();
+
+ return $this -> utils() -> response_success([
+ "devices" => $devices
+ ]);
+ }
+
+ public function scanning__all() {
+ $device_model = new Devices();
+ $devices = $device_model -> scanning_localnet(FCONF["device_ip_range"][0], FCONF["device_ip_range"][1]);
+
+ return $this -> utils() -> response_success([
+ "devices" => $devices
+ ]);
+ }
+
+ public function setup_new_device($device_ip, $alias, $description) {
+ $devices_model = new \SHServ\Models\Devices();
+ $result = $devices_model -> connect_new_device($device_ip, $alias, $description);
+
+ return $this -> utils() -> response_success([
+ "result" => $result ? true : false
+ ]);
+ }
+
+ public function remove_device($device_id) {
+ $devices_model = new Devices();
+ $result = $devices_model -> remove_device(intval($device_id));
+
+ return $this -> utils() -> response_success([
+ "result" => $result
+ ]);
+ }
+
+ public function reset_device() {
+
+ }
+
+ public function reboot_device() {
+
+ }
+}
\ No newline at end of file
diff --git a/server/SHServ/Routes.php b/server/SHServ/Routes.php
index c9a77f9..7a7df2e 100644
--- a/server/SHServ/Routes.php
+++ b/server/SHServ/Routes.php
@@ -3,6 +3,10 @@
namespace SHServ;
class Routes {
+
+ use \SHServ\Routes\DevMode;
+ use \SHServ\Routes\RESTAPI_v1;
+
/**
* Instance of Router module
*/
@@ -18,10 +22,6 @@
*/
protected String $cn;
- /**
- * @method __construct
- * @param \Fury\Modules\Router\Router $router [description]
- */
public function __construct(\Fury\Modules\Router\Router $router) {
$this -> router = $router;
$this -> cf = FCONF["controllers_folder"];
@@ -32,25 +32,25 @@
$this -> uri_routes();
$this -> get_routes();
$this -> post_routes();
+
+ $this -> restapi_uri_routes();
+ $this -> restapi_get_routes();
+ $this -> restapi_post_routes();
+
+ // DEV MODE
+ if(FCONF["devmode"]) {
+ $this -> devmode_uri_routes();
+ $this -> devmode_get_routes();
+ $this -> devmode_post_routes();
+ }
}
+ // Examples
+ // $this -> router -> uri("/", "{$this -> cn}\\SearchController@search_page");
+ // $this -> router -> uri('/not-found.html', "{$this -> cn}\\InfoPagesController@not_found_page");
+
+ // $this -> router -> uri('/uadpost/$alias', "{$this -> cn}\\UAdPostController@view_page");
protected function uri_routes() {
- // pages
- // $this -> router -> uri("/", "{$this -> cn}\\SearchController@search_page");
- // $this -> router -> uri('/not-found.html', "{$this -> cn}\\InfoPagesController@not_found_page");
-
- // $this -> router -> uri('/uadpost/$alias', "{$this -> cn}\\UAdPostController@view_page");
-
-
- // $this -> router -> uri(
- // '/profile/orders/$utype/exclude-states',
- // function($args) {
- // return app() -> utils -> redirect(
- // app() -> routes -> urlto("OrderController@orders_cur_user_page", ["utype" => $args["utype"]])
- // );
- // }
- // );
-
$this -> router -> uri("/", function(){
return "Smart home server.
Version 0.1 dev";
});
@@ -58,36 +58,7 @@
$this -> router -> uri("/cron/regular-scripts.html", "{$this -> cn}\\CronController@run_regular_cron_scripts");
$this -> router -> uri("/cron/status-update-scanning.html", "{$this -> cn}\\CronController@status_update_scanning");
- if(FCONF["devmode"]) {
- $this -> router -> uri("/dev/test/device-scanner.html", "{$this -> cn}\\DevTestController@device_scanner");
- $this -> router -> uri("/dev/test/device-api-base/about.html", "{$this -> cn}\\DevTestController@device_api_base__about");
- $this -> router -> uri("/dev/test/device-api-base/set_token.html", "{$this -> cn}\\DevTestController@device_api_base__set_token");
- $this -> router -> uri("/dev/test/device-api-base/reboot.html", "{$this -> cn}\\DevTestController@device_api_base__reboot");
- $this -> router -> uri("/dev/test/device-api-base/action.html", "{$this -> cn}\\DevTestController@device_api_base__post_action");
- $this -> router -> uri("/dev/test/device-api-base/set_device_name.html", "{$this -> cn}\\DevTestController@device_api_base__set_device_name");
- $this -> router -> uri("/dev/test/device-api-base/reset.html", "{$this -> cn}\\DevTestController@device_api_base__reset");
-
- $this -> router -> uri("/dev/test/model/devices/connect_new_device.html", function($args){
- $devices_model = new \SHServ\Models\Devices();
-
- echo "
";
- var_dump($devices_model -> connect_new_device("192.168.68.2", "test_back_street_light", "Test device. Back street light"));
- });
-
- $this -> router -> uri("/dev/test/model/devices/unregistered_devices.html", function($args){
- $devices_model = new \SHServ\Models\Devices();
-
- echo "";
- var_dump($devices_model -> get_unregistered_devices());
- });
-
- $this -> router -> uri("/dev/test/model/devices/remove_device.html", function($args){
- $devices_model = new \SHServ\Models\Devices();
-
- echo "";
- var_dump($devices_model -> remove_device(6));
- });
- }
+
}
protected function get_routes() {
@@ -99,17 +70,18 @@
}
protected function post_routes() {
- $this -> router -> post(
- [ "email", "password", "password_again" ],
- "{$this -> cn}\\AuthController@signup",
- "/auth/signup"
- );
+ // $this -> router -> post(
+ // [ "email", "password", "password_again" ],
+ // "{$this -> cn}\\AuthController@signup",
+ // "/auth/signup"
+ // );
- $this -> router -> post(
- [ "event_name", "device_id", "data"],
- "{$this -> cn}\\EventsController@new_event",
- "/events/new"
- );
+ // $this -> router -> post(
+ // [ "event_name", "device_id", "data"],
+ // "{$this -> cn}\\EventsController@new_event",
+ // "/events/new"
+ // );
+
}
/**
diff --git a/server/SHServ/Routes/DevMode.php b/server/SHServ/Routes/DevMode.php
new file mode 100644
index 0000000..84c967a
--- /dev/null
+++ b/server/SHServ/Routes/DevMode.php
@@ -0,0 +1,44 @@
+ router -> uri("/dev/test/device-scanner.html", "{$this -> cn}\\DevTestController@device_scanner");
+ $this -> router -> uri("/dev/test/device-api-base/about.html", "{$this -> cn}\\DevTestController@device_api_base__about");
+ $this -> router -> uri("/dev/test/device-api-base/set_token.html", "{$this -> cn}\\DevTestController@device_api_base__set_token");
+ $this -> router -> uri("/dev/test/device-api-base/reboot.html", "{$this -> cn}\\DevTestController@device_api_base__reboot");
+ $this -> router -> uri("/dev/test/device-api-base/action.html", "{$this -> cn}\\DevTestController@device_api_base__post_action");
+ $this -> router -> uri("/dev/test/device-api-base/set_device_name.html", "{$this -> cn}\\DevTestController@device_api_base__set_device_name");
+ $this -> router -> uri("/dev/test/device-api-base/reset.html", "{$this -> cn}\\DevTestController@device_api_base__reset");
+
+ $this -> router -> uri("/dev/test/model/devices/connect_new_device.html", function($args){
+ $devices_model = new \SHServ\Models\Devices();
+
+ echo "";
+ var_dump($devices_model -> connect_new_device("192.168.68.2", "test_back_street_light", "Test device. Back street light"));
+ });
+
+ $this -> router -> uri("/dev/test/model/devices/unregistered_devices.html", function($args){
+ $devices_model = new \SHServ\Models\Devices();
+
+ echo "";
+ var_dump($devices_model -> get_unregistered_devices());
+ });
+
+ $this -> router -> uri("/dev/test/model/devices/remove_device.html", function($args){
+ $devices_model = new \SHServ\Models\Devices();
+
+ echo "";
+ var_dump($devices_model -> remove_device(6));
+ });
+ }
+
+ protected function devmode_get_routes() {
+
+ }
+
+ protected function devmode_post_routes() {
+
+ }
+}
\ No newline at end of file
diff --git a/server/SHServ/Routes/RESTAPI_v1.php b/server/SHServ/Routes/RESTAPI_v1.php
new file mode 100644
index 0000000..7129541
--- /dev/null
+++ b/server/SHServ/Routes/RESTAPI_v1.php
@@ -0,0 +1,23 @@
+ router -> uri("/api/v1/devices/scanning/setup", "{$this -> cn}\\DevicesRESTAPIController@scanning__ready_to_setup");
+ $this -> router -> uri("/api/v1/devices/scanning/all", "{$this -> cn}\\DevicesRESTAPIController@scanning__all");
+ $this -> router -> uri('/api/v1/devices/remove/$device_id', "{$this -> cn}\\DevicesRESTAPIController@remove_device");
+ }
+
+ protected function restapi_get_routes() {
+
+ }
+
+ protected function restapi_post_routes() {
+ $this -> router -> post(
+ [ "event_name", "device_id", "data"],
+ "{$this -> cn}\\DevicesRESTAPIController@setup_new_device",
+ "/api/v1/devices/setup/new-device"
+ );
+ }
+}
\ No newline at end of file
diff --git a/server/SHServ/Utils.php b/server/SHServ/Utils.php
index 748c465..f9a117f 100644
--- a/server/SHServ/Utils.php
+++ b/server/SHServ/Utils.php
@@ -12,6 +12,7 @@
}
public function response_error(String $error_alias, Array $failed_fields = [], Array $extra = []) {
+ header("Content-Type: application/json");
return json_encode(array_merge([
"status" => false,
"error_alias" => $error_alias,
@@ -21,6 +22,7 @@
}
public function response_success(Array $resp_data = []) {
+ header("Content-Type: application/json");
return json_encode([
"status" => true,
"data" => $resp_data