ringfinger/backend/classes/controller/UserGetController.php

31 lines
700 B
PHP
Raw Normal View History

2020-08-17 23:46:58 +02:00
<?php
declare(strict_types=1);
final class UserGetController extends AbstractController
{
2020-08-23 12:37:39 +02:00
protected string $route = '/api/v1/user/{userId}';
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
private int $userId;
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
public function __construct(string $url)
{
parent::__construct($url);
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
$this->userId = (int)$this->getUrlParamInt('userId');
}
2020-08-17 23:46:58 +02:00
2020-08-23 12:37:39 +02:00
public function handle(): void
{
2020-08-21 22:47:49 +02:00
$this->response = new ApiJsonResponse();
2020-08-17 23:46:58 +02:00
2020-08-21 22:47:49 +02:00
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());
}
2020-08-23 12:37:39 +02:00
}
2020-08-17 23:46:58 +02:00
}