Merge branch 'fronkdev' into 'master'

Added Preorderselfservice API

See merge request fronk/thetool!806
This commit is contained in:
Frank Schubert
2024-12-11 14:48:17 +00:00
3 changed files with 112 additions and 1 deletions

View File

@@ -0,0 +1,73 @@
<?php
class PreorderselfserviceApicontroller extends mfBaseApicontroller {
public function init() {
$this->addRoute("/preorderselfservice/preorder", "getPreorder", "GET");
}
protected function authenticated() {
if($this->me->username != "preorder-selfservice-gui-api") {
return \mfResponse::Forbidden();
}
}
private function authUser() {
return true;
//return false;
}
protected function getPreorder() {
if(!$this->authUser()) {
return mfResponse::Forbidden(["status" => "403", "message" => "User authentication failed"]);
}
$auth_email = trim($this->get["auth_email"]);
$auth_phone = trim($this->get["auth_phone"]);
$search = [];
if($auth_email) {
$search = ["email" => $auth_email];
} elseif($auth_phone) {
$phone_search = [];
$auth_phone = preg_replace('/[^0-9]+/', '', $auth_phone);
$phone_search[] = $auth_phone;
if(substr($auth_phone, 0, 2) == "43") {
$phone_search[] = "+$auth_phone";
$auth_phone = preg_replace('/^43/', '0', $auth_phone);
$phone_search[] = $auth_phone;
}
if(substr($auth_phone, 0, 1) != "0") {
$phone_search[] = "0$auth_phone";
}
$search = ["phone" => $phone_search];
}
if(!count($search)) {
return mfResponse::BadRequest(["message" => "auth method missing"]);
}
$preorders = PreorderModel::searchActive($search);
$result = [];
foreach($preorders as $preorder) {
if(!$preorder->adb_hausnummer || !$preorder->adb_wohneinheit) continue;
//$hausnummer = $preorder->adb_hausnummer;
//$wohneinheit = $preorder->adb_wohneinheit;
$item = [];
$item["preorder"] = $preorder->getApiArray(["full_home", "full_address"]);
//$item["building"] = $hausnummer->getApiArray();
//$item["unit"] = $wohneinheit->getApiArray();
$result[] = $item;
}
return mfResponse::Ok($result);
}
}