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