1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Shop\Permissions\Repositories; |
4
|
|
|
|
5
|
|
|
use App\Shop\Base\BaseRepository; |
6
|
|
|
use App\Shop\Permissions\Exceptions\CreatePermissionErrorException; |
7
|
|
|
use App\Shop\Permissions\Exceptions\DeletePermissionErrorException; |
8
|
|
|
use App\Shop\Permissions\Exceptions\PermissionNotFoundErrorException; |
9
|
|
|
use App\Shop\Permissions\Exceptions\UpdatePermissionErrorException; |
10
|
|
|
use App\Shop\Permissions\Permission; |
11
|
|
|
use App\Shop\Permissions\Repositories\Interfaces\PermissionRepositoryInterface; |
12
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException; |
13
|
|
|
use Illuminate\Database\QueryException; |
14
|
|
|
use Illuminate\Support\Collection; |
15
|
|
|
|
16
|
|
|
class PermissionRepository extends BaseRepository implements PermissionRepositoryInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* PermissionRepository constructor. |
20
|
|
|
* |
21
|
|
|
* @param Permission $permission |
22
|
|
|
*/ |
23
|
|
|
public function __construct(Permission $permission) |
24
|
|
|
{ |
25
|
|
|
parent::__construct($permission); |
26
|
|
|
$this->model = $permission; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param array $data |
31
|
|
|
* |
32
|
|
|
* @return Permission |
33
|
|
|
* @throws CreatePermissionErrorException |
34
|
|
|
*/ |
35
|
|
|
public function createPermission(array $data) : Permission |
36
|
|
|
{ |
37
|
|
|
try { |
38
|
|
|
return $this->create($data); |
|
|
|
|
39
|
|
|
} catch (QueryException $e) { |
40
|
|
|
throw new CreatePermissionErrorException($e); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param int $id |
46
|
|
|
* |
47
|
|
|
* @return Permission |
48
|
|
|
* @throws PermissionNotFoundErrorException |
49
|
|
|
*/ |
50
|
|
|
public function findPermissionById(int $id) : Permission |
51
|
|
|
{ |
52
|
|
|
try { |
53
|
|
|
return $this->findOneOrFail($id); |
|
|
|
|
54
|
|
|
} catch (ModelNotFoundException $e) { |
55
|
|
|
throw new PermissionNotFoundErrorException($e); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param array $data |
61
|
|
|
* @param int $id |
62
|
|
|
* |
63
|
|
|
* @return bool |
64
|
|
|
* @throws UpdatePermissionErrorException |
65
|
|
|
*/ |
66
|
|
|
public function updatePermission(array $data, int $id) : bool |
67
|
|
|
{ |
68
|
|
|
try { |
69
|
|
|
return $this->update($data, $id); |
70
|
|
|
} catch (QueryException $e) { |
71
|
|
|
throw new UpdatePermissionErrorException($e); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param int $id |
77
|
|
|
* |
78
|
|
|
* @return bool |
79
|
|
|
* @throws DeletePermissionErrorException |
80
|
|
|
*/ |
81
|
|
|
public function deletePermissionById(int $id) : bool |
82
|
|
|
{ |
83
|
|
|
try { |
84
|
|
|
return $this->delete($id); |
85
|
|
|
} catch (QueryException $e) { |
86
|
|
|
throw new DeletePermissionErrorException($e); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param array $columns |
92
|
|
|
* @param string $orderBy |
93
|
|
|
* @param string $sortBy |
94
|
|
|
* |
95
|
|
|
* @return Collection |
96
|
|
|
*/ |
97
|
|
|
public function listPermissions($columns = array('*'), string $orderBy = 'id', string $sortBy = 'asc') : Collection |
98
|
|
|
{ |
99
|
|
|
return $this->all($columns, $orderBy, $sortBy); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|