AttemptsController.php 1.25 KB
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1
2
3
4
<?php

namespace App\Http\Controllers\Web\Admin;

Jacob Priddy's avatar
Jacob Priddy committed
5
use Carbon\Carbon;
Jacob Priddy's avatar
Jacob Priddy committed
6
7
use Illuminate\View\View;
use App\Http\Controllers\Controller;
Jacob Priddy's avatar
Jacob Priddy committed
8
9
use Source\UseCases\Attempts\GetAttempts\WebPresenter;
use Source\UseCases\Attempts\GetAttempts\GetAttemptsUseCase;
Jacob Priddy's avatar
Jacob Priddy committed
10
11
12

class AttemptsController extends Controller
{
Jacob Priddy's avatar
Jacob Priddy committed
13
14
15
16
    /**
     * @param \Source\UseCases\Attempts\GetAttempts\GetAttemptsUseCase $attempts
     * @return \Illuminate\View\View
     * @throws \Illuminate\Validation\ValidationException
17
     * @throws \Exception
Jacob Priddy's avatar
Jacob Priddy committed
18
19
     */
    public function index(GetAttemptsUseCase $attempts): View
Jacob Priddy's avatar
Jacob Priddy committed
20
    {
Jacob Priddy's avatar
Jacob Priddy committed
21
22
23
        $this->validate($this->request, [
            'start' => 'nullable|date',
            'end' => 'nullable|date',
24
            'door_location' => 'nullable|string',
Jacob Priddy's avatar
Jacob Priddy committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
        ]);

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

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

        $presenter = new WebPresenter();

        $attempts->getBetweenDates(
            $start,
            $end,
            $this->request->input('door_id'),
            $presenter
        );

        return view('admin.attempts', $presenter->getViewModel($this->request->all()));
Jacob Priddy's avatar
Jacob Priddy committed
45
46
    }
}