|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Containers\User\UI\API\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Containers\User\Actions\ApiLoginAction; |
|
6
|
|
|
use App\Containers\User\Actions\ApiLogoutAction; |
|
7
|
|
|
use App\Containers\User\Actions\DeleteUserAction; |
|
8
|
|
|
use App\Containers\User\Actions\FindUserAction; |
|
9
|
|
|
use App\Containers\User\Actions\ListAllUsersAction; |
|
10
|
|
|
use App\Containers\User\Actions\RegisterUserAction; |
|
11
|
|
|
use App\Containers\User\Actions\UpdateUserAction; |
|
12
|
|
|
use App\Containers\User\Actions\UpdateVisitorUserAction; |
|
13
|
|
|
use App\Containers\User\UI\API\Requests\DeleteUserRequest; |
|
14
|
|
|
use App\Containers\User\UI\API\Requests\LoginRequest; |
|
15
|
|
|
use App\Containers\User\UI\API\Requests\RegisterRequest; |
|
16
|
|
|
use App\Containers\User\UI\API\Requests\UpdateUserRequest; |
|
17
|
|
|
use App\Containers\User\UI\API\Requests\UpdateVisitorUserRequest; |
|
18
|
|
|
use App\Containers\User\UI\API\Transformers\UserTransformer; |
|
19
|
|
|
use App\Port\Controller\Abstracts\PortApiController; |
|
20
|
|
|
use App\Port\Request\Manager\HttpRequest; |
|
21
|
|
|
use Dingo\Api\Http\Request; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class Controller. |
|
25
|
|
|
* |
|
26
|
|
|
* @author Mahmoud Zalt <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
class Controller extends PortApiController |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param \App\Containers\User\UI\API\Requests\DeleteUserRequest $request |
|
33
|
|
|
* @param \App\Containers\User\Actions\DeleteUserAction $action |
|
34
|
|
|
* |
|
35
|
|
|
* @return \Dingo\Api\Http\Response |
|
36
|
|
|
*/ |
|
37
|
|
|
public function deleteUser(DeleteUserRequest $request, DeleteUserAction $action) |
|
38
|
|
|
{ |
|
39
|
|
|
$action->run($request->id); |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
return $this->response->accepted(null, [ |
|
42
|
|
|
'message' => 'User (' . $request->id . ') Deleted Successfully.', |
|
|
|
|
|
|
43
|
|
|
]); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param \App\Containers\User\Actions\ListAllUsersAction $action |
|
48
|
|
|
* |
|
49
|
|
|
* @return \Dingo\Api\Http\Response |
|
50
|
|
|
*/ |
|
51
|
|
|
public function listAllUsers(ListAllUsersAction $action) |
|
52
|
|
|
{ |
|
53
|
|
|
$users = $action->run(); |
|
54
|
|
|
|
|
55
|
|
|
return $this->response->paginator($users, new UserTransformer()); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param \App\Containers\User\UI\API\Requests\LoginRequest $request |
|
60
|
|
|
* @param \App\Containers\User\Actions\ApiLoginAction $action |
|
61
|
|
|
* |
|
62
|
|
|
* @return \Dingo\Api\Http\Response |
|
63
|
|
|
*/ |
|
64
|
|
|
public function loginUser(LoginRequest $request, ApiLoginAction $action) |
|
65
|
|
|
{ |
|
66
|
|
|
$user = $action->run($request['email'], $request['password']); |
|
67
|
|
|
|
|
68
|
|
|
return $this->response->item($user, new UserTransformer()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param \App\Port\Request\Manager\HttpRequest $request |
|
73
|
|
|
* @param \App\Containers\User\Actions\ApiLogoutAction $action |
|
74
|
|
|
* |
|
75
|
|
|
* @return \Dingo\Api\Http\Response |
|
76
|
|
|
*/ |
|
77
|
|
|
public function logoutUser(HttpRequest $request, ApiLogoutAction $action) |
|
78
|
|
|
{ |
|
79
|
|
|
$action->run($request->header('authorization')); |
|
80
|
|
|
|
|
81
|
|
|
return $this->response->accepted(null, [ |
|
82
|
|
|
'message' => 'User Logged Out Successfully.', |
|
83
|
|
|
]); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param \Dingo\Api\Http\Request $request |
|
88
|
|
|
* @param \App\Containers\User\Actions\FindUserAction $action |
|
89
|
|
|
* |
|
90
|
|
|
* @return \Dingo\Api\Http\Response |
|
91
|
|
|
*/ |
|
92
|
|
|
public function refreshUser(Request $request, FindUserAction $action) |
|
93
|
|
|
{ |
|
94
|
|
|
$user = $action->byEverything( |
|
95
|
|
|
$request['user_id'], |
|
96
|
|
|
$request->header('visitor-id'), |
|
97
|
|
|
$request->header('Authorization') |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
return $this->response->item($user, new UserTransformer()); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param \App\Containers\User\UI\API\Requests\RegisterRequest $request |
|
105
|
|
|
* @param \App\Containers\User\Actions\RegisterUserAction $action |
|
106
|
|
|
* |
|
107
|
|
|
* @return \Dingo\Api\Http\Response |
|
108
|
|
|
*/ |
|
109
|
|
View Code Duplication |
public function registerUser(RegisterRequest $request, RegisterUserAction $action) |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
// create and login (true parameter) the new user |
|
112
|
|
|
$user = $action->run( |
|
113
|
|
|
$request['email'], |
|
114
|
|
|
$request['password'], |
|
115
|
|
|
$request['name'], |
|
116
|
|
|
true |
|
117
|
|
|
); |
|
118
|
|
|
|
|
119
|
|
|
return $this->response->item($user, new UserTransformer()); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* The Visitor is the user that was previously created by an visitor ID (A.K.A Device ID). |
|
124
|
|
|
* The Visitor user usually gets created automatically by a Middleware. |
|
125
|
|
|
* |
|
126
|
|
|
* @param \App\Containers\User\UI\API\Requests\UpdateVisitorUserRequest $request |
|
127
|
|
|
* @param \App\Containers\User\Actions\UpdateVisitorUserAction $action |
|
128
|
|
|
* |
|
129
|
|
|
* @return \Dingo\Api\Http\Response |
|
130
|
|
|
*/ |
|
131
|
|
|
public function registerVisitorUser(UpdateVisitorUserRequest $request, UpdateVisitorUserAction $action) |
|
132
|
|
|
{ |
|
133
|
|
|
$user = $action->run( |
|
134
|
|
|
$request->header('Visitor-Id'), |
|
135
|
|
|
$request['email'], |
|
136
|
|
|
$request['password'], |
|
137
|
|
|
$request['name'] |
|
138
|
|
|
); |
|
139
|
|
|
|
|
140
|
|
|
return $this->response->item($user, new UserTransformer()); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @param \App\Containers\User\UI\API\Requests\UpdateUserRequest $request |
|
145
|
|
|
* @param \App\Containers\User\Actions\UpdateUserAction $action |
|
146
|
|
|
* |
|
147
|
|
|
* @return \Dingo\Api\Http\Response |
|
148
|
|
|
*/ |
|
149
|
|
View Code Duplication |
public function updateUser(UpdateUserRequest $request, UpdateUserAction $action) |
|
|
|
|
|
|
150
|
|
|
{ |
|
151
|
|
|
$user = $action->run( |
|
152
|
|
|
$request->id, |
|
|
|
|
|
|
153
|
|
|
$request['password'], |
|
154
|
|
|
$request['name'], |
|
155
|
|
|
$request['email'] |
|
156
|
|
|
); |
|
157
|
|
|
|
|
158
|
|
|
return $this->response->item($user, new UserTransformer()); |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
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@propertyannotation 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.