Endpoint for user deletion added

This commit is contained in:
Mal 2020-08-20 15:45:59 +02:00
parent 0a8c71b735
commit d5aa47ff54
3 changed files with 40 additions and 1 deletions

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
final class UserDeleteController extends AbstractController
{
protected string $route = '/api/v1/user/{userId}';
private int $userId;
public function __construct(string $url)
{
parent::__construct($url);
$this->userId = (int)$this->getUrlParamInt('userId');
}
public function handle(): void
{
parent::handle();
if ($this->response->getStatus() !== ServerStatus::OK) {
return;
}
try {
$user = new User($this->userId);
$user->Delete();
$this->response = new ApiJsonResponse();
$this->response->setParameter('success', true);
} catch (Throwable $e) {
$this->response = new ApiJsonResponse(ServerStatus::BAD_REQUEST);
$this->response->setParameter('success', false);
$this->response->setMessage($e->getMessage());
}
}
}

View File

@ -72,6 +72,7 @@ class Autoloader
'GET' => [],
'POST' => [],
'PUT' => [],
'DELETE' => [],
];
foreach ($controllersResult as $className => $path) {

View File

@ -116,7 +116,7 @@ abstract class Table
$result = $this->database->getResult();
if (count($result) === 0) {
throw new Exception('No table entry with id ' . $id . ' found!');
throw new Exception(sprintf('No %s with id %d found!', $this->tableName, $id));
}
foreach ($result[0] as $field => $value) {