| 123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace Controllers;
- use Libs\ResponseLib;
- use Models\UserModel;
- use Psr\Http\Message\ServerRequestInterface;
- class UserGetController
- {
- private UserModel $model;
- public function __construct()
- {
- $this->model = new UserModel();
- }
- public function __invoke(ServerRequestInterface $request)
- {
- $body = json_decode((string)$request->getBody(), true) ?? [];
- if (!isset($body['company_id']) || !is_numeric($body['company_id']) || (int)$body['company_id'] <= 0) {
- return ResponseLib::sendFail("Validation failed: invalid company_id", [], "E_VALIDATE")->withStatus(400);
- }
- $companyId = (int) $body['company_id'];
- $users = $this->model->getUsersByCompany($companyId);
- return $users
- ? ResponseLib::sendOk($users)
- : ResponseLib::sendFail("User Not Found", [], "E_DATABASE")->withStatus(204);
- }
- }
|