Completed
Pull Request — master (#48)
by claudio
05:21
created

MeetingsController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4286
c 2
b 1
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace plunner\Http\Controllers\Employees\Planners;
4
5
use Illuminate\Http\Request;
6
7
use plunner\Http\Requests;
8
use plunner\Http\Requests\Employees\MeetingRequest;
9
use plunner\Http\Controllers\Controller;
10
11
use plunner\Meeting;
12
use plunner\Group;
13
14
class MeetingsController extends Controller
15
{
16
    /**
17
     * ExampleController constructor.
18
     */
19 28
    public function __construct()
20
    {
21 28
        config(['auth.model' => \plunner\Planner::class]);
22 28
        config(['jwt.user' => \plunner\Planner::class]);
23 28
        $this->middleware('jwt.authandrefresh:mode-en');
24 28
    }
25
26
    /**
27
     * Display a listing of the resource.
28
     *
29
     *  @param int $groupId
30
     * @return mixed
31
     */
32 2
    public function index($groupId)
33
    {
34 2
        $group = Group::findOrFail($groupId);
35 2
        $this->authorize($group);
36 2
        return $group->meetings;
37
        //TODO get only current meetings via a get query
38
    }
39
40
    /**
41
     * Display the specified resource.
42
     *
43
     * @param int $groupId
44
     * @param int $meetingId
45
     * @return mixed
46
     */
47 6
    public function show($groupId, $meetingId)
48
    {
49 6
        $group = Group::findOrFail($groupId);
50 6
        $this->authorize($group);
51 6
        $meeting = Meeting::where('group_id', $groupId)->findOrFail($meetingId);
52 4
        $this->authorize($meeting);
53 4
        return $meeting;
54
    }
55
56
    /**
57
     * Store a newly created resource in storage.
58
     *
59
     * @param MeetingRequest $request
60
     * @param int $groupId
61
     * @return static
62
     */
63 8
    public function store(MeetingRequest $request, $groupId)
64
    {
65 8
        $group = Group::findOrFail($groupId);
66 8
        $this->authorize($group);
67 8
        $input = $request->all();
68 8
        $meeting = $group->meetings()->create($input);
69 8
        return $meeting;
70
    }
71
72
    /**
73
     * Update the specified resource in storage.
74
     *
75
     * @param MeetingRequest $request
76
     * @param int $meetingId
77
     * @param int $groupId
78
     * @return mixed
79
     */
80 8
    public function update(MeetingRequest $request, $groupId, $meetingId)
81
    {
82 8
        $meeting = Meeting::findOrFail($meetingId);
83 6
        $this->authorize($meeting);
84 6
        $group = Group::findOrFail($groupId);
85 6
        $this->authorize($group);
86 6
        $input = $request->all();
87 6
        $meeting->update($input);
88 6
        return $meeting;
89
    }
90
91
    /**
92
     * Remove the specified resource from storage.
93
     *
94
     * @param int $groupId
95
     * @param int $meetingId
96
     * @return mixed
97
     */
98 8
    public function destroy($groupId, $meetingId)
99
    {
100 8
        $meeting = Meeting::findOrFail($meetingId);
101 6
        $this->authorize($meeting);
102 6
        $group = Group::findOrFail($groupId);
103 6
        $this->authorize($group);
104 6
        $meeting->delete();
105 6
        return $meeting;
106
    }
107
}
108