2020-08-17 23:46:58 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
final class FingerprintGetController extends AbstractController
|
|
|
|
{
|
2020-08-23 12:37:39 +02:00
|
|
|
protected string $route = '/api/v1/fingerprint/{fingerprintId}';
|
2020-08-17 23:46:58 +02:00
|
|
|
|
2020-08-23 12:37:39 +02:00
|
|
|
private int $fingerprintId;
|
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->fingerprintId = (int)$this->getUrlParamInt('fingerprintId');
|
|
|
|
}
|
2020-08-17 23:46:58 +02:00
|
|
|
|
2020-08-23 12:37:39 +02:00
|
|
|
public function handle(): void
|
|
|
|
{
|
|
|
|
try {
|
2020-08-23 11:44:12 +02:00
|
|
|
if (!$this->isUserLoggedIn()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-23 12:37:39 +02:00
|
|
|
$fingerprint = new Fingerprint($this->fingerprintId);
|
|
|
|
|
|
|
|
if (!$this->hasUserPermission($fingerprint->getUserId())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->response = new ApiJsonResponse();
|
|
|
|
$this->response->setResult($fingerprint);
|
|
|
|
} catch (Throwable $e) {
|
|
|
|
$this->response = new ApiJsonResponse(ApiResponse::STATUS_NOT_FOUND);
|
|
|
|
$this->response->setParameter('success', false);
|
|
|
|
$this->response->setMessage(sprintf('No fingerprint with id %d found!', $this->fingerprintId));
|
|
|
|
$this->response->setMimeType(ApiResponse::MIME_TYPE_JSON);
|
|
|
|
}
|
|
|
|
}
|
2020-08-17 23:46:58 +02:00
|
|
|
}
|