diff --git a/backend/classes/controller/UserDeleteController.php b/backend/classes/controller/UserDeleteController.php new file mode 100644 index 0000000..f2a83ac --- /dev/null +++ b/backend/classes/controller/UserDeleteController.php @@ -0,0 +1,38 @@ +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()); + } + } +} \ No newline at end of file diff --git a/backend/classes/core/Autoloader.php b/backend/classes/core/Autoloader.php index cc66e16..097fb89 100644 --- a/backend/classes/core/Autoloader.php +++ b/backend/classes/core/Autoloader.php @@ -72,6 +72,7 @@ class Autoloader 'GET' => [], 'POST' => [], 'PUT' => [], + 'DELETE' => [], ]; foreach ($controllersResult as $className => $path) { diff --git a/backend/classes/core/Table.php b/backend/classes/core/Table.php index 60834e3..0641608 100644 --- a/backend/classes/core/Table.php +++ b/backend/classes/core/Table.php @@ -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) {