GetEntriesForUser.php 1.18 KB
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1
2
3
4
5
6
<?php

namespace Source\UseCases\Entries\GetEntriesForUser;

use Carbon\Carbon;
use Source\UseCases\Entries\Presenter;
7
use Source\Gateways\Users\UsersRepository;
Jacob Priddy's avatar
Jacob Priddy committed
8
use Source\UseCases\Entries\ResponseModel;
9
use Source\Exceptions\EntityNotFoundException;
Jacob Priddy's avatar
Jacob Priddy committed
10
11
12
13
14
15
16
17
18
use Source\Gateways\Entries\EntriesRepository;

class GetEntriesForUser implements GetEntriesForUserUseCase
{
    /**
     * @var \Source\Gateways\Entries\EntriesRepository
     */
    protected EntriesRepository $entries;

19
20
21
22
23
24
    /**
     * @var \Source\Gateways\Users\UsersRepository
     */
    protected UsersRepository $users;

    public function __construct(EntriesRepository $entries, UsersRepository $users)
Jacob Priddy's avatar
Jacob Priddy committed
25
26
    {
        $this->entries = $entries;
27
        $this->users = $users;
Jacob Priddy's avatar
Jacob Priddy committed
28
29
30
31
32
33
34
    }

    /**
     * @inheritDoc
     */
    public function getEntriesForUserBetween(string $userId, string $begin, string $end, Presenter $presenter): void
    {
35
36
37
38
        if (!$this->users->exists($userId)) {
            throw new EntityNotFoundException();
        }

Jacob Priddy's avatar
Jacob Priddy committed
39
40
41
42
43
44
45
        $entries = $this->entries->getForUserBetween($userId, new Carbon($begin), new Carbon($end));

        $response = new ResponseModel($entries);

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