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 zmscitizenapi post reserve appointment and refactor #574

2 changes: 2 additions & 0 deletions zmscitizenapi/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// Set option for environment, routing, logging and templating
\BO\Slim\Bootstrap::init();

\App::$slim->addBodyParsingMiddleware();

\App::$http = new \BO\Zmsclient\Http(\App::ZMS_API_URL);
//\BO\Zmsclient\Psr7\Client::$curlopt = \App::$http_curl_config;

Expand Down
32 changes: 16 additions & 16 deletions zmscitizenapi/routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
\App::$slim->get(
'/services/',
'\BO\Zmscitizenapi\Controllers\ServicesList'
'\BO\Zmscitizenapi\ServicesList'
)
->setName("ServicesList");

Expand All @@ -48,7 +48,7 @@
*/
\App::$slim->get(
'/scopes/',
'\BO\Zmscitizenapi\Controllers\ScopesList'
'\BO\Zmscitizenapi\ScopesList'
)
->setName("ScopesList");

Expand All @@ -72,7 +72,7 @@
*/
\App::$slim->get(
'/offices/',
'\BO\Zmscitizenapi\Controllers\OfficesList'
'\BO\Zmscitizenapi\OfficesList'
)
->setName("OfficesList");

Expand All @@ -96,7 +96,7 @@
*/
\App::$slim->get(
'/offices-and-services/',
'\BO\Zmscitizenapi\Controllers\OfficesServicesRelations'
'\BO\Zmscitizenapi\OfficesServicesRelations'
)
->setName("OfficesServicesRelations");

Expand Down Expand Up @@ -128,7 +128,7 @@
*/
\App::$slim->get(
'/scope-by-id/',
'\BO\Zmscitizenapi\Controllers\ScopeByIdGet'
'\BO\Zmscitizenapi\ScopeByIdGet'
)
->setName("ScopeByIdGet");

Expand Down Expand Up @@ -158,7 +158,7 @@
*/
\App::$slim->get(
'/services-by-office/',
'\BO\Zmscitizenapi\Controllers\ServicesByOfficeList'
'\BO\Zmscitizenapi\ServicesByOfficeList'
)
->setName("ServicesByOfficeList");

Expand Down Expand Up @@ -188,7 +188,7 @@
*/
\App::$slim->get(
'/offices-by-service/',
'\BO\Zmscitizenapi\Controllers\OfficesByServiceList'
'\BO\Zmscitizenapi\OfficesByServiceList'
)
->setName("OfficesByServiceList");

Expand Down Expand Up @@ -223,7 +223,7 @@
*/
\App::$slim->get(
'/available-days/',
'\BO\Zmscitizenapi\Controllers\AvailableDaysList'
'\BO\Zmscitizenapi\AvailableDaysList'
)
->setName("AvailableDaysList");

Expand Down Expand Up @@ -263,7 +263,7 @@
*/
\App::$slim->get(
'/available-appointments/',
'\BO\Zmscitizenapi\Controllers\AvailableAppointmentsList'
'\BO\Zmscitizenapi\AvailableAppointmentsList'
)
->setName("AvailableAppointmentsList");

Expand Down Expand Up @@ -318,7 +318,7 @@
*/
\App::$slim->get(
'/appointment/',
'\BO\Zmscitizenapi\Controllers\AppointmentGet'
'\BO\Zmscitizenapi\AppointmentGet'
)
->setName("AppointmentGet");

Expand All @@ -342,7 +342,7 @@
*/
\App::$slim->get(
'/captcha-details/',
'\BO\Zmscitizenapi\Controllers\CaptchaGet'
'\BO\Zmscitizenapi\CaptchaGet'
)
->setName("CaptchaGet");

Expand Down Expand Up @@ -393,7 +393,7 @@
*/
\App::$slim->post(
'/reserve-appointment/',
'\BO\Zmscitizenapi\Controllers\AppointmentReserve'
'\BO\Zmscitizenapi\AppointmentReserve'
)
->setName("AppointmentReserve");

Expand Down Expand Up @@ -444,7 +444,7 @@
*/
\App::$slim->post(
'/update-appointment/',
'\BO\Zmscitizenapi\Controllers\AppointmentUpdate'
'\BO\Zmscitizenapi\AppointmentUpdate'
)
->setName("AppointmentUpdate");

Expand Down Expand Up @@ -495,7 +495,7 @@
*/
\App::$slim->post(
'/confirm-appointment/',
'\BO\Zmscitizenapi\Controllers\AppointmentConfirm'
'\BO\Zmscitizenapi\AppointmentConfirm'
)
->setName("AppointmentConfirm");

Expand Down Expand Up @@ -546,7 +546,7 @@
*/
\App::$slim->post(
'/preconfirm-appointment/',
'\BO\Zmscitizenapi\Controllers\AppointmentPreconfirm'
'\BO\Zmscitizenapi\AppointmentPreconfirm'
)
->setName("AppointmentPreconfirm");

Expand Down Expand Up @@ -597,6 +597,6 @@
*/
\App::$slim->post(
'/cancel-appointment/',
'\BO\Zmscitizenapi\Controllers\AppointmentCancel'
'\BO\Zmscitizenapi\AppointmentCancel'
)
->setName("AppointmentCancel");
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace BO\Zmscitizenapi\Controllers;
namespace BO\Zmscitizenapi;

use BO\Zmscitizenapi\BaseController;
use BO\Slim\Render;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace BO\Zmscitizenapi\Controllers;
namespace BO\Zmscitizenapi;

use BO\Zmscitizenapi\BaseController;
use BO\Slim\Render;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
<?php

namespace BO\Zmscitizenapi\Controllers;
namespace BO\Zmscitizenapi;

use BO\Zmscitizenapi\BaseController;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use BO\Zmscitizenapi\Services\AppointmentService;
use BO\Zmscitizenapi\Services\ProcessService;
use BO\Zmscitizenapi\Services\ZmsApiFacadeService;

class AppointmentGet extends BaseController
{
protected $appointmentService;

public function __construct()
{
$processService = new ProcessService(\App::$http);
$this->appointmentService = new AppointmentService($processService);
}

public function readResponse(RequestInterface $request, ResponseInterface $response, array $args)
{
$queryParams = $request->getQueryParams();
$processId = $queryParams['processId'] ?? null;
$authKey = $queryParams['authKey'] ?? null;

$result = $this->appointmentService->getAppointmentById($processId, $authKey);
$result = ZmsApiFacadeService::getProcessById($processId, $authKey);

return $this->createJsonResponse($response, $result['data'] ?? $result, $result['status']);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace BO\Zmscitizenapi\Controllers;
namespace BO\Zmscitizenapi;

use BO\Zmscitizenapi\BaseController;
use BO\Slim\Render;
Expand Down
110 changes: 110 additions & 0 deletions zmscitizenapi/src/Zmscitizenapi/AppointmentReserve.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace BO\Zmscitizenapi;

use BO\Zmscitizenapi\Application;
use BO\Zmscitizenapi\BaseController;
use BO\Zmscitizenapi\Helper\UtilityHelper;
use BO\Zmscitizenapi\Services\CaptchaService;
use BO\Zmscitizenapi\Services\MapperService;
use BO\Zmscitizenapi\Services\ValidationService;
use BO\Zmscitizenapi\Services\ZmsApiFacadeService;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

class AppointmentReserve extends BaseController
{


public function readResponse(RequestInterface $request, ResponseInterface $response, array $args)
{
$request = $request instanceof ServerRequestInterface ? $request : null;

$body = $request->getParsedBody();

$officeId = $body['officeId'] ?? null;
$serviceIds = $body['serviceId'] ?? [];
$serviceCounts = $body['serviceCount'] ?? [1];
$captchaSolution = $body['captchaSolution'] ?? null;
$timestamp = $body['timestamp'] ?? null;


$errors = ValidationService::validatePostAppointmentReserve($officeId, $serviceIds, $serviceCounts, $captchaSolution, $timestamp);
if (!empty($errors['errors'])) {
return $this->createJsonResponse($response,
$errors, 400);
}

try {
$providerScope = ZmsApiFacadeService::getScopeByOfficeId($officeId);
$captchaRequired = Application::$CAPTCHA_ENABLED === "1" && $providerScope['captchaActivatedRequired'] === "1";

if ($captchaRequired) {
$captchaVerificationResult = CaptchaService::verifyCaptcha($captchaSolution);
if (!$captchaVerificationResult['success']) {
return $this->createJsonResponse($response, [
'errorCode' => 'captchaVerificationFailed',
'errorMessage' => 'Captcha verification failed'
], 400);
}
}

$serviceValidationResult = ValidationService::validateServiceLocationCombination($officeId, $serviceIds);
if ($serviceValidationResult['status'] !== 200) {
return $this->createJsonResponse($response, $serviceValidationResult, 400);
}

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

$selectedProcess = array_filter($freeAppointments, function ($process) use ($timestamp) {
if (!isset($process['appointments']) || !is_array($process['appointments'])) {
return false;
}
return in_array($timestamp, array_column($process['appointments'], 'date'));
});

$errors = ValidationService::validateGetProcessNotFound($selectedProcess);
if (!empty($errors['errors'])) {
return $this->createJsonResponse($response,
$errors, 404);
}

$selectedProcess = array_values($selectedProcess)[0];
$selectedProcess['clients'] = [
[
'email' => 'test@muenchen.de'
]
];

$reservedProcess = ZmsApiFacadeService::reserveTimeslot($selectedProcess, $serviceIds, $serviceCounts);

if ($reservedProcess && $reservedProcess->scope && $reservedProcess->scope->id) {
$scopeIds = [$reservedProcess->scope->id];
$scopesData = ZmsApiFacadeService::getScopeByIds($scopeIds);

if ($scopesData['status'] === 200 && isset($scopesData['scopes']['scopes']) && !empty($scopesData['scopes']['scopes'])) {
$reservedProcess->scope = MapperService::mapScope($scopesData['scopes']['scopes'][0]);
}
}

$thinnedProcessData = UtilityHelper::getThinnedProcessData($reservedProcess);
$thinnedProcessData = array_merge($thinnedProcessData, ['officeId' => $officeId]);

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

} catch (\Exception $e) {
return [
'errorCode' => 'unexpectedError',
'errorMessage' => 'Unexpected error: ' . $e->getMessage(),
'status' => 500,
];
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace BO\Zmscitizenapi\Controllers;
namespace BO\Zmscitizenapi;

use BO\Zmscitizenapi\BaseController;
use BO\Slim\Render;
Expand Down
21 changes: 21 additions & 0 deletions zmscitizenapi/src/Zmscitizenapi/AvailableAppointmentsList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace BO\Zmscitizenapi;

use BO\Zmscitizenapi\BaseController;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use BO\Zmscitizenapi\Services\ZmsApiFacadeService;

class AvailableAppointmentsList extends BaseController
{
public function readResponse(RequestInterface $request, ResponseInterface $response, array $args)
{
$queryParams = $request->getQueryParams();

$result = ZmsApiFacadeService::getAvailableAppointments($queryParams);

return $this->createJsonResponse($response, $result, statusCode: $result['status']);
}

}
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
<?php

namespace BO\Zmscitizenapi\Controllers;
namespace BO\Zmscitizenapi;

use BO\Zmscitizenapi\BaseController;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use BO\Zmscitizenapi\Services\AvailableDaysService;
use BO\Zmscitizenapi\Services\ZmsApiFacadeService;

class AvailableDaysList extends BaseController
{
protected $availableDaysService;

public function __construct()
{
$this->availableDaysService = new AvailableDaysService();
}

public function readResponse(RequestInterface $request, ResponseInterface $response, array $args)
{
$queryParams = $request->getQueryParams();

$result = $this->availableDaysService->getAvailableDays($queryParams);
$result = ZmsApiFacadeService::getBookableFreeDays($queryParams);

return $this->createJsonResponse($response, $result, $result['status']);
}
Expand Down
Loading
Loading