aboutsummaryrefslogtreecommitdiffhomepage
path: root/api/Users/Controllers/UserController.php
diff options
context:
space:
mode:
Diffstat (limited to 'api/Users/Controllers/UserController.php')
-rw-r--r--api/Users/Controllers/UserController.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/api/Users/Controllers/UserController.php b/api/Users/Controllers/UserController.php
new file mode 100644
index 0000000..5178dcb
--- /dev/null
+++ b/api/Users/Controllers/UserController.php
@@ -0,0 +1,57 @@
+<?php
+
+namespace Api\Users\Controllers;
+
+use Illuminate\Http\Request;
+use Infrastructure\Http\Controller;
+use Api\Users\Requests\CreateUserRequest;
+use Api\Users\Services\UserService;
+
+class UserController extends Controller
+{
+ private $userService;
+
+ public function __construct(UserService $userService)
+ {
+ $this->userService = $userService;
+ }
+
+ public function getAll()
+ {
+ $resourceOptions = $this->parseResourceOptions();
+
+ $data = $this->userService->getAll($resourceOptions);
+ $parsedData = $this->parseData($data, $resourceOptions, 'users');
+
+ return $this->response($parsedData);
+ }
+
+ public function getById($userId)
+ {
+ $resourceOptions = $this->parseResourceOptions();
+
+ $data = $this->userService->getById($userId, $resourceOptions);
+ $parsedData = $this->parseData($data, $resourceOptions, 'user');
+
+ return $this->response($parsedData);
+ }
+
+ public function create(CreateUserRequest $request)
+ {
+ $data = $request->get('user', []);
+
+ return $this->response($this->userService->create($data), 201);
+ }
+
+ public function update($userId, Request $request)
+ {
+ $data = $request->get('user', []);
+
+ return $this->response($this->userService->update($userId, $data));
+ }
+
+ public function delete($userId)
+ {
+ return $this->response($this->userService->delete($userId));
+ }
+}