Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.55% |
28 / 29 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| CalendarAvailabilityGet | |
96.55% |
28 / 29 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| readResponse | |
96.55% |
28 / 29 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @package ZMS API |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
| 6 | **/ |
| 7 | |
| 8 | namespace BO\Zmsbackend\Calendar\Api; |
| 9 | |
| 10 | use BO\Slim\Render; |
| 11 | use BO\Mellon\Validator; |
| 12 | use BO\Zmsbackend\Calendar\Service\CalendarAvailability; |
| 13 | use BO\Zmsbackend\Slot\Exception\Calendar\InvalidAvailabilityInput; |
| 14 | |
| 15 | /** |
| 16 | * Combined calendar availability endpoint used only by zmscitizenapi. |
| 17 | */ |
| 18 | class CalendarAvailabilityGet extends \BO\Zmsbackend\Api\BaseController |
| 19 | { |
| 20 | /** |
| 21 | * @SuppressWarnings(Param) |
| 22 | * @return \Psr\Http\Message\ResponseInterface |
| 23 | */ |
| 24 | #[\Override] |
| 25 | public function readResponse( |
| 26 | \Psr\Http\Message\RequestInterface $request, |
| 27 | \Psr\Http\Message\ResponseInterface $response, |
| 28 | array $args |
| 29 | ) { |
| 30 | $slotsRequired = Validator::param('slotsRequired')->isNumber()->getValue(); |
| 31 | $slotType = Validator::param('slotType')->isString()->getValue(); |
| 32 | if ($slotType || $slotsRequired) { |
| 33 | (new \BO\Zmsbackend\Helper\User($request))->checkPermissions(); |
| 34 | } else { |
| 35 | $slotsRequired = 0; |
| 36 | $slotType = 'public'; |
| 37 | } |
| 38 | |
| 39 | try { |
| 40 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); |
| 41 | $message->data = (new CalendarAvailability())->readFromQuery( |
| 42 | \App::getNow(), |
| 43 | $slotType, |
| 44 | $slotsRequired, |
| 45 | Validator::param('startDate')->isString()->getValue(), |
| 46 | Validator::param('endDate')->isString()->getValue(), |
| 47 | Validator::param('officeIds')->isString()->getValue(), |
| 48 | Validator::param('serviceIds')->isString()->getValue(), |
| 49 | Validator::param('serviceCounts')->isString()->setDefault('')->getValue(), |
| 50 | Validator::param('providerSource')->isString()->getValue() ?: null, |
| 51 | Validator::param('requestSource')->isString()->getValue() ?: null, |
| 52 | Validator::param('slotsStartDate')->isString()->getValue(), |
| 53 | Validator::param('slotsEndDate')->isString()->getValue() |
| 54 | ); |
| 55 | } catch (InvalidAvailabilityInput $exception) { |
| 56 | throw new \BO\Zmsbackend\Calendar\Exception\InvalidFirstDay( |
| 57 | $exception->getMessage(), |
| 58 | 0, |
| 59 | $exception |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | $response = Render::withLastModified($response, time(), '0'); |
| 64 | return Render::withJson($response, $message->setUpdatedMetaData(), 200); |
| 65 | } |
| 66 | } |