Lines
100.00%
9 / 9
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| MyAppointmentsController | 100.00% | 9 / 9 | 100.00% | 2 / 2 | 3 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| readResponse | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace BO\Zmscitizenapi\Controllers\Appointment; | |
| 6 | ||
| 7 | use BO\Mellon\Validator; | |
| 8 | use BO\Zmscitizenapi\BaseController; | |
| 9 | use BO\Zmscitizenapi\Services\Core\AuthenticationService; | |
| 10 | use BO\Zmscitizenapi\Services\Appointment\MyAppointmentsService; | |
| 11 | use BO\Zmscitizenapi\Utils\ErrorMessages; | |
| 12 | use Psr\Http\Message\RequestInterface; | |
| 13 | use Psr\Http\Message\ResponseInterface; | |
| 14 | ||
| 15 | class MyAppointmentsController extends BaseController | |
| 16 | { | |
| 17 | private MyAppointmentsService $service; | |
| 18 | /** @psalm-api */ | |
| 19 | public function __construct() | |
| 20 | { | |
| 21 | $this->service = new MyAppointmentsService(); | |
| 22 | } | |
| 23 | ||
| 24 | #[\Override] | |
| 25 | public function readResponse(RequestInterface $request, ResponseInterface $response, array $args): ResponseInterface | |
| 26 | { | |
| 27 | $filterId = Validator::param('filterId')->isNumber()->getValue(); | |
| 28 | $user = AuthenticationService::getAuthenticatedUser($request); | |
| 29 | if (is_null($user)) { | |
| 30 | return $this->createJsonResponse($response, [ | |
| 31 | 'errors' => [ErrorMessages::get('authKeyMismatch')] | |
| 32 | ], 401); | |
| 33 | } | |
| 34 | $result = $this->service->getAppointmentsForUser($user, $filterId); | |
| 35 | return $this->createJsonResponse($response, $result, 200); | |
| 36 | } | |
| 37 | } |