More Facades, User delete

This commit is contained in:
2024-07-22 00:56:04 +02:00
parent 4b89a7e9ca
commit 7b897071f5
14 changed files with 177 additions and 63 deletions
+28 -11
View File
@@ -5,13 +5,16 @@ namespace Api\User;
use Exception;
use Khofmann\Models\User\User as MUser;
use Khofmann\Input\Input;
use Khofmann\Response\Response;
use Khofmann\Api\Api;
use Khofmann\Request\Request;
class User
class User extends Api
{
public function get($id)
{
try {
return json_encode(MUser::getByID($id));
return Response::json(MUser::getByID($id));
} catch (Exception $err) {
switch ($err->getMessage()) {
case "NotFound":
@@ -22,14 +25,14 @@ class User
}
}
public function post($id)
public function patch($id)
{
$username = Input::post("username");
$password = Input::post("password");
$username = Input::patch("username");
$password = Input::patch("password");
$image = Input::file("image");
try {
return json_encode(MUser::getByID($id)->update($username, $password, $image));
return Response::json(MUser::getByID($id)->update($username, $password, $image));
} catch (Exception $err) {
switch ($err->getMessage()) {
case "NotFound":
@@ -46,15 +49,15 @@ class User
}
}
public function postSelf()
public function patchSelf()
{
$token = Input::header("token");
$username = Input::post("username");
$password = Input::post("password");
$token = Request::header("token");
$username = Input::patch("username");
$password = Input::patch("password");
$image = Input::file("image");
try {
return json_encode(MUser::getByToken($token)->update($username, $password, $image));
return Response::json(MUser::getByToken($token)->update($username, $password, $image));
} catch (Exception $err) {
switch ($err->getMessage()) {
case "NotFound":
@@ -70,4 +73,18 @@ class User
}
}
}
public function delete($id)
{
try {
return Response::json(MUser::getByID($id)->delete());
} catch (Exception $err) {
switch ($err->getMessage()) {
case "NotFound":
throw new Exception("User not Found", 404);
default:
throw $err;
}
}
}
}