Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
87.50% |
7 / 8 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
AppointmentByIdController | |
87.50% |
7 / 8 |
|
50.00% |
1 / 2 |
5.05 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
readResponse | |
85.71% |
6 / 7 |
|
0.00% |
0 / 1 |
4.05 |
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\Localization\ErrorMessages; |
9 | use BO\Zmscitizenapi\Services\Appointment\AppointmentByIdService; |
10 | use BO\Zmscitizenapi\Services\Core\ValidationService; |
11 | use Psr\Http\Message\RequestInterface; |
12 | use Psr\Http\Message\ResponseInterface; |
13 | |
14 | class AppointmentByIdController extends BaseController |
15 | { |
16 | private AppointmentByIdService $service; |
17 | public function __construct() |
18 | { |
19 | $this->service = new AppointmentByIdService(); |
20 | } |
21 | |
22 | // AppointmentByIdController.php |
23 | public function readResponse(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface |
24 | { |
25 | |
26 | $requestErrors = ValidationService::validateServerGetRequest($request); |
27 | if (!empty($requestErrors['errors'])) { |
28 | return $this->createJsonResponse($response, $requestErrors, ErrorMessages::get('invalidRequest', $this->language)['statusCode']); |
29 | } |
30 | |
31 | $result = $this->service->getAppointmentById($request->getQueryParams()); |
32 | return is_array($result) && isset($result['errors']) |
33 | ? $this->createJsonResponse($response, $result, ErrorMessages::getHighestStatusCode($result['errors'])) |
34 | : $this->createJsonResponse($response, $result->toArray(), 200); |
35 | } |
36 | } |