2020-08-20 15:58:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
final class FingerprintDeleteController extends AbstractController
|
|
|
|
{
|
|
|
|
protected string $route = '/api/v1/fingerprint/{fingerprintId}';
|
|
|
|
|
|
|
|
private int $fingerprintId;
|
|
|
|
|
|
|
|
public function __construct(string $url)
|
|
|
|
{
|
|
|
|
parent::__construct($url);
|
|
|
|
|
|
|
|
$this->fingerprintId = (int)$this->getUrlParamInt('fingerprintId');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle(): void
|
|
|
|
{
|
2020-08-23 11:44:12 +02:00
|
|
|
if (!$this->isUserLoggedIn()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-20 15:58:00 +02:00
|
|
|
parent::handle();
|
|
|
|
|
|
|
|
if ($this->response->getStatus() !== ServerStatus::OK) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2020-08-20 16:53:54 +02:00
|
|
|
$db = new MySqlDatabase();
|
2020-08-23 11:44:12 +02:00
|
|
|
$this->response = new ApiJsonResponse();
|
|
|
|
|
2020-08-20 16:53:54 +02:00
|
|
|
$db->startTransaction();
|
|
|
|
|
|
|
|
$fingerprint = new Fingerprint($this->fingerprintId, $db);
|
2020-08-23 11:44:12 +02:00
|
|
|
|
|
|
|
if (!$this->hasUserPermission($fingerprint->getUserId())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-20 16:53:54 +02:00
|
|
|
$qrCode = new QrCode($fingerprint->getFingerprintId(), $fingerprint->getFingerprint());
|
2020-08-20 15:58:00 +02:00
|
|
|
$fingerprint->Delete();
|
2020-08-20 16:53:54 +02:00
|
|
|
$qrCode->delete();
|
|
|
|
|
|
|
|
$db->commit();
|
2020-08-20 15:58:00 +02:00
|
|
|
} catch (Throwable $e) {
|
|
|
|
$this->response = new ApiJsonResponse(ServerStatus::BAD_REQUEST);
|
|
|
|
$this->response->setParameter('success', false);
|
|
|
|
$this->response->setMessage($e->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|