ringfinger/backend/classes/controller/UserGetController.php
2020-08-21 22:47:49 +02:00

31 lines
736 B
PHP

<?php
declare(strict_types=1);
final class UserGetController extends AbstractController
{
protected string $route = '/api/v1/user/{userId}';
private int $userId;
public function __construct(string $url)
{
parent::__construct($url);
$this->userId = (int)$this->getUrlParamInt('userId');
}
public function handle(): void
{
$this->response = new ApiJsonResponse();
try {
$user = new User($this->userId);
$this->response->setResult($user);
} catch (Throwable $e) {
$this->response->setParameter('success', false);
$this->response->setStatus($e->getCode() !== 0 ? $e->getCode() : ServerStatus::INTERNAL_ERROR);
$this->response->setMessage($e->getMessage());
}
}
}