GetAttempts.php 1.01 KB
Newer Older
1
2
3
4
<?php

namespace Source\UseCases\Attempts\GetAttempts;

Jacob Priddy's avatar
Jacob Priddy committed
5
6
7
use Source\Sanitize\CastsTo;
use Source\UseCases\Attempts\Presenter;
use Source\UseCases\Attempts\ResponseModel;
8
9
10
11
use Source\Gateways\Attempts\AttemptsRepository;

class GetAttempts implements GetAttemptsUseCase
{
Jacob Priddy's avatar
Jacob Priddy committed
12
13
    use CastsTo;

14
15
16
17
18
19
20
21
22
23
24
25
26
    /**
     * @var \Source\Gateways\Attempts\AttemptsRepository
     */
    protected AttemptsRepository $attempts;

    public function __construct(AttemptsRepository $attempts)
    {
        $this->attempts = $attempts;
    }

    /**
     * @inheritDoc
     */
Jacob Priddy's avatar
Jacob Priddy committed
27
    public function getBetweenDates(?string $start, ?string $end, ?string $doorId, Presenter $presenter): void
28
    {
Jacob Priddy's avatar
Jacob Priddy committed
29
30
31
32
33
34
35
        $attempts = $this->attempts->getBetween(
            $this->liberalCastToCarbon($start),
            $this->liberalCastToCarbon($end),
            $doorId
        );

        $response = new ResponseModel();
36

Jacob Priddy's avatar
Jacob Priddy committed
37
38
39
        foreach ($attempts as $attempt) {
            $response->addAttempt($attempt);
        }
40
41
42
43

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