Completed
Pull Request — master (#51)
by claudio
05:36 queued 01:00
created

MeetingTimeslotsController::destroy()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

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