1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Modules\PushNotificationDevices\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Modules\Core\BaseClasses\BaseApiController; |
6
|
|
|
use App\Modules\PushNotificationDevices\Repositories\PushNotificationDeviceRepository; |
7
|
|
|
use App\Modules\Core\Utl\CoreConfig; |
8
|
|
|
use App\Modules\PushNotificationDevices\Http\Requests\RegisterDevice; |
9
|
|
|
use App\Modules\PushNotificationDevices\Http\Requests\InsertPushNotificationDevice; |
10
|
|
|
use App\Modules\PushNotificationDevices\Http\Requests\UpdatePushNotificationDevice; |
11
|
|
|
|
12
|
|
View Code Duplication |
class PushNotificationDeviceController extends BaseApiController |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* List of all route actions that the base api controller |
16
|
|
|
* will skip permissions check for them. |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
protected $skipPermissionCheck = ['registerDevice']; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Init new object. |
23
|
|
|
* |
24
|
|
|
* @param PushNotificationDeviceRepository $repo |
25
|
|
|
* @param CoreConfig $config |
26
|
|
|
* @return void |
|
|
|
|
27
|
|
|
*/ |
28
|
|
|
public function __construct(PushNotificationDeviceRepository $repo, CoreConfig $config) |
29
|
|
|
{ |
30
|
|
|
parent::__construct($repo, $config, 'App\Modules\PushNotificationDevices\Http\Resources\PushNotificationDevice'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Insert the given model to storage. |
35
|
|
|
* |
36
|
|
|
* @param InsertPushNotificationDevice $request |
37
|
|
|
* @return \Illuminate\Http\Response |
38
|
|
|
*/ |
39
|
|
|
public function insert(InsertPushNotificationDevice $request) |
40
|
|
|
{ |
41
|
|
|
return new $this->modelResource($this->repo->save($request->all())); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Update the given model to storage. |
46
|
|
|
* |
47
|
|
|
* @param UpdatePushNotificationDevice $request |
48
|
|
|
* @return \Illuminate\Http\Response |
49
|
|
|
*/ |
50
|
|
|
public function update(UpdatePushNotificationDevice $request) |
51
|
|
|
{ |
52
|
|
|
return new $this->modelResource($this->repo->save($request->all())); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Register the given device to the logged in user. |
57
|
|
|
* |
58
|
|
|
* @param RegisterDevice $request |
59
|
|
|
* @return \Illuminate\Http\Response |
60
|
|
|
*/ |
61
|
|
|
public function registerDevice(RegisterDevice $request) |
62
|
|
|
{ |
63
|
|
|
return new $this->modelResource($this->repo->registerDevice($request->all())); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.