Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| AppointmentCancelController | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| readResponse | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
6 | |||
| 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\AppointmentCancelService; |
| 10 | use BO\Zmscitizenapi\Services\Core\AuthenticationService; |
| 11 | use BO\Zmscitizenapi\Services\Core\ValidationService; |
| 12 | use Psr\Http\Message\RequestInterface; |
| 13 | use Psr\Http\Message\ResponseInterface; |
| 14 | |
| 15 | class AppointmentCancelController extends BaseController |
| 16 | { |
| 17 | private AppointmentCancelService $service; |
| 18 | public function __construct() |
| 19 | { |
| 20 | $this->service = new AppointmentCancelService(); |
| 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 | $authenticatedUser = AuthenticationService::getAuthenticatedUser($request); |
| 31 | $result = $this->service->processCancel($request->getParsedBody(), $authenticatedUser); |
| 32 | |
| 33 | if (is_array($result) && isset($result['errors'])) { |
| 34 | foreach ($result['errors'] as &$error) { |
| 35 | if (isset($error['errorCode'])) { |
| 36 | $error = ErrorMessages::get($error['errorCode']); |
| 37 | } |
| 38 | } |
| 39 | return $this->createJsonResponse($response, $result, ErrorMessages::getHighestStatusCode($result['errors'])); |
| 40 | } |
| 41 | |
| 42 | return $this->createJsonResponse($response, $result->toArray(), 200); |
| 43 | } |
| 44 | } |