Completed
Push — master ( 4e82e1...a0021a )
by claudio
10:25 queued 05:15
created

MeetingTimeslotsController   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 81.58%

Importance

Changes 4
Bugs 3 Features 1
Metric Value
wmc 17
c 4
b 3
f 1
lcom 1
cbo 2
dl 0
loc 124
ccs 62
cts 76
cp 0.8158
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A index() 0 11 2
A show() 0 13 3
A store() 0 17 3
A update() 0 19 4
A destroy() 0 17 4
1
<?php
2
3
namespace plunner\Http\Controllers\Employees\Planners;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Response;
7
use plunner\Group;
8
use plunner\Http\Controllers\Controller;
9
use plunner\Http\Requests;
10
use plunner\Http\Requests\Employees\Meeting\MeetingTimeslotRequest;
11
use plunner\Meeting;
12
use plunner\MeetingTimeslot;
13
14
15
class MeetingTimeslotsController extends Controller
16
{
17 28
    public function __construct()
18
    {
19 28
        config(['auth.model' => \plunner\Planner::class]);
20 28
        config(['jwt.user' => \plunner\Planner::class]);
21 28
        $this->middleware('jwt.authandrefresh:mode-en');
22 28
    }
23
24
    /**
25
     * @param $groupId
26
     * @param $meetingId
27
     * @return mixed
28
     */
29 4
    public function index($groupId, $meetingId)
30
    {
31 4
        $group = Group::findOrFail($groupId);
32 4
        $this->authorize($group);
33 4
        $meeting = Meeting::findOrFail($meetingId);
34 4
        $this->authorize($meeting);
35
36 4
        if ($meeting->group_id == $groupId)
37 3
            return $meeting->timeslots;
38 2
        return Response::json(['error' => 'meeting->group_id <> groupId'], 403);
39
    }
40
41
    /**
42
     * Display the specified resource.
43
     *
44
     * @param int $groupId
45
     * @param int $meetingId
46
     * @param int $timeslotId
47
     * @return mixed
48
     */
49 8
    public function show($groupId, $meetingId, $timeslotId)
50
    {
51 8
        $group = Group::findOrFail($groupId);
52 8
        $this->authorize($group);
53 8
        $meeting = Meeting::findOrFail($meetingId);
54 8
        $this->authorize($meeting);
55 8
        $timeslot = MeetingTimeslot::findOrFail($timeslotId);
56 6
        $this->authorize($timeslot);
57
58 6
        if ($meeting->group_id == $groupId && $timeslot->meeting_id == $meetingId)
59 5
            return $timeslot;
60 2
        return Response::json(['error' => 'meeting->group_id <> groupId || timeslot->meeting_id <> meetingId'], 403);
61
    }
62
63
    /**
64
     * @param MeetingTimeslotRequest $request
65
     * @param $groupId
66
     * @param $meetingId
67
     * @return mixed
68
     */
69 6
    public function store(MeetingTimeslotRequest $request, $groupId, $meetingId)
70
    {
71 6
        $group = Group::findOrFail($groupId);
72 6
        $this->authorize($group);
73 6
        $meeting = Meeting::findOrFail($meetingId);
74 6
        $this->authorize($meeting);
75 6
        if ($meeting->start_time != NULL)
76 4
            return Response::json(['error' => 'the meeting is already planned'], 422);
77
78 4
        $input = $request->all();
79
80 4
        if ($meeting->group_id == $groupId) {
81 2
            $timeslot = $meeting->timeslots()->create($input);
82 2
            return $timeslot;
83
        }
84 2
        return Response::json(['error' => 'meeting->group_id <> groupId'], 403);
85
    }
86
87
    /**
88
     * @param MeetingTimeslotRequest $request
89
     * @param $groupId
90
     * @param $meetingId
91
     * @param $timeslotId
92
     */
93 6
    public function update(MeetingTimeslotRequest $request, $groupId, $meetingId, $timeslotId)
94
    {
95 6
        $group = Group::findOrFail($groupId);
96 6
        $this->authorize($group);
97 6
        $meeting = Meeting::findOrFail($meetingId);
98 6
        $this->authorize($meeting);
99 6
        if ($meeting->start_time != NULL)
100 4
            return Response::json(['error' => 'the meeting is already planned'], 422);
101 4
        $timeslot = MeetingTimeslot::findOrFail($timeslotId);
102 4
        $this->authorize($timeslot);
103
104 4
        $input = $request->all();
105
106 4
        if ($meeting->group_id == $groupId && $timeslot->meeting_id == $meetingId) {
107 2
            $timeslot->update($input);
108 2
            return $timeslot;
109
        }
110 2
        return Response::json(['error' => 'meeting->group_id <> groupId || timeslot->meeting_id <> meetingId'], 403);
111
    }
112
113
    /**
114
     * Remove the specified resource from storage.
115
     *
116
     * @param int $groupId
117
     * @param int $meetingId
118
     * @param int $timeslotId
119
     * @return mixed
120
     */
121 6
    public function destroy($groupId, $meetingId, $timeslotId)
122
    {
123 6
        $group = Group::findOrFail($groupId);
124 6
        $this->authorize($group);
125 6
        $meeting = Meeting::findOrFail($meetingId);
126 6
        $this->authorize($meeting);
127 6
        if ($meeting->start_time != NULL)
128 4
            return Response::json(['error' => 'the meeting is already planned'], 422);
129 4
        $timeslot = MeetingTimeslot::findOrFail($timeslotId);
130 4
        $this->authorize($timeslot);
131
132 4
        if ($meeting->group_id == $groupId && $timeslot->meeting_id == $meetingId) {
133 2
            $timeslot->delete();
134 2
            return $timeslot;
135
        }
136 2
        return Response::json(['error' => 'meeting->group_id <> groupId || timeslot->meeting_id <> meetingId'], 403);
137
    }
138
}
139