GroupRelationController.php 5.84 KB
Newer Older
1
2
3
4
5
<?php


namespace App\Http\Controllers\Web\Admin;

Jacob Priddy's avatar
Jacob Priddy committed
6
use Carbon\Carbon;
Jacob Priddy's avatar
Jacob Priddy committed
7
use Illuminate\View\View;
8
use App\Http\Controllers\Controller;
Jacob Priddy's avatar
Jacob Priddy committed
9
use Illuminate\Http\RedirectResponse;
Jacob Priddy's avatar
Jacob Priddy committed
10
11
use Source\UseCases\Schedules\SchedulesGet\DropdownPresenter;
use Source\UseCases\Schedules\SchedulesGet\SchedulesGetUseCase;
Jacob Priddy's avatar
Jacob Priddy committed
12
13
use Source\UseCases\DoorGroup\GetGroupDoors\GetGroupDoorsUseCase;
use Source\UseCases\GroupUser\GetGroupUsers\GetGroupUsersUseCase;
14
use Source\UseCases\DoorGroup\AddDoorToGroup\AddDoorToGroupSearch;
15
use Source\UseCases\GroupUser\AddUserToGroup\AddUserToGroupSearch;
Jacob Priddy's avatar
Jacob Priddy committed
16
17
use Source\UseCases\GroupSchedule\GetGroupSchedules\GetGroupSchedulesUseCase;
use Source\UseCases\DoorGroup\GetGroupDoors\WebPresenter as GroupDoorsPresenter;
Jacob Priddy's avatar
Jacob Priddy committed
18
19
20
21
22
23
use Source\UseCases\GroupUser\GetGroupUsers\WebPresenter as GroupUsersPresenter;
use Source\UseCases\DoorGroup\AddDoorToGroup\APIPresenter as DoorToGroupPresenter;
use Source\UseCases\GroupUser\AddUserToGroup\APIPresenter as UserToGroupPresenter;
use Source\UseCases\GroupSchedule\AddSchedulesToGroups\AddSchedulesToGroupsUseCase;
use Source\UseCases\GroupSchedule\GetGroupSchedules\WebPresenter as GroupSchedulesPresenter;
use Source\UseCases\GroupSchedule\AddSchedulesToGroups\ApiPresenter as ScheduleGroupPresenter;
24
25
26

class GroupRelationController extends Controller
{
Jacob Priddy's avatar
Jacob Priddy committed
27
28
29
30
31
32
33
34
35
    /**
     * @param string                                                        $groupId
     * @param \Source\UseCases\DoorGroup\GetGroupDoors\GetGroupDoorsUseCase $groupDoors
     * @return \Illuminate\View\View
     * @throws \Source\Exceptions\EntityNotFoundException
     */
    public function doors(string $groupId, GetGroupDoorsUseCase $groupDoors): View
    {
        $presenter = new GroupDoorsPresenter();
36

Jacob Priddy's avatar
Jacob Priddy committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
        $groupDoors->getDoorsForGroup($groupId, $presenter);

        return view('admin.groupEntity', array_merge(
            $presenter->getViewModel(),
            ['groupId' => $groupId],
        ));
    }

    /**
     * @param string                                                        $groupId
     * @param \Source\UseCases\GroupUser\GetGroupUsers\GetGroupUsersUseCase $groupUsers
     * @return \Illuminate\View\View
     * @throws \Source\Exceptions\EntityNotFoundException
     */
    public function users(string $groupId, GetGroupUsersUseCase $groupUsers): View
    {
        $presenter = new GroupUsersPresenter();

        $groupUsers->getUsersForGroup($groupId, $presenter);

        return view('admin.groupEntity', array_merge(
            $presenter->getViewModel(),
            ['groupId' => $groupId],
        ));
    }

63
64
65
    /**
     * @param string                                                                    $groupId
     * @param \Source\UseCases\GroupSchedule\GetGroupSchedules\GetGroupSchedulesUseCase $groupSchedules
Jacob Priddy's avatar
Jacob Priddy committed
66
     * @param \Source\UseCases\Schedules\SchedulesGet\SchedulesGetUseCase               $schedules
67
68
     * @return \Illuminate\View\View
     * @throws \Source\Exceptions\EntityNotFoundException
Jacob Priddy's avatar
Jacob Priddy committed
69
     * @throws \Exception
70
     */
Jacob Priddy's avatar
Jacob Priddy committed
71
    public function schedules(string $groupId, GetGroupSchedulesUseCase $groupSchedules, SchedulesGetUseCase $schedules): View
Jacob Priddy's avatar
Jacob Priddy committed
72
    {
Jacob Priddy's avatar
Jacob Priddy committed
73
74
75
76
        $schedulesPresenter = new DropdownPresenter();

        $schedules->filter(null, Carbon::now(), null, $schedulesPresenter);

Jacob Priddy's avatar
Jacob Priddy committed
77
78
79
80
        $presenter = new GroupSchedulesPresenter();

        $groupSchedules->getSchedulesForGroup($groupId, $presenter);

Jacob Priddy's avatar
Jacob Priddy committed
81
        return view('admin.groupScheduleEntity', array_merge(
Jacob Priddy's avatar
Jacob Priddy committed
82
83
            $presenter->getViewModel(),
            ['groupId' => $groupId],
Jacob Priddy's avatar
Jacob Priddy committed
84
            ['schedules' => $schedulesPresenter->getViewModel()],
Jacob Priddy's avatar
Jacob Priddy committed
85
86
87
        ));
    }

88
89
90
91
92
93
94
    /**
     * @param string                                                         $groupId
     * @param \Source\UseCases\DoorGroup\AddDoorToGroup\AddDoorToGroupSearch $addDoorToGroupSearch
     * @return \Illuminate\Http\RedirectResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function addDoor(string $groupId, AddDoorToGroupSearch $addDoorToGroupSearch): RedirectResponse
Jacob Priddy's avatar
Jacob Priddy committed
95
    {
96
97
98
99
100
101
102
        $this->validate($this->request, [
            'door' => 'required|string',
        ]);

        $presenter = new DoorToGroupPresenter();

        $addDoorToGroupSearch->addDoorToGroup([$this->request->input('door')], [$groupId], $presenter);
Jacob Priddy's avatar
Jacob Priddy committed
103

104
        return redirect()->back()->with($presenter->getViewModel());
Jacob Priddy's avatar
Jacob Priddy committed
105
106
    }

107
108
109
110
111
112
113
    /**
     * @param string                                                         $groupId
     * @param \Source\UseCases\GroupUser\AddUserToGroup\AddUserToGroupSearch $addUserToGroupSearch
     * @return \Illuminate\Http\RedirectResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function addUser(string $groupId, AddUserToGroupSearch $addUserToGroupSearch): RedirectResponse
Jacob Priddy's avatar
Jacob Priddy committed
114
    {
115
116
117
118
119
        $this->validate($this->request, [
            'user' => 'required|string',
        ]);

        $presenter = new UserToGroupPresenter();
Jacob Priddy's avatar
Jacob Priddy committed
120

121
122
123
        $addUserToGroupSearch->addUserToGroup([$this->request->input('user')], [$groupId], $presenter);

        return redirect()->back()->with($presenter->getViewModel());
Jacob Priddy's avatar
Jacob Priddy committed
124
125
    }

126
127
128
129
130
131
132
    /**
     * @param string                                                                          $groupId
     * @param \Source\UseCases\GroupSchedule\AddSchedulesToGroups\AddSchedulesToGroupsUseCase $schedulesToGroups
     * @return \Illuminate\Http\RedirectResponse
     * @throws \Illuminate\Validation\ValidationException
     */
    public function addSchedule(string $groupId, AddSchedulesToGroupsUseCase $schedulesToGroups): RedirectResponse
Jacob Priddy's avatar
Jacob Priddy committed
133
    {
134
        $this->validate($this->request, [
Jacob Priddy's avatar
Jacob Priddy committed
135
            'schedule' => 'required|numeric|integer',
136
137
138
139
140
141
        ]);

        $presenter = new ScheduleGroupPresenter();
        $schedulesToGroups->addGroup($groupId);
        $schedulesToGroups->addSchedule($this->request->input('schedule'));
        $schedulesToGroups->attach($presenter);
Jacob Priddy's avatar
Jacob Priddy committed
142

143
        return redirect()->back()->with($presenter->getViewModel());
Jacob Priddy's avatar
Jacob Priddy committed
144
    }
145
}