Compare commits
2 Commits
f6d1376dbb
...
3cb02a12f1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3cb02a12f1 | ||
![]() |
b0f2991346 |
@ -17,6 +17,7 @@ final class FingerprintPostController extends AbstractController
|
|||||||
$db = new MySqlDatabase();
|
$db = new MySqlDatabase();
|
||||||
$json = json_decode($this->requestBody);
|
$json = json_decode($this->requestBody);
|
||||||
$fingerprint = new Fingerprint(null, $db);
|
$fingerprint = new Fingerprint(null, $db);
|
||||||
|
$this->response = new ApiJsonResponse();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$fingerprint->setFingerprint($json->fingerprint);
|
$fingerprint->setFingerprint($json->fingerprint);
|
||||||
@ -36,13 +37,10 @@ final class FingerprintPostController extends AbstractController
|
|||||||
|
|
||||||
$this->response->setParameter('fingerprintId', $fingerprint->getFingerprintId());
|
$this->response->setParameter('fingerprintId', $fingerprint->getFingerprintId());
|
||||||
} catch (QrCodeException $e) {
|
} catch (QrCodeException $e) {
|
||||||
$db->rollback();
|
|
||||||
|
|
||||||
$this->response->setParameter('success', false);
|
|
||||||
$this->response->setStatus(ServerStatus::INTERNAL_ERROR);
|
$this->response->setStatus(ServerStatus::INTERNAL_ERROR);
|
||||||
$this->response->setMessage('An error occured during qr code creation!');
|
$this->response->setParameter('success', false);
|
||||||
|
$this->response->setMessage('An error occured during QR code creation!');
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
$db->rollback();
|
|
||||||
$this->catchDatabaseException($e->getMessage(), $json);
|
$this->catchDatabaseException($e->getMessage(), $json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
57
backend/classes/controller/FingerprintPutController.php
Normal file
57
backend/classes/controller/FingerprintPutController.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
final class FingerprintPutController 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
|
||||||
|
{
|
||||||
|
parent::handle();
|
||||||
|
|
||||||
|
if ($this->response->getStatus() !== ServerStatus::OK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->response = new ApiJsonResponse();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$json = json_decode($this->requestBody, true);
|
||||||
|
$fingerprint = new Fingerprint($this->fingerprintId);
|
||||||
|
|
||||||
|
if ($this->handleFingerprint($fingerprint, $json)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->response->setMessage('Fingerprint did not differ from the stored. Nothing changed.');
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
$this->response->setStatus(ServerStatus::BAD_REQUEST);
|
||||||
|
$this->response->setParameter('success', false);
|
||||||
|
$this->response->setMessage($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handleFingerprint(Fingerprint $fingerprint, array $json): bool
|
||||||
|
{
|
||||||
|
if (isset($json['fingerprint'])) {
|
||||||
|
if ($fingerprint->getFingerprint() !== $json['fingerprint']) {
|
||||||
|
$fingerprint->setFingerprint($json['fingerprint']);
|
||||||
|
$fingerprint->Save();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user