Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.67% |
11 / 12 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| AppointmentReserveController | |
91.67% |
11 / 12 |
|
50.00% |
1 / 2 |
7.03 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| readResponse | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
6.04 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace BO\Zmscitizenapi\Controllers\Appointment; |
| 6 | |
| 7 | use BO\Zmscitizenapi\BaseController; |
| 8 | use BO\Zmscitizenapi\Controllers\UnpublishedAccessTrait; |
| 9 | use BO\Zmscitizenapi\Utils\ErrorMessages; |
| 10 | use BO\Zmscitizenapi\Services\Appointment\AppointmentReserveService; |
| 11 | use BO\Zmscitizenapi\Services\Core\ValidationService; |
| 12 | use Psr\Http\Message\RequestInterface; |
| 13 | use Psr\Http\Message\ResponseInterface; |
| 14 | |
| 15 | class AppointmentReserveController extends BaseController |
| 16 | { |
| 17 | use UnpublishedAccessTrait; |
| 18 | |
| 19 | private AppointmentReserveService $service; |
| 20 | |
| 21 | public function __construct() |
| 22 | { |
| 23 | $this->initializeUnpublishedAccess(); |
| 24 | $this->service = new AppointmentReserveService(); |
| 25 | } |
| 26 | |
| 27 | public function readResponse(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface |
| 28 | { |
| 29 | $requestErrors = ValidationService::validateServerPostRequest($request); |
| 30 | if (!empty($requestErrors['errors'])) { |
| 31 | return $this->createJsonResponse($response, $requestErrors, ErrorMessages::get('invalidRequest')['statusCode']); |
| 32 | } |
| 33 | |
| 34 | $result = $this->service->processReservation($request->getParsedBody(), $this->showUnpublished); |
| 35 | if (is_array($result) && isset($result['errors'])) { |
| 36 | foreach ($result['errors'] as &$error) { |
| 37 | if (isset($error['errorCode'])) { |
| 38 | $error = ErrorMessages::get($error['errorCode']); |
| 39 | } |
| 40 | } |
| 41 | return $this->createJsonResponse($response, $result, ErrorMessages::getHighestStatusCode($result['errors'])); |
| 42 | } |
| 43 | |
| 44 | return $this->createJsonResponse($response, $result->toArray(), 200); |
| 45 | } |
| 46 | } |