From 4b678b580db2ecc1e1c33a3317b17f4b37e2208f Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Mon, 4 Dec 2023 13:04:00 +0100 Subject: [PATCH] Added Preorder API EP getCifData; added cifcableurl to preorder --- .../Api/v1/Modules/ApiControllerModule.php | 35 ++++++++++++ application/Api/v1/Modules/Preorder/Cif.php | 54 +++++++++++++++++++ application/Api/v1/Preorder/Preorder_Cif.php | 16 ------ application/Api/v1/PreorderApicontroller.php | 42 +++++++++------ application/Preorder/Preorder.php | 40 ++++++++++++++ .../PreorderlogisticsController.php | 5 ++ ...0231204100158_preorder_add_cifcableurl.php | 31 +++++++++++ public/docs/preorder-api.yaml | 4 ++ 8 files changed, 195 insertions(+), 32 deletions(-) create mode 100644 application/Api/v1/Modules/ApiControllerModule.php create mode 100644 application/Api/v1/Modules/Preorder/Cif.php delete mode 100644 application/Api/v1/Preorder/Preorder_Cif.php create mode 100644 db/migrations/20231204100158_preorder_add_cifcableurl.php diff --git a/application/Api/v1/Modules/ApiControllerModule.php b/application/Api/v1/Modules/ApiControllerModule.php new file mode 100644 index 000000000..6418ca2a5 --- /dev/null +++ b/application/Api/v1/Modules/ApiControllerModule.php @@ -0,0 +1,35 @@ +log = \mfLoghandler::singleton(); + + if(is_array($dependencies) && count($dependencies)) { + foreach($dependencies as $name => $dep) { + $this->$name = $dep; + } + } + + if(method_exists($this, "init")) { + $this->init(); + } + } + + public function __get($name) { + if(array_key_exists($name, $this->dependencies)) { + return $this->dependencies[$name]; + } + return null; + } + + public function __set($name, $value) { + $this->dependencies[$name] = $value; + return true; + } + +} \ No newline at end of file diff --git a/application/Api/v1/Modules/Preorder/Cif.php b/application/Api/v1/Modules/Preorder/Cif.php new file mode 100644 index 000000000..5706655c3 --- /dev/null +++ b/application/Api/v1/Modules/Preorder/Cif.php @@ -0,0 +1,54 @@ + "in providerSetCif($code)"]); + } + + public function getCifData() { + + if(!array_key_exists("ciftoken", $this->get) || !$this->get['ciftoken']) { + return \mfResponse::BadRequest(["message" => "ciftoken missing"]); + } + + $preorder = \PreorderModel::getFirst(["ciftoken" => $this->get["ciftoken"], "partner_id" => $this->me->address_id]); + if(!$preorder) { + return \mfResponse::NotFound(["message" => "Invalid ciftoken"]); + } + + $return = $preorder->getCifdataApiArray(); + + return \mfResponse::Ok($return); + } + + public function userSetCif() { + return \mfResponse::InternalServerError(); + + if(!array_key_exists("ciftoken", $this->get) || !$this->get['ciftoken']) { + return \mfResponse::BadRequest(["message" => "ciftoken missing"]); + } + + $preorder = \PreorderModel::getFirst(["ciftoken" => $this->get["ciftoken"], "partner_id" => $this->me->address_id]); + if(!$preorder) { + return \mfResponse::NotFound(["message" => "Invalid ciftoken"]); + } + + } + + + +} \ No newline at end of file diff --git a/application/Api/v1/Preorder/Preorder_Cif.php b/application/Api/v1/Preorder/Preorder_Cif.php deleted file mode 100644 index 9655b7083..000000000 --- a/application/Api/v1/Preorder/Preorder_Cif.php +++ /dev/null @@ -1,16 +0,0 @@ - "in providerSetCif($code)"]); - } - - public function getCifData() { - return mfResponse::Ok(["message" => "in getCifData()"]); - } - - public function userSetCif() { - return mfResponse::Ok(["message" => "in userSetCif()"]); - } -} \ No newline at end of file diff --git a/application/Api/v1/PreorderApicontroller.php b/application/Api/v1/PreorderApicontroller.php index ca28321d9..d97442974 100644 --- a/application/Api/v1/PreorderApicontroller.php +++ b/application/Api/v1/PreorderApicontroller.php @@ -1,6 +1,8 @@ db(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME); - - $cifObject = new Preorder_Cif(); - - $this->addRoute("/preorder", "submitPreorder", "POST"); - $this->addRoute("/preorder/open", "getOpenPreorders", "GET"); - $this->addRoute("/preorder/customerInstallationFeedback", [$cifObject, "getCifData"], "GET"); - $this->addRoute("/preorder/customerInstallationFeedback", [$cifObject, "userSetCif"], "POST"); - - $this->addRoute("/preorder/:code", "getPreorder", "GET"); - $this->addRoute("/preorder/:code", "cancelPreorder", "DELETE"); - $this->addRoute("/preorder/:code/clientInstallationFinished", [$cifObject, "providerSetCif"], "GET"); - $this->addRoute("/preorder/:code/serviceActivated", "setServiceActive", "POST"); - $this->allowMissingOrigin = true; } + protected function registerRoutes() { + $moduleCif = new Modules\Preorder\Cif([ + "get" => $this->get, + "post" => $this->post, + "db" => $this->db(), + "me" => $this->me + ]); + + $this->addRoute("/preorder", "submitPreorder", "POST"); + $this->addRoute("/preorder/open", "getOpenPreorders", "GET"); + $this->addRoute("/preorder/customerInstallationFeedback", [$moduleCif, "getCifData"], "GET"); + $this->addRoute("/preorder/customerInstallationFeedback", [$moduleCif, "userSetCif"], "POST"); + + $this->addRoute("/preorder/:code", "getPreorder", "GET"); + $this->addRoute("/preorder/:code", "cancelPreorder", "DELETE"); + $this->addRoute("/preorder/:code/clientInstallationFinished", [$moduleCif, "providerSetCif"], "GET"); + $this->addRoute("/preorder/:code/serviceActivated", "setServiceActive", "POST"); + } + + /* + * is called after User is authenticated by API Key + */ protected function authenticated() { + $this->registerRoutes(); if($this->me->is("preorderaddressreporting")) { return mfResponse::Forbidden(); @@ -92,8 +104,6 @@ class PreorderApicontroller extends mfBaseApicontroller { } $this->allowed_preordertypes = array_unique($this->allowed_preordertypes); - - //var_dump($campaign, $this->allowed_origins);exit; } protected function getOpenPreorders() { diff --git a/application/Preorder/Preorder.php b/application/Preorder/Preorder.php index 8685229d4..4c3ee81dd 100644 --- a/application/Preorder/Preorder.php +++ b/application/Preorder/Preorder.php @@ -370,6 +370,45 @@ class Preorder extends mfBaseModel { return $ciftoken; } + public function getCifdataApiArray() { + if(!$this->id) { + return false; + } + + $hausnummer = $this->getProperty("adb_hausnummer"); + $wohneinheit = $this->getProperty("adb_wohneinheit"); + + $a = []; + $a["ciftoken"] = $this->ciftoken; + $a["code"] = $this->ucode; + $a['oaid'] = $this->oaid; + + $a['company'] = ($this->company) ? $this->company : null; + $a['uid'] = ($this->uid) ? $this->uid : null; + $a['firstnam'] = ($this->firstname) ? $this->firstname : null; + $a['lastname'] = ($this->lastname) ? $this->lastname : null; + + $a['street'] = $hausnummer->strasse->name; + $a['housenumber'] = $hausnummer->hausnummer; + $a['zip'] = $hausnummer->plz->plz; + $a['city'] = $hausnummer->strasse->gemeinde->name; + $a['municipality'] = ""; + $a['district'] = $hausnummer->ortschaft->name; + $a['block'] = ($wohneinheit->block) ? $wohneinheit->block : null; + $a['stock'] = ($wohneinheit->stock) ? $wohneinheit->stock : null; + $a['stiege'] = ($wohneinheit->stiege) ? $wohneinheit->stiege : null; + $a['tuer'] = ($wohneinheit->tuer) ? $wohneinheit->tuer : null; + + if($campaign->district_is_city) { + $a['city'] = $hausnummer->ortschaft->name; + $a['municipality'] = $hausnummer->strasse->gemeinde->name; + } else { + unset($a['municipality']); + } + + return $a; + } + public function getApiArray() { if(!$this->id) { return false; @@ -388,6 +427,7 @@ class Preorder extends mfBaseModel { $a['status'] = $this->getProperty("status")->getApiArray(); $a['ciftoken'] = ($this->ciftoken) ? $this->ciftoken : null; $a['cifurl'] = ($this->cifurl) ? $this->cifurl : null; + $a['cifcableurl'] = ($this->cifcableurl) ? $this->cifcableurl : null; $a['installationDate'] = ($this->installation_date) ? date("c", $this->installation_date) : null; $a['connectionType'] = $this->connection_type; $a['connectionCount'] = ($this->connection_count) ? (int)$this->connection_count : 1; diff --git a/application/Preorderlogistics/PreorderlogisticsController.php b/application/Preorderlogistics/PreorderlogisticsController.php index d95070dde..fe12ce4cb 100644 --- a/application/Preorderlogistics/PreorderlogisticsController.php +++ b/application/Preorderlogistics/PreorderlogisticsController.php @@ -202,6 +202,11 @@ class PreorderlogisticsController extends mfBaseController { $preorder->save(); } + if(!$preorder->cifcableurl) { + $preorder->cifcableurl = "https://www.deineglasfaser.at/kundinnen/leerrohr-nachbestellung/"; + $preorder->save(); + } + $plog = PreorderlogisticsModel::getFirst(["preorder_id" => $preorder->id]); if(!$plog) { diff --git a/db/migrations/20231204100158_preorder_add_cifcableurl.php b/db/migrations/20231204100158_preorder_add_cifcableurl.php new file mode 100644 index 000000000..c1f574eaa --- /dev/null +++ b/db/migrations/20231204100158_preorder_add_cifcableurl.php @@ -0,0 +1,31 @@ +getEnvironment() == "thetool") { + $table = $this->table("Preorder"); + $table->addColumn("cifcableurl", "string", ["null" => true, "default" => null, "limit" => 255, "after" => "cifurl"]); + $table->update(); + } + + if($this->getEnvironment() == "addressdb") { + + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + + } + + if($this->getEnvironment() == "addressdb") { + + } + } +} diff --git a/public/docs/preorder-api.yaml b/public/docs/preorder-api.yaml index f98e304b1..ef8a69f7d 100644 --- a/public/docs/preorder-api.yaml +++ b/public/docs/preorder-api.yaml @@ -1442,6 +1442,10 @@ components: type: string description: Customer Installation Feedback Url example: "https://pro.ichwillglasfaser.at/ClientSubmit/finishedInstallationWork?c=XArjnWQXGq4a8JWF" + cifcableurl: + type: string + description: Url to order various lengths of cable for Customer Installation + example: "https://www.ichwillglasfaser.at/CableOrderForm" installationDate: type: string format: date-time