Skip to content

Commit

Permalink
feat(MPDZBS-877): zmscitizenapi cleanup (#740)
Browse files Browse the repository at this point in the history
* feat(MPDZB-877): Work on thinnedprocess typing

* feat(MPDZB): Refactor part 1

* feat(MPDZB): Refactor part 1

* feat(MPDZB-877): revert to processId in parameter

* feat(MPDZBS-877): refactor thinned process to object

* feat(MPDZB-877): refactor thinned process and rename controllers

* feat(MPDZBs-877): clean up more junk

---------

Co-authored-by: Tom Fink <thomasafink@Toms-MacBook-Air.local>
Co-authored-by: DDEV User <nobody@example.com>
Co-authored-by: Thomas Fink <thomasafink@Thomass-MacBook-Air.local>
  • Loading branch information
4 people authored Dec 16, 2024
1 parent cc0ad02 commit f98d01f
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 150 deletions.
1 change: 0 additions & 1 deletion zmscitizenapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "zmscitizenapi",
"version": "1.0.0",
"description": "This application offers a REST-like interface for ZMS functions and database access.",
"main": "index.js",
"private": true,
"scripts": {
"preinstall": "",
Expand Down
22 changes: 11 additions & 11 deletions zmscitizenapi/src/Zmscitizenapi/AppointmentReserve.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public function readResponse(RequestInterface $request, ResponseInterface $respo
}

$freeAppointments = new ProcessList();
$freeAppointments = ZmsApiFacadeService::getFreeAppointments([
'officeId' => $officeId,
'serviceIds' => $serviceIds,
'serviceCounts' => $serviceCounts,
'date' => UtilityHelper::getInternalDateFromTimestamp($timestamp)
]);
$freeAppointments = ZmsApiFacadeService::getFreeAppointments(
$officeId,
$serviceIds,
$serviceCounts,
UtilityHelper::getInternalDateFromTimestamp($timestamp)
);

$processArray = json_decode(json_encode($freeAppointments), true);

Expand Down Expand Up @@ -106,17 +106,17 @@ public function readResponse(RequestInterface $request, ResponseInterface $respo
}
}

$appointment = new ThinnedProcess();
$appointment = UtilityHelper::processToThinnedProcess($reservedProcess);
$thinnedProcess = new ThinnedProcess();
$thinnedProcess = UtilityHelper::processToThinnedProcess($reservedProcess);

$appointment = array_merge($appointment->toArray(), ['officeId' => $officeId]);
$thinnedProcess = array_merge($thinnedProcess->toArray(), ['officeId' => $officeId]);

return $this->createJsonResponse($response, $appointment, 200);
return $this->createJsonResponse($response, $thinnedProcess, 200);

} catch (\Exception $e) {
return $this->createJsonResponse($response, [
'errorCode' => 'internalServerError',
'errorMessage' => $e->getMessage()
'errorMessage' => 'An internal server error occurred'
], 500);
}
}
Expand Down
39 changes: 25 additions & 14 deletions zmscitizenapi/src/Zmscitizenapi/Helper/UtilityHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,27 @@ public static function uniqueElementsFilter($value, $index, $self): bool
return array_search($value, $self) === $index;
}

public static function getClientIp(): string
{
$headers = ['HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR'];
foreach ($headers as $header) {
if (isset($_SERVER[$header]) && filter_var($_SERVER[$header], FILTER_VALIDATE_IP)) {
return $_SERVER[$header];
}
}
return '127.0.0.1';
}

public static function processToThinnedProcess(Process $myProcess): ThinnedProcess
{
if (!$myProcess || !isset($myProcess->id)) {
return null;
}

$subRequestCounts = [];
$mainServiceId = null;
$mainServiceCount = 0;

$requests = $myProcess->requests ?? [];
if ($requests) {
$requests = is_array($requests) ? $requests : iterator_to_array($requests);
Expand Down Expand Up @@ -96,7 +107,7 @@ public static function processToThinnedProcess(Process $myProcess): ThinnedProce
$thinnedProcess->subRequestCounts = array_values($subRequestCounts);
$thinnedProcess->serviceId = $mainServiceId;
$thinnedProcess->serviceCount = $mainServiceCount;

return $thinnedProcess;
}

Expand All @@ -105,23 +116,23 @@ public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess):
if (!$thinnedProcess || !isset($thinnedProcess->processId)) {
return null;
}

$processEntity = new Process();
$processEntity->id = $thinnedProcess->processId;
$processEntity->authKey = $thinnedProcess->authKey ?? null;

$client = new Client();
$client->familyName = $thinnedProcess->familyName ?? null;
$client->email = $thinnedProcess->email ?? null;
$client->telephone = $thinnedProcess->telephone ?? null;
$client->customTextfield = $thinnedProcess->customTextfield ?? null;

$processEntity->clients = [$client];

$thinnedProcess = new Appointment();
$thinnedProcess->date = $thinnedProcess->timestamp ?? null;
$processEntity->appointments = [$thinnedProcess];

$scope = new Scope();
if (isset($thinnedProcess->officeName)) {
$scope->contact = new Contact();
Expand All @@ -133,11 +144,11 @@ public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess):
$scope->provider->source = \App::$source_name;
}
$processEntity->scope = $scope;

$mainServiceId = $thinnedProcess->serviceId ?? null;
$mainServiceCount = $thinnedProcess->serviceCount ?? 0;
$subRequestCounts = $thinnedProcess->subRequestCounts ?? [];

$requests = [];
for ($i = 0; $i < $mainServiceCount; $i++) {
$request = new Request();
Expand All @@ -154,13 +165,13 @@ public static function thinnedProcessToProcess(ThinnedProcess $thinnedProcess):
}
}
$processEntity->requests = $requests;

$processEntity->lastChange = time();
$processEntity->createIP = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1';
$processEntity->createIP = self::getClientIp();
$processEntity->createTimestamp = time();

return $processEntity;
}


}
8 changes: 1 addition & 7 deletions zmscitizenapi/src/Zmscitizenapi/Models/AppointmentCancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class AppointmentCancel extends Entity
{

public static $schema = "citizenapi/appointmentCancel.json";
public static $schema = "zmsentities/schema/citizenapi/appointmentCancel.json";

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class AppointmentConfirm extends Entity
{

public static $schema = "citizenapi/appointmentConfirm.json";
public static $schema = "zmsentities/schema/citizenapi/appointmentConfirm.json";

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class AppointmentPreConfirm extends Entity
{

public static $schema = "citizenapi/appointmentPreConfirm.json";
public static $schema = "zmsentities/schema/citizenapi/appointmentPreConfirm.json";

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class AppointmentReserve extends Entity
{

public static $schema = "citizenapi/appointmentReserve.json";
public static $schema = "zmsentities/schema/citizenapi/appointmentReserve.json";

}
8 changes: 1 addition & 7 deletions zmscitizenapi/src/Zmscitizenapi/Models/AppointmentUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class AppointmentUpdate extends Entity
{

public static $schema = "citizenapi/appointmentUpdate.json";
public static $schema = "zmsentities/schema/citizenapi/appointmentUpdate.json";

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class AvailableAppointments extends Entity
{

public static $schema = "citizenapi/availableAppointments.json";
public static $schema = "zmsentities/schema/citizenapi/availableAppointments.json";

}
8 changes: 1 addition & 7 deletions zmscitizenapi/src/Zmscitizenapi/Models/AvailableDays.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class AvailableDays extends Entity
{

public static $schema = "citizenapi/availableDays.json";
public static $schema = "zmsentities/schema/citizenapi/availableDays.json";

}
8 changes: 1 addition & 7 deletions zmscitizenapi/src/Zmscitizenapi/Models/CaptchaDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class CaptchaDetails extends Entity
{

public static $schema = "citizenapi/captchaDetails.json";
public static $schema = "zmsentities/schema/citizenapi/captchaDetails.json";

}
8 changes: 1 addition & 7 deletions zmscitizenapi/src/Zmscitizenapi/Models/Offices.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class Offices extends Entity
{

public static $schema = "citizenapi/offices.json";
public static $schema = "zmsentities/schema/citizenapi/offices.json";

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class OfficesAndServices extends Entity
{

public static $schema = "citizenapi/officesAndServices.json";
public static $schema = "zmsentities/schema/citizenapi/officesAndServices.json";

}
8 changes: 1 addition & 7 deletions zmscitizenapi/src/Zmscitizenapi/Models/OfficesByService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class OfficesByService extends Entity
{

public static $schema = "citizenapi/officesByService.json";
public static $schema = "zmsentities/schema/citizenapi/officesByService.json";

}
8 changes: 1 addition & 7 deletions zmscitizenapi/src/Zmscitizenapi/Models/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class Scope extends Entity
{

public static $schema = "citizenapi/scope.json";
public static $schema = "zmsentities/schema/citizenapi/scope.json";

}
8 changes: 1 addition & 7 deletions zmscitizenapi/src/Zmscitizenapi/Models/Scopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
use \BO\Zmsentities\Helper\Property;
use \BO\Zmsentities\Schema\Entity;

/**
* @SuppressWarnings(Complexity)
* @SuppressWarnings(Coupling)
* @SuppressWarnings(Public)
*
*/
class Scopes extends Entity
{

public static $schema = "citizenapi/scopes.json";
public static $schema = "zmsentities/schema/citizenapi/scopes.json";

}
Loading

0 comments on commit f98d01f

Please sign in to comment.