diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 105ebcf..928b544 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -31,7 +31,9 @@ $routes->group('admin', ['namespace' => 'App\Controllers\Admin', 'filter' => 'au $routes->post('insert', 'UserController::insert'); $routes->get('update', 'UserController::form_update'); $routes->post('update', 'UserController::upadate'); - $routes->get('delete/', 'UserController::delete', ['filter' => 'authFilter:master']); $routes->get('view', 'UserController::view'); + $routes->get('delete/', 'UserController::delete', ['filter' => 'authFilter:master']); + $routes->post('point', 'UserController::form_point'); + $routes->post('point', 'UserController::point', ['filter' => 'authFilter:master']); }); }); diff --git a/app/Controllers/Admin/AdminController.php b/app/Controllers/Admin/AdminController.php index b8df803..1d4aed6 100644 --- a/app/Controllers/Admin/AdminController.php +++ b/app/Controllers/Admin/AdminController.php @@ -7,20 +7,7 @@ use App\Controllers\BaseController; abstract class AdminController extends BaseController { private $_datas = []; - final public function __get($name) - { - // echo "Getting '$name'\n"; - if (array_key_exists($name, $this->_datas)) { - return $this->_datas[$name]; - } - return null; - } - final public function __set($name, $value) - { - // echo "Setting '$name' to '$value'\n"; - $this->_datas[$name] = $value; - } protected function __construct() { //사용자 기본 Role 지정 @@ -33,4 +20,17 @@ abstract class AdminController extends BaseController $this->_datas['currentRoles'] = is_array($currentRoles) ? $currentRoles : [DEFAULTS["ROLE"]]; } } + + final public function __get($name): array|null + { + if (!array_key_exists($name, $this->_datas)) { + return null; + } + return $this->_datas; + } + + final public function __set($name, $value): void + { + $this->_datas[$name] = $value; + } } diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 900ac59..fbc8fd8 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -2,10 +2,6 @@ namespace App\Controllers\Admin; -use CodeIgniter\HTTP\RequestInterface; -use CodeIgniter\HTTP\ResponseInterface; -use Psr\Log\LoggerInterface; - use App\Models\UserModel; use App\Traits\MangboardTrait; @@ -24,20 +20,21 @@ class UserController extends AdminController return __METHOD__; } - public function update() + public function point() { try { $id = $this->request->getPost('id'); - $point = $this->request->getPost('point'); - $sign = $this->request->getPost('point') ?: "+"; - $entity = is_numeric($id) ? $this->_model->getEntityByPK(intval($id)) : $this->_model->getEntityByID($id); if (!$entity) { - throw new \Exception(sprintf("해당 회원[%s:%s]이 없습니다.", gettype($id), $id)); + throw new \Exception("해당 회원[{$id}]이 없습니다."); } + + $point = $this->request->getPost('point'); if (!is_numeric($point)) { throw new \Exception("포인트 값에 {$point}를 사용할 수 없습니다."); } + + $sign = $this->request->getPost('point') ?: "+"; $entity = $this->setUserPointByMangboardTrait($entity, intval($point), $sign); return "완료되었습니다."; } catch (\Exception $e) {