Endpoint for user deletion added
This commit is contained in:
parent
0a8c71b735
commit
d5aa47ff54
38
backend/classes/controller/UserDeleteController.php
Normal file
38
backend/classes/controller/UserDeleteController.php
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
@ -72,6 +72,7 @@ class Autoloader
|
||||
'GET' => [],
|
||||
'POST' => [],
|
||||
'PUT' => [],
|
||||
'DELETE' => [],
|
||||
];
|
||||
|
||||
foreach ($controllersResult as $className => $path) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user