Merge branch 'master' of code.fronk.at:fronk/thetool

This commit is contained in:
Frank Schubert
2022-09-06 19:10:12 +02:00
9 changed files with 292 additions and 67 deletions

View File

@@ -1,7 +1,7 @@
<?php
class ADBGemeinde extends mfBaseModel {
public $plz = [];
public $plzs = [];
protected function init() {
@@ -39,10 +39,10 @@ class ADBGemeinde extends mfBaseModel {
}
public function afterLoad() {
$this->loadPlz();
//$this->loadPlz();
}
public function loadPlz() {
/*public function loadPlz() {
if(!$this->id) {
return false;
}
@@ -57,12 +57,12 @@ class ADBGemeinde extends mfBaseModel {
}
return true;
}
}*/
public function getPlzList() {
$list = [];
foreach($this->plz as $plz) {
$list[$plz->id] = $plz->plz;
foreach($this->plzs as $plz) {
$list[$plz->id] = $plz->plzs;
}
return $list;
}

View File

@@ -2,6 +2,7 @@
class ADBHausnummer extends mfBaseModel {
public $strasse;
public $plz;
public $status;
public $providers = [];
public $providerlist = [];
@@ -13,33 +14,7 @@ class ADBHausnummer extends mfBaseModel {
public function afterLoad() {
$this->strasse = new ADBStrasse($this->strasse_id);
//$this->loadStatus();
//$this->loadProvider();
$this->plz = new ADBPlz($this->plz_id);
}
/*
public function loadStatus() {
if(!$this->id) {
return false;
}
$status = HausnummerStatus::singleton();
$this->status = $status->getObject($this->status_id);
}
public function loadProvider() {
if(!$this->id) {
return false;
}
$res = $this->db->select("HausnummerProvider", "*", "hausnummer_id=".$this->id);
if($this->db->num_rows($res)) {
while($data = $this->db->fetch_object($res)) {
$provider = new Provider($data->provider_id);
$this->providerlist[$provider->id] = $provider->name;
$this->providers[] = $provider;
}
}
return true;
}*/
}

View File

@@ -1,10 +1,11 @@
<?php
class ADBHausnummerModel {
public $gemeinde_id;
public $plz_id;
public $strasse_id;
public $kennziffer;
public $name;
public $plz;
public $create_by = null;
public $edit_by = null;
@@ -116,6 +117,14 @@ class ADBHausnummerModel {
private static function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("plz_id", $filter)) {
$plz_id = $filter['plz_id'];
if(is_numeric($plz_id)) {
$where .= " AND Hausnummer.plz_id=$plz_id";
} elseif(is_array($plz_id) && count($plz_id)) {
$where .= " AND Hausnummer.plz_id IN (". implode(",", $plz_id).")";
}
}
if(array_key_exists("strasse_id", $filter)) {
$strasse_id = $filter['strasse_id'];

View File

@@ -25,4 +25,5 @@ class ADBOrtschaft extends mfBaseModel {
return $results;
}
}

View File

@@ -1,7 +1,6 @@
<?php
class ADBPlzModel {
public $gemeinde_id;
public $plz;
public $plzstring;
@@ -40,7 +39,7 @@ class ADBPlzModel {
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$where = self::getSqlFilter($filter);
$res = $db->select("Plz", "*", "$where ORDER BY gemeinde_id,plz LIMIT 1");
$res = $db->select("Plz", "*", "$where ORDER BY plz LIMIT 1");
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
$item = new ADBPlz($data);
@@ -58,7 +57,7 @@ class ADBPlzModel {
$db = FronkDB::singleton(ADDRESSDB_DBHOST, ADDRESSDB_DBUSER, ADDRESSDB_DBPASS, ADDRESSDB_DBNAME);
$res = $db->select("Plz", "*", "1=1 ORDER BY gemeinde_id,plz");
$res = $db->select("Plz", "*", "1=1 ORDER BY plz");
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new ADBPlz($data);
@@ -92,7 +91,7 @@ class ADBPlzModel {
$where = self::getSqlFilter($filter);
$sql = "SELECT Plz.* FROM Plz
WHERE $where
ORDER BY gemeinde_id,plz";
ORDER BY plz";
//mfLoghandler::singleton()->debug($sql);
if(is_array($limit) && count($limit)) {
@@ -116,13 +115,12 @@ class ADBPlzModel {
$where = "1=1 ";
if(array_key_exists("gemeinde_id", $filter)) {
$gemeinde_id = $filter['gemeinde_id'];
if(is_numeric($gemeinde_id)) {
$where .= " AND Plz.gemeinde_id=$gemeinde_id";
} elseif(is_array($gemeinde_id) && count($gemeinde_id)) {
$where .= " AND Plz.gemeinde_id IN (". implode(",", $gemeinde_id).")";
if(array_key_exists("hausnummer_id", $filter)) {
$hausnummer_id = $filter['hausnummer_id'];
if(is_numeric($hausnummer_id)) {
$where .= " AND Plz.hausnummer_id=$hausnummer_id";
} elseif(is_array($hausnummer_id) && count($hausnummer_id)) {
$where .= " AND Plz.hausnummer_id IN (". implode(",", $hausnummer_id).")";
}
}

View File

@@ -121,11 +121,11 @@ class AddressDB {
die("Error creating Ortschaft $ort_kz $ort_name!\n");
}
}
$plz = ADBPlzModel::getFirst(['gemeinde_id' => $gemeinde->id, 'plz' => $plz_name]);
$plz = ADBPlzModel::getFirst(['plz' => $plz_name]);
if(!$plz) {
$plz = new ADBPlz();
$plz->gemeinde_id = $gemeinde->id;
$plz->plz = $plz_name;
$plz->plzstring = $plz_name;
$plz_id = $plz->save();
@@ -133,8 +133,8 @@ class AddressDB {
die("Error creating Plz $plz_name!\n");
}
}
//var_dump($plz);exit;
$strasse = ADBStrasseModel::getFirst(['gemeinde_id' => $gemeinde->id, 'ortschaft_id' => $ort->id, 'name' => $strasse_name]);
if(!$strasse) {
@@ -147,12 +147,13 @@ class AddressDB {
die("error creating Strasse $strasse_name (gemeinde ".$gemeinde->id.", ort ".$ort->id.")");
}
}
//var_dump($strasse);exit;
$hausnummer = ADBHausnummerModel::getFirst(['strasse_id' => $strasse->id, 'hausnummer' => $hausnummer_name]);
if(!$hausnummer) {
$hausnummer = new ADBHausnummer();
$hausnummer->plz_id = $plz->id;
$hausnummer->strasse_id = $strasse->id;
$hausnummer->hausnummer = $hausnummer_name;
$hausnummer_id = $hausnummer->save();
@@ -161,6 +162,7 @@ class AddressDB {
}
}
//var_dump($hausnummer);exit;
$we_search = [
'hausnummer_id' => $hausnummer->id,

View File

@@ -12,12 +12,12 @@ class AddressdbApicontroller extends mfBaseApicontroller {
}
protected function findCity() {
$search = $this->db()->escape($this->post['search']);
$search = $this->db()->escape(trim($this->post['search']));
if(!$search) {
return mfResponse::BadRequest(['message' => "Searchstring cannot be empty!"]);
}
$results = ADBOrtschaftModel::search(['name%' => $search], ['count' => 20]);
$results = ADBOrtschaftModel::search(['name%' => $search]);
$cities = [];
@@ -25,17 +25,17 @@ class AddressdbApicontroller extends mfBaseApicontroller {
$cities[] = $result->name;
}
$citiesv= array_unique($cities);
return mfResponse::Ok(['cities' => $cities]);
$cities = array_unique($cities);
return mfResponse::Ok(['cities' => array_values($cities)]);
}
protected function findZip() {
$search = $this->db()->escape($this->post['search']);
$search = $this->db()->escape(trim($this->post['search']));
if(!$search) {
return mfResponse::BadRequest(['message' => "Searchstring cannot be empty!"]);
}
$results = ADBPlzModel::search(['plzstring%' => $search], ['count' => 20]);
$results = ADBPlzModel::search(['plzstring%' => $search]);
$zips = [];
@@ -44,16 +44,16 @@ class AddressdbApicontroller extends mfBaseApicontroller {
}
$zips = array_unique($zips);
return mfResponse::Ok(['zips' => $zips]);
return mfResponse::Ok(['zips' => array_values($zips)]);
}
protected function findStreet() {
$search = $this->db()->escape($this->post['search']);
$search = $this->db()->escape(trim($this->post['search']));
if(!$search) {
return mfResponse::BadRequest(['message' => "Searchstring cannot be empty!"]);
}
$results = ADBStrasseModel::search(['name%' => $search], ['count' => 20]);
$results = ADBStrasseModel::search(['name%' => $search]);
$streets = [];
@@ -62,14 +62,14 @@ class AddressdbApicontroller extends mfBaseApicontroller {
}
$streets = array_unique($streets);
return mfResponse::Ok(['streets' => $streets]);
return mfResponse::Ok(['streets' => array_values($streets)]);
}
protected function find() {
$search_street = $this->db()->escape($this->post['street']);
$search_zip = $this->db()->escape($this->post['zip']);
$search_city = $this->db()->escape($this->post['city']);
$search_housenumber = $this->db()->escape($this->post['housenumber']);
$search_street = $this->db()->escape(trim($this->post['street']));
$search_zip = $this->db()->escape(trim($this->post['zip']));
$search_city = $this->db()->escape(trim($this->post['city']));
$search_housenumber = $this->db()->escape(trim($this->post['housenumber']));
if(!$search_street) {
@@ -94,7 +94,7 @@ class AddressdbApicontroller extends mfBaseApicontroller {
}
//$res = $this->db()->select("view_wohneinheit_plz", "*", $where);
$sql = "SELECT * FROM view_wohneinheit WHERE $where ORDER BY plz, ortschaft, strasse, LENGTH(hausnummer), hausnummer, block, stiege, stock, LENGTH(tuer), tuer LIMIT 20";
$sql = "SELECT * FROM view_wohneinheit WHERE $where ORDER BY plz, ortschaft, strasse, LENGTH(hausnummer), hausnummer, block, stiege, stock, LENGTH(tuer), tuer";
//echo $sql;exit;
$res = $this->db()->query($sql);

View File

@@ -1,4 +1,4 @@
SetEnvIf Origin "(https://docs.breitband-steiermark.at|https://editor.swagger.io)$" AccessControlAllowOrigin=$0
SetEnvIf Origin "^(https://docs.thetool.xinon.at|https://editor.swagger.io|.*abstellgleis.at)$" AccessControlAllowOrigin=$0
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS"
Header add Access-Control-Allow-Headers: "X-Api-Key"

View File

@@ -0,0 +1,240 @@
openapi: 3.0.1
info:
title: thetool Preorder API
description: API Dokumentation für thetool Vorbestellung
contact:
name: thetool Development Team
email: thetool-api-support@xinon.at
license:
name: Apache 2.0 License
url: http://www.apache.org/licenses/LICENSE-2.0.html
version: 1.0.0
servers:
- url: https://thetool.xinon.at/api/v1
tags:
- name: addressdb
description: Abfrage von GWR Daten
paths:
/addressdb/findAddress:
post:
tags:
- addressdb
summary: Adressen suchen
description: Sucht nach Adressen
operationId: findAddresses
requestBody:
description: addressSearchRequest object. Parameter müssen mindestens 3 Zeichen lang sein, `zip` muss mindestens 2 Zeichen lang sein.
required: true
content:
'application/json':
schema:
$ref: '#/components/schemas/Address'
'application/x-www-form-urlencoded':
schema:
$ref: '#/components/schemas/Address'
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: object
properties:
status:
type: string
description: Status string
example: OK
result:
type: object
properties:
addresses:
$ref: '#/components/schemas/Addresses'
'400':
description: |
Bad Request
Parameter missing or malformed
'401':
description: Unauthorized
/addressdb/findStreet:
post:
tags:
- addressdb
summary: Straßen suchen
description: Sucht nach Straßen
operationId: findStreets
requestBody:
description: addressComponentSearchRequest object. Parameter `search` muss mindestens 3 Zeichen lang sein.
required: true
content:
'application/json':
schema:
$ref: '#/components/schemas/addressComponentSearchRequest'
'application/x-www-form-urlencoded':
schema:
$ref: '#/components/schemas/addressComponentSearchRequest'
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: object
properties:
status:
type: string
description: Status string
example: OK
result:
type: object
properties:
streets:
$ref: '#/components/schemas/Streets'
'400':
description: |
Bad Request
Parameter missing or malformed
'401':
description: Unauthorized
/addressdb/findZip:
post:
tags:
- addressdb
summary: Postleitzahlen suchen
description: Sucht nach Postleitzahlen
operationId: findZips
requestBody:
description: zipSearchRequest object. Parameter `search` muss mindestens 2 Zeichen lang sein.
required: true
content:
'application/json':
schema:
$ref: '#/components/schemas/zipComponentSearchRequest'
'application/x-www-form-urlencoded':
schema:
$ref: '#/components/schemas/zipComponentSearchRequest'
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: object
properties:
status:
type: string
description: Status string
example: OK
result:
type: object
properties:
streets:
$ref: '#/components/schemas/Zips'
'400':
description: |
Bad Request
Parameter missing or malformed
'401':
description: Unauthorized
/addressdb/findCity:
post:
tags:
- addressdb
summary: Ortschaften suchen
description: Sucht nach Ortschaften
operationId: findCity
requestBody:
description: addressComponentSearchRequest object. Parameter `search` muss mindestens 3 Zeichen lang sein.
required: true
content:
'application/json':
schema:
$ref: '#/components/schemas/addressComponentSearchRequest'
'application/x-www-form-urlencoded':
schema:
$ref: '#/components/schemas/addressComponentSearchRequest'
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: object
properties:
status:
type: string
description: Status string
example: OK
result:
type: object
properties:
streets:
$ref: '#/components/schemas/Cities'
'400':
description: |
Bad Request
Parameter missing or malformed
'401':
description: Unauthorized
components:
schemas:
addressComponentSearchRequest:
type: object
properties:
search:
type: string
description: Suchbegriff von mindestens 3 Zeichen Länge
minLength: 3
zipComponentSearchRequest:
type: object
properties:
search:
type: string
description: Suchbegriff von mindestens 2 Zeichen Länge
minLength: 2
Zips:
type: array
items:
type: string
Cities:
type: array
items:
type: string
Streets:
type: array
items:
type: string
Addresses:
type: array
items:
$ref: '#/components/schemas/Address'
Address:
type: object
properties:
street:
type: string
description: Straße
housenumber:
type: string
description: Hausnummer
zip:
type: string
description: PLZ
city:
type: string
description: Ortschaft
securitySchemes:
api_key_header:
type: apiKey
name: X-Api-Key
in: header
api_key_query:
type: apiKey
name: apikey
in: query
security:
- api_key_header: []
- api_key_query: []