Completed
Push — master ( cb49ac...f14b58 )
by claudio
13:10
created

TimeslotsController::destroy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4286
cc 1
eloc 7
nc 1
nop 2
crap 1
1
<?php
2
3
namespace plunner\Http\Controllers\Employees\Calendars;
4
5
use Illuminate\Http\Request;
6
use plunner\Calendar;
7
use plunner\Http\Controllers\Controller;
8
use plunner\Http\Requests\Employees\Calendar\TimeslotRequest;
9
use plunner\Timeslot;
10
11
12
class TimeslotsController extends Controller
13
{
14
    /**
15
     * @var \plunner\Company
16
     */
17
    private $user;
0 ignored issues
show
Unused Code introduced by
The property $user is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
18
19
    /**
20
     * ExampleController constructor.
21
     */
22 14
    public function __construct()
23
    {
24 14
        config(['auth.model' => \plunner\Employee::class]);
25 14
        config(['jwt.user' => \plunner\Employee::class]);
26 14
        $this->middleware('jwt.authandrefresh:mode-en');
27 14
    }
28
29
    //TODO check that the calendar is not a caldav calendar
30
31
    /**
32
     * Display a listing of the resource.
33
     *
34
     * @param  int  $calendarId
35
     * @return \Illuminate\Http\Response
36
     */
37 2
    public function index($calendarId)
38
    {
39
        //TODO improvement return small period
40
        /**
41
         * @var $employee Employee
42
         */
43 2
        $calendar = Calendar::findOrFail($calendarId);
44 2
        $this->authorize($calendar);
45 2
        return $calendar->timeslots;
46
    }
47
48
    /**
49
     * Store a newly created resource in storage.
50
     *
51
     * @param  TimeslotRequest  $request
52
     * @param  int  $calendarId
53
     * @return \Illuminate\Http\Response
54
     */
55 2
    public function store(TimeslotRequest $request, $calendarId)
56
    {
57
        //TODO check that end is after start and start is after now
58
        //TODO CHECK
59 2
        $calendar = Calendar::findOrFail($calendarId);
60 2
        $this->authorize($calendar);
61 2
        $input = $request->all();
62 2
        $timeslot = $calendar->timeslots()->create($input);
63
        //  if( $timeslot->time_start > $timeslot->time_end) //IMPROVE THIS,t hsi must be inserted before creation
64 2
        return $timeslot;
65
        //TODO else
66
    }
67
68
    /**
69
     * Display the specified resource.
70
     *
71
     * @param  int  $calendarId
72
     * @param  int  $timeslotId
73
     * @return \Illuminate\Http\Response
74
     */
75 6
    public function show($calendarId, $timeslotId)
76
    {
77
        //
78 6
        $calendar = Calendar::findOrFail($calendarId);
79 6
        $this->authorize($calendar);
80 6
        $timeslot = Timeslot::findOrFail($timeslotId);
81 6
        $this->authorize($timeslot);
82 4
        return $timeslot;
83
    }
84
85
    /**
86
     * Update the specified resource in storage.
87
     *
88
     * @param  TimeslotRequest  $request
89
     * @param  int  $calendarId
90
     * @param  int  $timeslotId
91
     * @return \Illuminate\Http\Response
92
     */
93 2
    public function update(TimeslotRequest $request, $calendarId, $timeslotId)
94
    {
95
        //
96 2
        $calendar = Calendar::findOrFail($calendarId);
97 2
        $this->authorize($calendar);
98 2
        $timeslot = Timeslot::findOrFail($timeslotId);
99 2
        $this->authorize($timeslot);
100 2
        $input = $request->all();
101 2
        $timeslot->update($input);
102 2
        return $timeslot;
103
    }
104
105
    /**
106
     * Remove the specified resource from storage.
107
     *
108
     * @param  int  $calendarId
109
     * @param  int  $timeslotId
110
     * @return \Illuminate\Http\Response
111
     */
112 2
    public function destroy($calendarId, $timeslotId)
113
    {
114
        //
115 2
        $calendar = Calendar::findOrFail($calendarId);
116 2
        $this->authorize($calendar);
117 2
        $timeslot = Timeslot::findOrFail($timeslotId);
118 2
        $this->authorize($timeslot);
119 2
        $timeslot->delete();
120 2
        return $timeslot;
121
    }
122
}
123