Merge branch 'fronkdev' into 'master'

Added API endpoint PUT /preorder/{id} to update contact data

See merge request fronk/thetool!1781
This commit is contained in:
Frank Schubert
2025-09-19 12:27:09 +00:00
4 changed files with 262 additions and 3 deletions

View File

@@ -599,8 +599,14 @@ $pagination_entity_name = "Vorbestellungen";
<span class="text-pink"><?=$preorder->oaid?></span>
</td>
<td>
<?=($preorder->company) ? $preorder->company : $preorder->firstname." ".$preorder->lastname?><br />
<?=$preorder->street?><?=($preorder->housenumber) ? " ".$preorder->housenumber : ""?><br />
<?=($preorder->company) ? $preorder->company."<br />" : ""?>
<?=($preorder->firstname || $preorder->lastname ) ? $preorder->firstname." ".$preorder->lastname."<br />" : ""?>
<?=$preorder->street?><?=($preorder->housenumber) ? " ".$preorder->housenumber : ""?>
<?=($preorder->block) ? "Block ".$preorder->block : ""?>
<?=($preorder->stiege) ? "Stiege ".$preorder->stiege : ""?>
<?=($preorder->stock) ? "Stock ".$preorder->stock : ""?>
<?=($preorder->tuer) ? "Tür ".$preorder->tuer : ""?>
<br />
<?=$preorder->zip?> <?=$preorder->city?>
</td>
<td>

View File

@@ -53,6 +53,7 @@ class PreorderApicontroller extends mfBaseApicontroller {
$this->addRoute("/preorder/:code/clientInstallationFinished", [$modules["Cif"], "providerSetCif"], "POST");
$this->addRoute("/preorder/:code/serviceActivated", [$modules["Activation"], "setServiceActive"], "POST");
$this->addRoute("/preorder/:code", "getPreorder", "GET");
$this->addRoute("/preorder/:code", "updatePreorder", "PUT");
$this->addRoute("/preorder/:code", "cancelPreorder", "DELETE");
@@ -331,6 +332,67 @@ class PreorderApicontroller extends mfBaseApicontroller {
}
protected function updatePreorder($code) {
$code = trim($code);
if(!$code) {
return mfResponse::NotFound(["message" => "Preorder not found"]);
}
$preorder = PreorderModel::getFirst(['ucode' => strtoupper($code), 'partner_id' => $this->me->address_id]);
if(!$preorder) {
// try as extref
$preorder = PreorderModel::getFirst(['extref' => $code, 'partner_id' => $this->me->address_id]);
}
if(!$preorder) {
// try oan id
$preorder = PreorderModel::getFirst(['oaid' => strtolower($code), 'partner_id' => $this->me->address_id], "`create` DESC");
}
if(!$preorder) {
return mfResponse::NotFound(["message" => "Preorder not found"]);
}
if($preorder->partner_id != $this->me->address_id) {
return mfResponse::NotFound(["message" => "Preorder not found"]);
}
$updates = [];
foreach(["contact_type","company","uid","firstname","lastname","street","housenumber","block","stock","stiege","tuer","unit_string","zip","city","phone","email"] as $type) {
if(array_key_exists($type, $this->post)) {
$updates[$type] = trim($this->post[$type]);
}
}
if(!count($updates)) {
return mfResponse::BadRequest(["message" => "No updates provided"]);
}
if(array_key_exists("contact_type", $updates)) {
if($updates["contact_type"] != "tenant" && $updates["contact_type"] != "owner") {
return mfResponse::BadRequest(["message" => "Invalid contact type. Must be 'owner' or 'tenant'"]);
}
}
$updates["edit_by"] = $this->me->id;
$preorder->update($updates);
// sanity checks
if(!$preorder->company && (!$preorder->firstname || !$preorder->lastname)) {
return mfResponse::BadRequest(["message" => "Cannot leave company or first- and lastname empty"]);
}
if(!$preorder->email) {
return mfResponse::BadRequest(["message" => "Cannot leave email empty"]);
}
if(!$preorder->save()) {
return mfResponse::InternalServerError();
}
return mfResponse::Ok(["message" => "Contact successfully updated"]);
}
protected function cancelPreorder($code) {
if($this->me->is("Preorderreadonly")) return \mfResponse::Forbidden();
/*

View File

@@ -185,7 +185,7 @@ class mfBaseApicontroller {
// POST Request
$post = [];
if($this->http_method == "POST") {
if($this->http_method == "POST" || $this->http_method == "PUT") {
$post = $this->getPostRequest();
if($post === false) {
$post = [];
@@ -234,6 +234,11 @@ class mfBaseApicontroller {
return $request_body;
}
if($this->http_method == "PUT") {
// PUT requests in application/x-www-form-urlencoded format need special handling
parse_str(file_get_contents("php://input"), $_POST);
}
// Request body is urlencoded or multipart-formdata
if(array_key_exists("CONTENT_TYPE", $_SERVER) && preg_match('#charset\s*=\s*["\']?([^ "\']+)["\']?\s*;?#i', $_SERVER["CONTENT_TYPE"], $m)) {
$request_charset = strtolower($m[1]);

View File

@@ -820,6 +820,192 @@ paths:
description: Unauthorized
'404':
description: Vorbestellung nicht gefunden
put:
tags:
- preorder
summary: Kontaktdaten bearbeiten
description: Zum Bearbeiten der Kontaktdaten einer Bestellung. Ein oder mehrere Parameter benötigt.
operationId: updatePreorderContact
parameters:
- name: id
in: path
description: Automatisch generierter **code** der Vorbestellung, **OAID** der Wohneinheit oder providereigene ID (**extref**)
required: true
schema:
type: string
requestBody:
description: zu ändernde Kontaktdaten
required: true
content:
'application/json':
schema:
type: object
description: Vertragsinhaber
properties:
type:
type: string
enum: [ "owner","tenant" ]
description: |
Ist diese Adresse Besitzer oder Bewohner der Wohneinheit. Optional, aber kann je nach Kampagne ein Pflichtfeld sein.
| type | Description |
|--------|-------------|
| owner | Ist Besitzer |
| tenant | Ist Bewohner|
company:
type: string
description: Firmenname Kunde
example:
uid:
type: string
description: UID (wenn Firmenkunde)
example:
firstname:
type: string
description: Vorname Kunde
example: Vor
lastname:
type: string
description: Nachname Kunde
example: Nachname
street:
type: string
description: Straße Kunde
example: Beispielstraße
housenumber:
type: string
description: Hausnummer Kunde
example: 42
zip:
type: string
description: PLZ Kunde
example: 9999
city:
type: string
description: Ort Kunde
example: Beispielhausen
block:
type: string
description: Adresszusatz
example: null
stiege:
type: string
description: Adresszusatz
example: null
stock:
type: string
description: Adresszusatz
example: null
tuer:
type: string
description: Adresszusatz
example: null
phone:
type: string
description: Telefonnummer Kunde
example: "01 1234 567 89"
email:
type: string
description: Emailadresse Kunde
example: this.email@does-not.exist
'application/x-www-form-urlencoded':
schema:
type: object
description: Vertragsinhaber
properties:
type:
type: string
enum: [ "owner","tenant" ]
description: |
Ist diese Adresse Besitzer oder Bewohner der Wohneinheit. Optional, aber kann je nach Kampagne ein Pflichtfeld sein.
| type | Description |
|--------|-------------|
| owner | Ist Besitzer |
| tenant | Ist Bewohner|
company:
type: string
description: Firmenname Kunde
example:
uid:
type: string
description: UID (wenn Firmenkunde)
example:
firstname:
type: string
description: Vorname Kunde
example: Vor
lastname:
type: string
description: Nachname Kunde
example: Nachname
street:
type: string
description: Straße Kunde
example: Beispielstraße
housenumber:
type: string
description: Hausnummer Kunde
example: 42
zip:
type: string
description: PLZ Kunde
example: 9999
city:
type: string
description: Ort Kunde
example: Beispielhausen
block:
type: string
description: Adresszusatz
example: null
stiege:
type: string
description: Adresszusatz
example: null
stock:
type: string
description: Adresszusatz
example: null
tuer:
type: string
description: Adresszusatz
example: null
phone:
type: string
description: Telefonnummer Kunde
example: "01 1234 567 89"
email:
type: string
description: Emailadresse Kunde
example: this.email@does-not.exist
responses:
'200':
description: Successful operation
content:
application/json:
schema:
type: object
properties:
status:
type: string
description: Status string
example: OK
result:
type: object
properties:
message:
type: string
description: Statustext
example: Contact successfully updated
'400':
description: Fehler in Eingabedaten
'401':
description: Api key fehlt oder ungültig
'403':
description: Keine Berechtigung
'404':
description: Bestellung nicht gefunden oder bereits storniert
delete:
tags:
- preorder