Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
96.67% covered (success)
96.67%
29 / 30
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
CalendarAvailabilityGet
96.67% covered (success)
96.67%
29 / 30
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 readResponse
96.67% covered (success)
96.67%
29 / 30
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * @package ZMS API
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsbackend\Calendar\Api;
9
10use BO\Slim\Render;
11use BO\Mellon\Validator;
12use BO\Zmsbackend\Calendar\Service\CalendarAvailability;
13use BO\Zmsbackend\Slot\Exception\Calendar\InvalidAvailabilityInput;
14
15/**
16 * Combined calendar availability endpoint used only by zmscitizenapi.
17 */
18class 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        $slotsRequired = (int) ($slotsRequired ?? 0);
39
40        try {
41            $message = \BO\Zmsbackend\Api\Response\Message::create($request);
42            $message->data = (new CalendarAvailability())->readFromQuery(
43                \App::getNow(),
44                $slotType,
45                $slotsRequired,
46                Validator::param('startDate')->isString()->getValue(),
47                Validator::param('endDate')->isString()->getValue(),
48                Validator::param('officeIds')->isString()->getValue(),
49                Validator::param('serviceIds')->isString()->getValue(),
50                Validator::param('serviceCounts')->isString()->setDefault('')->getValue(),
51                Validator::param('providerSource')->isString()->getValue() ?: null,
52                Validator::param('requestSource')->isString()->getValue() ?: null,
53                Validator::param('slotsStartDate')->isString()->getValue(),
54                Validator::param('slotsEndDate')->isString()->getValue()
55            );
56        } catch (InvalidAvailabilityInput $exception) {
57            throw new \BO\Zmsbackend\Calendar\Exception\InvalidFirstDay(
58                $exception->getMessage(),
59                0,
60                $exception
61            );
62        }
63
64        $response = Render::withLastModified($response, time(), '0');
65        return Render::withJson($response, $message->setUpdatedMetaData(), 200);
66    }
67}