Completed
Push — master ( f7f9ac...c628bd )
by claudio
05:45
created

MeetingsController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 8
Bugs 4 Features 0
Metric Value
wmc 6
c 8
b 4
f 0
lcom 1
cbo 2
dl 0
loc 96
ccs 36
cts 36
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A index() 0 7 1
A show() 0 10 1
A store() 0 8 1
A update() 0 10 1
A destroy() 0 9 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
        //Meeting::where('group_id', $groupId)->findOrFail($meetingId);
52
        //it is good but expensive and useless for the user experience
53 4
        $meeting = Meeting::findOrFail($meetingId);
54 2
        $this->authorize($meeting);
55 2
        return $meeting;
56
    }
57
58
    /**
59
     * Store a newly created resource in storage.
60
     *
61
     * @param MeetingRequest $request
62
     * @param int $groupId
63
     * @return static
64
     */
65 8
    public function store(MeetingRequest $request, $groupId)
66
    {
67 8
        $group = Group::findOrFail($groupId);
68 8
        $this->authorize($group);
69 8
        $input = $request->all();
70 8
        $meeting = $group->meetings()->create($input);
71 8
        return $meeting;
72
    }
73
74
    /**
75
     * Update the specified resource in storage.
76
     *
77
     * @param MeetingRequest $request
78
     * @param int $meetingId
79
     * @param int $groupId
80
     * @return mixed
81
     */
82 6
    public function update(MeetingRequest $request, $groupId, $meetingId)
83
    {
84 6
        $group = Group::findOrFail($groupId);
85 6
        $this->authorize($group);
86 4
        $meeting = Meeting::findOrFail($meetingId);
87 2
        $this->authorize($meeting);
88 2
        $input = $request->all();
89 2
        $meeting->update($input);
90 2
        return $meeting;
91
    }
92
93
    /**
94
     * Remove the specified resource from storage.
95
     *
96
     * @param int $groupId
97
     * @param int $meetingId
98
     * @return mixed
99
     */
100 6
    public function destroy($groupId, $meetingId)
101
    {
102 6
        $group = Group::findOrFail($groupId);
103 6
        $this->authorize($group);
104 4
        $meeting = Meeting::findOrFail($meetingId);
105 2
        $this->authorize($meeting);
106 2
        $meeting->delete();
107 2
        return $meeting;
108
    }
109
}
110