OverridesGet.php 1.06 KB
Newer Older
1
2
<?php

3
namespace Source\UseCases\Overrides\OverridesGet;
4

5
use Source\Sanitize\CastsTo;
6
7
8
9
use Source\UseCases\Overrides\Presenter;
use Source\UseCases\Overrides\ResponseModel;
use Source\Gateways\Overrides\OverridesRepository;

10
class OverridesGet implements OverridesGetUseCase
11
{
12
13
    use CastsTo;

14
15
16
17
18
19
20
21
22
23
24
25
26
    /**
     * @var \Source\Gateways\Overrides\OverridesRepository
     */
    protected OverridesRepository $overrides;

    public function __construct(OverridesRepository $overrides)
    {
        $this->overrides = $overrides;
    }

    /**
     * @inheritDoc
     */
27
    public function filter(?string $doorId, ?string $userId, ?string $start, ?string $end, Presenter $presenter): void
28
    {
29
30
31
        $overrides = $this->overrides->filterHistory(
            $doorId,
            $userId,
32
33
            self::liberalCastToCarbon($start),
            self::liberalCastToCarbon($end)
34
        );
35
36
37
38
39
40
41
42
43
44

        $response = new ResponseModel();

        foreach ($overrides as $override) {
            $response->addOverride($override);
        }

        $presenter->present($response);
    }
}