ringfinger/backend/classes/controller/UserSharingsGetController.php

31 lines
742 B
PHP
Raw Permalink Normal View History

2020-09-09 21:35:11 +02:00
<?php
declare(strict_types=1);
final class UserSharingsGetController extends AbstractController
{
protected string $route = '/api/v1/user/{userId}/sharings';
private int $userId;
public function __construct(string $url)
{
parent::__construct($url);
$this->userId = (int)$this->getUrlParamInt('userId');
}
public function handle(): void
{
$user = new User($this->userId);
try {
$this->response = new ApiJsonResponse();
$this->response->setParameter('sharings', $user->getSharings());
} catch (Throwable $e) {
$this->response = new ApiJsonResponse($e->getCode() !== 0 ? $e->getCode() : ServerStatus::BAD_REQUEST);
$this->response->setSuccess(false);
$this->response->setMessage($e->getMessage());
}
}
}