1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Containers\User\UI\API\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Containers\User\Actions\CreateAdminAction; |
6
|
|
|
use App\Containers\User\Actions\CreateUserAction; |
7
|
|
|
use App\Containers\User\Actions\DeleteUserAction; |
8
|
|
|
use App\Containers\User\Actions\GetUserAction; |
9
|
|
|
use App\Containers\User\Actions\ListAndSearchUsersAction; |
10
|
|
|
use App\Containers\User\Actions\UpdateUserAction; |
11
|
|
|
use App\Containers\User\UI\API\Requests\CreateAdminRequest; |
12
|
|
|
use App\Containers\User\UI\API\Requests\DeleteUserRequest; |
13
|
|
|
use App\Containers\User\UI\API\Requests\GetUserRequest; |
14
|
|
|
use App\Containers\User\UI\API\Requests\ListAllUsersRequest; |
15
|
|
|
use App\Containers\User\UI\API\Requests\RegisterUserRequest; |
16
|
|
|
use App\Containers\User\UI\API\Requests\UpdateUserRequest; |
17
|
|
|
use App\Containers\User\UI\API\Transformers\UserTransformer; |
18
|
|
|
use App\Port\Controller\Abstracts\PortApiController; |
19
|
|
|
use Dingo\Api\Http\Request; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class Controller. |
23
|
|
|
* |
24
|
|
|
* @author Mahmoud Zalt <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class Controller extends PortApiController |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param \App\Containers\User\UI\API\Requests\DeleteUserRequest $request |
31
|
|
|
* @param \App\Containers\User\Actions\DeleteUserAction $action |
32
|
|
|
* |
33
|
|
|
* @return \Dingo\Api\Http\Response |
34
|
|
|
*/ |
35
|
|
|
public function deleteUser(DeleteUserRequest $request, DeleteUserAction $action) |
36
|
|
|
{ |
37
|
|
|
$action->run($request->id); |
|
|
|
|
38
|
|
|
|
39
|
|
|
return $this->response->accepted(null, [ |
40
|
|
|
'message' => 'User (' . $request->user()->id . ') Deleted Successfully.', |
41
|
|
|
]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param \App\Containers\User\UI\API\Requests\ListAllUsersRequest $request |
46
|
|
|
* @param \App\Containers\User\Actions\ListAndSearchUsersAction $action |
47
|
|
|
* |
48
|
|
|
* @return \Dingo\Api\Http\Response |
49
|
|
|
*/ |
50
|
|
|
public function listAllUsers(ListAllUsersRequest $request, ListAndSearchUsersAction $action) |
51
|
|
|
{ |
52
|
|
|
$users = $action->run(); |
53
|
|
|
|
54
|
|
|
return $this->response->paginator($users, new UserTransformer()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param \App\Containers\User\UI\API\Requests\ListAllUsersRequest $request |
59
|
|
|
* @param \App\Containers\User\Actions\ListAndSearchUsersAction $action |
60
|
|
|
* |
61
|
|
|
* @return \Dingo\Api\Http\Response |
62
|
|
|
*/ |
63
|
|
|
public function listAllClients(ListAllUsersRequest $request, ListAndSearchUsersAction $action) |
64
|
|
|
{ |
65
|
|
|
$users = $action->run(['client']); |
66
|
|
|
|
67
|
|
|
return $this->response->paginator($users, new UserTransformer()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param \App\Containers\User\UI\API\Requests\ListAllUsersRequest $request |
72
|
|
|
* @param \App\Containers\User\Actions\ListAndSearchUsersAction $action |
73
|
|
|
* |
74
|
|
|
* @return \Dingo\Api\Http\Response |
75
|
|
|
*/ |
76
|
|
|
public function listAllAdmins(ListAllUsersRequest $request, ListAndSearchUsersAction $action) |
77
|
|
|
{ |
78
|
|
|
$users = $action->run(['admin']); |
79
|
|
|
|
80
|
|
|
return $this->response->paginator($users, new UserTransformer()); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param \Dingo\Api\Http\Request $request |
85
|
|
|
* @param \App\Containers\User\Actions\GetUserAction $action |
86
|
|
|
* |
87
|
|
|
* @return \Dingo\Api\Http\Response |
88
|
|
|
*/ |
89
|
|
|
public function refreshUser(Request $request, GetUserAction $action) |
90
|
|
|
{ |
91
|
|
|
$user = $action->run( |
92
|
|
|
$request['user_id'], |
93
|
|
|
$request->header('Authorization') |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
return $this->response->item($user, new UserTransformer()); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param \App\Containers\User\UI\API\Requests\GetUserRequest $request |
101
|
|
|
* @param \App\Containers\User\Actions\GetUserAction $action |
102
|
|
|
* |
103
|
|
|
* @return \Dingo\Api\Http\Response |
104
|
|
|
*/ |
105
|
|
|
public function getUser(GetUserRequest $request, GetUserAction $action) |
106
|
|
|
{ |
107
|
|
|
$user = $action->run($request->id); |
|
|
|
|
108
|
|
|
|
109
|
|
|
return $this->response->item($user, new UserTransformer()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param \App\Containers\User\UI\API\Requests\RegisterUserRequest $request |
114
|
|
|
* @param \App\Containers\User\Actions\CreateUserAction $action |
115
|
|
|
* |
116
|
|
|
* @return \Dingo\Api\Http\Response |
117
|
|
|
*/ |
118
|
|
|
public function registerUser(RegisterUserRequest $request, CreateUserAction $action) |
119
|
|
|
{ |
120
|
|
|
$user = $action->run($request['email'], $request['password'], $request['name'], $request['gender'], |
121
|
|
|
$request['birth'], true); |
122
|
|
|
|
123
|
|
|
return $this->response->item($user, new UserTransformer()); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param \App\Containers\User\UI\API\Requests\CreateAdminRequest $request |
128
|
|
|
* @param \App\Containers\User\Actions\CreateAdminAction $action |
129
|
|
|
* |
130
|
|
|
* @return \Dingo\Api\Http\Response |
131
|
|
|
*/ |
132
|
|
|
public function createAdmin(CreateAdminRequest $request, CreateAdminAction $action) |
133
|
|
|
{ |
134
|
|
|
$admin = $action->run($request['email'], $request['password'], $request['name']); |
135
|
|
|
|
136
|
|
|
return $this->response->item($admin, new UserTransformer()); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param \App\Containers\User\UI\API\Requests\UpdateUserRequest $request |
141
|
|
|
* @param \App\Containers\User\Actions\UpdateUserAction $action |
142
|
|
|
* |
143
|
|
|
* @return \Dingo\Api\Http\Response |
144
|
|
|
*/ |
145
|
|
|
public function updateUser(UpdateUserRequest $request, UpdateUserAction $action) |
146
|
|
|
{ |
147
|
|
|
$user = $action->run( |
148
|
|
|
$request['password'], |
149
|
|
|
$request['name'], |
150
|
|
|
$request['email'], |
151
|
|
|
$request['gender'], |
152
|
|
|
$request['birth'] |
153
|
|
|
)->withToken(); |
154
|
|
|
|
155
|
|
|
return $this->response->item($user, new UserTransformer()); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.