Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature mpdzbs 887 zms 2518 zmscitizenapi post update appointment #587

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ RewriteRule ^terminvereinbarung/calldisplay(.*) /var/www/html/zmscalldisplay/pub
RewriteRule ^terminvereinbarung/calldisplay/+_(.*) /var/www/html/zmscalldisplay/public/_$1 [QSA]


# zmscitizenapi
SetEnvIf Request_URI ^/zmscitizenapi ZMS_MODULE_BASEPATH=/terminvereinbarung/api/citizen
RewriteCond %{REQUEST_URI} !^/terminvereinbarung/api/citizen/+(_|doc)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^terminvereinbarung/api/citizen(.*) /var/www/html/zmscitizenapi/public/index.php?$1 [QSA]
RewriteRule ^terminvereinbarung/api/citizen/+(doc|_)(.*) /var/www/html/zmscitizenapi/public/$1$2 [QSA]


# zmsstatistic
SetEnvIf Request_URI ^/zmsstatistic ZMS_MODULE_BASEPATH=/terminvereinbarung/statistic
RewriteCond %{REQUEST_URI} !^/terminvereinbarung/[^/]+/+_
Expand Down
52 changes: 49 additions & 3 deletions zmscitizenapi/src/Zmscitizenapi/AppointmentUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,60 @@
namespace BO\Zmscitizenapi;

use BO\Zmscitizenapi\BaseController;
use BO\Slim\Render;
use BO\Zmscitizenapi\Services\ZmsApiFacadeService;
use BO\Zmscitizenapi\Services\ValidationService;
use BO\Zmscitizenapi\Helper\UtilityHelper;
use BO\Zmscitizenapi\Services\ExceptionService;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

class AppointmentUpdate extends BaseController
{
public function readResponse(RequestInterface $request, ResponseInterface $response, array $args)
{
return Render::withJson($response, []);
$request = $request instanceof ServerRequestInterface ? $request : null;

$body = $request->getParsedBody();
$processId = $body['processId'] ?? null;
$authKey = $body['authKey'] ?? null;
$familyName = $body['familyName'] ?? null;
$email = $body['email'] ?? null;
$telephone = $body['telephone'] ?? null;
$customTextfield = $body['customTextfield'] ?? null;

$errors = ValidationService::validateUpdateAppointmentInputs($processId, $authKey, $familyName, $email, $telephone, $customTextfield);
if (!empty($errors['errors'])) {
return $this->createJsonResponse($response, $errors, 400);
}

try {

$reservedProcess = ZmsApiFacadeService::getProcessById($processId, $authKey);
if (!empty($reservedProcess['errors'])) {
return $this->createJsonResponse($response, $reservedProcess, 404);
}

$reservedProcess['clients'][0]['familyName'] = $familyName;
$reservedProcess['clients'][0]['email'] = $email;
$reservedProcess['clients'][0]['telephone'] = $telephone;
$reservedProcess['customTextfield'] = $customTextfield;

$updatedProcess = ZmsApiFacadeService::updateClientData($reservedProcess);

if (isset($updatedProcess['exception']) && $updatedProcess['exception'] === 'tooManyAppointmentsWithSameMail') {
return $this->createJsonResponse($response, ExceptionService::tooManyAppointmentsWithSameMail(), 406);
}

$thinnedProcessData = UtilityHelper::getThinnedProcessData($updatedProcess);
return $this->createJsonResponse($response, $thinnedProcessData, 200);

} catch (\Exception $e) {
return [
'errorCode' => 'unexpectedError',
'errorMessage' => 'Unexpected error: ' . $e->getMessage(),
'status' => 500,
];
}
}
}
}
25 changes: 24 additions & 1 deletion zmscitizenapi/src/Zmscitizenapi/Services/ExceptionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class ExceptionService
{

public static function exceptionNoAppointmentsAtLocation(){
public static function noAppointmentsAtLocation(){

$errors[] = [
'errorCode' => 'noAppointmentForThisOffice',
Expand All @@ -17,4 +17,27 @@ public static function exceptionNoAppointmentsAtLocation(){

}

public static function appointmentNotFound(){

$errors[] = [
'errorCode' => 'appointmentNotFound',
'errorMessage' => 'Termin wurde nicht gefunden.',
'status' => 404,
];

return ['errors' => $errors, 'status' => 404];

}

public static function tooManyAppointmentsWithSameMail(){
$errors[] = [
'errorCode' => 'tooManyAppointmentsWithSameMail',
'errorMessage' => 'Zu viele Termine mit gleicher E-Mail- Adresse.',
'status' => 406,
];

return ['errors' => $errors, 'status' => 406];

}

}
79 changes: 68 additions & 11 deletions zmscitizenapi/src/Zmscitizenapi/Services/ValidationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,28 @@ public static function validateGetAvailableAppointments($date, $officeId, $servi
'errorMessage' => 'date is required and must be a valid date.',
];
}

if (!$officeId || !is_numeric($officeId)) {
$errors[] = [
'status' => 400,
'errorMessage' => 'officeId should be a 32-bit integer.',
];
}

if (empty($serviceIds[0]) || !preg_match('/^\d+(,\d+)*$/', implode(',', $serviceIds))) {
$errors[] = [
'status' => 400,
'errorMessage' => 'serviceId should be a comma-separated string of integers.',
];
}

if (empty($serviceCounts[0]) || !preg_match('/^\d+(,\d+)*$/', implode(',', $serviceCounts))) {
$errors[] = [
'status' => 400,
'errorMessage' => 'serviceCount should be a comma-separated string of integers.',
];
}

return ['errors' => $errors, 'status' => 400];
}
public static function validatePostAppointmentReserve($officeId, $serviceIds, $serviceCounts, $captchaSolution, $timestamp)
Expand Down Expand Up @@ -184,7 +184,8 @@ public static function validateGetScopeByIds($scopeIds)
return ['errors' => $errors, 'status' => 400];
}

public static function validateGetServicesByOfficeIds($officeIds){
public static function validateGetServicesByOfficeIds($officeIds)
{

$errors = [];
if (empty($officeIds) || $officeIds == ['']) {
Expand Down Expand Up @@ -234,7 +235,7 @@ public static function validateGetProcessNotFound($process)
if (!$process) {
$errors[] = [
'errorCode' => 'appointmentNotAvailable',
'errorMessage' => 'Der von Ihnen gewählte Termin ist leider nicht mehr verfügbar.',
'errorMessage' => 'Der von Ihnen gewählte Termin ist leider nicht mehr verfügbar.',
'status' => 404,
];
}
Expand All @@ -248,7 +249,7 @@ public static function validateScopesNotFound($scopes)
if (empty($scopes)) {
$errors[] = [
'errorCode' => 'scopesNotFound',
'errorMessage' => 'Scope(s) not found.',
'errorMessage' => 'Scope(s) not found.',
'status' => 404,
];
}
Expand All @@ -262,7 +263,7 @@ public static function validateServicesNotFound($services)
if (empty($services)) {
$errors[] = [
'errorCode' => 'servicesNotFound',
'errorMessage' => 'Service(s) not found for the provided officeId(s).',
'errorMessage' => 'Service(s) not found for the provided officeId(s).',
'status' => 404,
];
}
Expand All @@ -276,7 +277,7 @@ public static function validateOfficesNotFound($offices)
if (empty($offices)) {
$errors[] = [
'errorCode' => 'officesNotFound',
'errorMessage' => 'Office(s) not found for the provided serviceId(s).',
'errorMessage' => 'Office(s) not found for the provided serviceId(s).',
'status' => 404,
];
}
Expand All @@ -298,7 +299,8 @@ public static function validateAppointmentDaysNotFound($formattedDays)
return ['errors' => $errors, 'status' => 404];
}

public static function validateNoAppointmentsAtLocation(){
public static function validateNoAppointmentsAtLocation()
{

$errors[] = [
'errorCode' => 'noAppointmentForThisScope',
Expand All @@ -310,4 +312,59 @@ public static function validateNoAppointmentsAtLocation(){

}

}
public static function validateUpdateAppointmentInputs($processId, $authKey, $familyName, $email, $telephone, $customTextfield)
{
$errors = [];

if (!$processId || !is_numeric($processId) || intval($processId) <= 0) {
$errors[] = [
'status' => 400,
'errorMessage' => 'processId should be a positive 32-bit integer.',
];
}

if (!$authKey || !is_string($authKey)) {
$errors[] = [
'status' => 400,
'errorMessage' => 'authKey should be a non-empty string.',
];
}

if (!$familyName || !is_string($familyName)) {
$errors[] = [
'status' => 400,
'errorMessage' => 'familyName should be a non-empty string.',
];
}

if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = [
'status' => 400,
'errorMessage' => 'email should be a valid email address.',
];
}

if ($telephone !== null && !$telephone || !preg_match('/^\d{7,15}$/', $telephone)) {
$errors[] = [
'status' => 400,
'errorMessage' => 'telephone should be a numeric string between 7 and 15 digits.',
];
}

if ($customTextfield !== null && !is_string($customTextfield)) {
$errors[] = [
'status' => 400,
'errorMessage' => 'customTextfield should be a string.',
];
}

if (!empty($errors)) {
return ['errors' => $errors, 'status' => 400];
}

return ['status' => 200, 'message' => 'Valid input for updating appointment.'];
}


}

55 changes: 42 additions & 13 deletions zmscitizenapi/src/Zmscitizenapi/Services/ZmsApiClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static function getServices()

}

public static function getRequestRelationList(){
public static function getRequestRelationList()
{

$sources = \App::$http->readGetResult('/source/' . \App::$source_name . '/', [
'resolveReferences' => 2,
Expand Down Expand Up @@ -89,15 +90,14 @@ public static function getFreeTimeslots($providers, $requests, $firstDay, $lastD
}

$psr7Response = $result->getResponse();
$responseBody = (string) $psr7Response->getBody();


return $result;
}

public static function reserveTimeslot($appointmentProcess, $serviceIds, $serviceCounts)
{
$requests = [];

foreach ($serviceIds as $index => $serviceId) {
$count = intval($serviceCounts[$index]);
for ($i = 0; $i < $count; $i++) {
Expand All @@ -109,32 +109,61 @@ public static function reserveTimeslot($appointmentProcess, $serviceIds, $servic
}

$processEntity = new ProcessEntity();

$processEntity->appointments = $appointmentProcess['appointments'] ?? [];
$processEntity->authKey = $appointmentProcess['authKey'] ?? null;
$processEntity->clients = $appointmentProcess['clients'] ?? [];

$processEntity->scope = $appointmentProcess['scope'] ?? null;
$processEntity->requests = $requests;
$processEntity->lastChange = $appointmentProcess['lastChange'] ?? time();


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

if (isset($appointmentProcess['queue'])) {
$processEntity->queue = $appointmentProcess['queue'];
}

$result = \App::$http->readPostResult('/process/status/reserved/', $processEntity);

return $result->getEntity();
}

public function submitClientData($process)
public static function submitClientData($process)
{
$url = "/process/{$process['id']}/{$process['authKey']}/";
return \App::$http->readPostResult($url, $process)->getEntity();
$processEntity = new ProcessEntity();
$processEntity->id = $process['data']['processId'] ?? null;
$processEntity->authKey = $process['data']['authKey'] ?? null;
$processEntity->appointments = $process['appointments'] ?? [];
$processEntity->clients = $process['clients'] ?? [];
$processEntity->scope = $process['data']['scope'] ?? null;
$processEntity->customTextfield = $process['customTextfield'] ?? null;
$processEntity->lastChange = $process['lastChange'] ?? time();

if (isset($process['queue'])) {
$processEntity->queue = $process['queue'];
}

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

$url = "/process/{$processEntity->id}/{$processEntity->authKey}/";

try {
$result = \App::$http->readPostResult($url, $processEntity);
return $result->getEntity();
} catch (\Exception $e) {
$exceptionName = json_decode(json_encode($e), true)['template'] ?? null;
if ($exceptionName === 'BO\\Zmsapi\\Exception\\Process\\MoreThanAllowedAppointmentsPerMail') {
$exception = [
'exception' => 'tooManyAppointmentsWithSameMail'
];
return $exception;
}
}

}

public function preconfirmProcess($process)
Expand Down
Loading
Loading