EntriesController.php 1.33 KB
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php


namespace App\Http\Controllers\Web\Admin;

use Carbon\Carbon;
use Illuminate\View\View;
use App\Http\Controllers\Controller;
use Source\UseCases\Entries\WebPresenter;
use Source\UseCases\Entries\GetEntries\GetEntriesUseCase;

class EntriesController extends Controller
{
    /**
     * @param \Source\UseCases\Entries\GetEntries\GetEntriesUseCase $entries
     * @return \Illuminate\View\View
     * @throws \Illuminate\Validation\ValidationException
     * @throws \Source\Exceptions\EntityNotFoundException
     */
    public function index(GetEntriesUseCase $entries): View
    {
        $this->validate($this->request, [
            'start' => 'nullable|date',
            'end' => 'nullable|date',
25
            'door_id' => 'nullable|integer',
Jacob Priddy's avatar
Jacob Priddy committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
            'user_id' => 'nullable|integer',
        ]);

        $presenter = new WebPresenter();

        $start = $this->request->input('start');
        $end = $this->request->input('end');

        if (!$start && !$end) {
            $start = Carbon::now()->subWeek();
            $end = Carbon::now();
        }

        $entries->getEntries(
            $this->request->input('user_id'),
41
            $this->request->input('door_id'),
Jacob Priddy's avatar
Jacob Priddy committed
42
43
44
45
46
47
48
49
            $start,
            $end,
            $presenter
        );

        return view('admin.entries', $presenter->getViewModel($this->request->all()));
    }
}