dbmsv4 init...1
This commit is contained in:
parent
16ad702c5e
commit
e347f0abc5
@ -40,13 +40,13 @@ abstract class AbstractCRUDController extends AbstractWebController
|
||||
return $this->action_redirect_process('error', "{$this->getTitle()}에서 생성폼 오류:" . $e->getMessage());
|
||||
}
|
||||
}
|
||||
protected function create_process(): CommonEntity
|
||||
protected function create_process(): object
|
||||
{
|
||||
// POST 데이터를 DTO 객체로 변환 (getPost()는 POST 요청 본문만 가져옵니다.)
|
||||
return $this->service->create($this->service->createDTO($this->request->getPost()));
|
||||
}
|
||||
|
||||
protected function create_result_process(CommonEntity $entity, ?string $redirect_url = null): string|RedirectResponse
|
||||
protected function create_result_process($entity, ?string $redirect_url = null): string|RedirectResponse
|
||||
{
|
||||
return $this->action_redirect_process(
|
||||
'info',
|
||||
@ -73,7 +73,7 @@ abstract class AbstractCRUDController extends AbstractWebController
|
||||
}
|
||||
|
||||
// --- 수정 (Modify) ---
|
||||
protected function modify_form_process($uid): CommonEntity
|
||||
protected function modify_form_process($uid): object
|
||||
{
|
||||
return $this->service->getEntity($uid);
|
||||
}
|
||||
@ -100,13 +100,13 @@ abstract class AbstractCRUDController extends AbstractWebController
|
||||
}
|
||||
}
|
||||
|
||||
protected function modify_process($uid): CommonEntity
|
||||
protected function modify_process($uid): object
|
||||
{
|
||||
// POST 데이터를 DTO 객체로 변환
|
||||
return $this->service->modify($uid, $this->service->createDTO($this->request->getPost()));
|
||||
}
|
||||
|
||||
protected function modify_result_process(CommonEntity $entity, ?string $redirect_url = null): string|RedirectResponse
|
||||
protected function modify_result_process($entity, ?string $redirect_url = null): string|RedirectResponse
|
||||
{
|
||||
return $this->action_redirect_process(
|
||||
'info',
|
||||
@ -131,13 +131,11 @@ abstract class AbstractCRUDController extends AbstractWebController
|
||||
}
|
||||
|
||||
// --- 삭제 (Delete) ---
|
||||
|
||||
protected function delete_process($uid): CommonEntity
|
||||
protected function delete_process($uid): object
|
||||
{
|
||||
return $this->service->delete($uid);
|
||||
}
|
||||
|
||||
protected function delete_result_process(CommonEntity $entity, ?string $redirect_url = null): string|RedirectResponse
|
||||
protected function delete_result_process($entity, ?string $redirect_url = null): string|RedirectResponse
|
||||
{
|
||||
return $this->action_redirect_process('info', "{$this->getTitle()}에서 {$entity->getTitle()} 삭제가 완료되었습니다.", $redirect_url);
|
||||
}
|
||||
@ -157,8 +155,7 @@ abstract class AbstractCRUDController extends AbstractWebController
|
||||
}
|
||||
|
||||
// --- 상세보기 (View) ---
|
||||
|
||||
protected function view_process($uid): CommonEntity
|
||||
protected function view_process($uid): object
|
||||
{
|
||||
return $this->service->getEntity($uid);
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Controllers\Admin\Customer;
|
||||
|
||||
use App\Entities\Customer\AccountEntity;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
@ -26,8 +26,7 @@ class GoogleController extends AuthController
|
||||
protected function login_process(): UserEntity
|
||||
{
|
||||
//요청 데이터를 DTO 객체로 변환
|
||||
$dto = new GoogleDTO($this->request->getPost());
|
||||
return $this->service->login($dto);
|
||||
return $this->service->login(new GoogleDTO($this->request->getPost()));
|
||||
}
|
||||
protected function logout_process(): void
|
||||
{
|
||||
|
||||
@ -26,8 +26,7 @@ class LocalController extends AuthController
|
||||
protected function login_process(): UserEntity
|
||||
{
|
||||
$this->action_init_process('login');
|
||||
$dto = new LocalDTO($this->request->getPost());
|
||||
return $this->service->login($dto);
|
||||
return $this->service->login(new LocalDTO($this->request->getPost()));
|
||||
}
|
||||
protected function logout_process(): void
|
||||
{
|
||||
|
||||
@ -10,7 +10,6 @@ class ServiceDTO extends CommonDTO
|
||||
public ?int $user_uid = null;
|
||||
public ?int $clientinfo_uid = null;
|
||||
public ?int $serverinfo_uid = null;
|
||||
public ?int $payment_uid = null;
|
||||
public ?string $code = null;
|
||||
public ?string $title = null;
|
||||
public ?string $site = null;
|
||||
|
||||
@ -740,14 +740,14 @@ CREATE TABLE `user` (
|
||||
`email` varchar(50) NOT NULL,
|
||||
`mobile` varchar(20) DEFAULT NULL,
|
||||
`role` varchar(255) DEFAULT NULL,
|
||||
`status` varchar(20) DEFAULT 'normal',
|
||||
`status` varchar(20) NOT NULL DEFAULT 'available',
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`deleted_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`uid`),
|
||||
UNIQUE KEY `UQ_id` (`id`),
|
||||
UNIQUE KEY `UQ_email` (`email`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=46 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='관리자정보';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='관리자정보';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -769,4 +769,4 @@ UNLOCK TABLES;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2025-12-01 18:50:18
|
||||
-- Dump completed on 2025-12-02 10:31:27
|
||||
|
||||
@ -740,14 +740,14 @@ CREATE TABLE `user` (
|
||||
`email` varchar(50) NOT NULL,
|
||||
`mobile` varchar(20) DEFAULT NULL,
|
||||
`role` varchar(255) DEFAULT NULL,
|
||||
`status` varchar(20) DEFAULT 'normal',
|
||||
`status` varchar(20) NOT NULL DEFAULT 'available',
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`deleted_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`uid`),
|
||||
UNIQUE KEY `UQ_id` (`id`),
|
||||
UNIQUE KEY `UQ_email` (`email`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=46 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='관리자정보';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci COMMENT='관리자정보';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -769,4 +769,4 @@ UNLOCK TABLES;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2025-12-01 18:50:25
|
||||
-- Dump completed on 2025-12-02 10:31:19
|
||||
|
||||
@ -20,10 +20,6 @@ class ServiceEntity extends CustomerEntity
|
||||
{
|
||||
return $this->attributes['serverinfo_uid'] ?? null;
|
||||
}
|
||||
final public function getPaymentUID(): string|null
|
||||
{
|
||||
return $this->attributes['payment_uid'] ?? null;
|
||||
}
|
||||
//기본기능용
|
||||
public function getCustomTitle(mixed $title = null): string
|
||||
{
|
||||
|
||||
@ -24,10 +24,6 @@ class ServerPartEntity extends EquipmentEntity
|
||||
{
|
||||
return $this->attributes['serviceinfo_uid'] ?? null;
|
||||
}
|
||||
final public function getPaymentUID(): int|null
|
||||
{
|
||||
return $this->attributes['payment_uid'] ?? null;
|
||||
}
|
||||
//기본기능용
|
||||
public function getCalculatedAmount(): int
|
||||
{
|
||||
|
||||
@ -15,8 +15,7 @@ class LocalForm extends CommonForm
|
||||
{
|
||||
switch ($field) {
|
||||
case "id":
|
||||
$rule = "required|trim|min_length[4]|max_length[20]";
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
$rule = sprintf("required|trim|min_length[4]|max_length[20]%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
||||
break;
|
||||
case "passwd":
|
||||
$rule = in_array($action, ["create", "create_form"]) ? "required|trim|string" : "permit_empty|trim|string";
|
||||
|
||||
@ -147,19 +147,17 @@ abstract class CommonForm
|
||||
switch ($field) {
|
||||
case $this->getAttribute('pk_field'):
|
||||
if (!$this->$this->getAttribute('useAutoIncrement')) {
|
||||
$rule = "required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]";
|
||||
$rule .= in_array($action, ["create"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
$rule = sprintf("required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]%s", in_array($action, ["create"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
||||
} else {
|
||||
$rule = "required|numeric";
|
||||
}
|
||||
break;
|
||||
case $this->getAttribute('title_field'):
|
||||
$rule = "required|trim|string";
|
||||
$rule = sprintf("required|trim|string%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
||||
break;
|
||||
case "code":
|
||||
// a-zA-Z → 영문 대소문자,0-9 → 숫자,가-힣 → 한글 완성형,\- → 하이픈
|
||||
$rule = "required|regex_match[/^[a-zA-Z0-9가-힣\-]+$/]|min_length[4]|max_length[20]";
|
||||
$rule .= in_array($action, ["create"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
$rule = sprintf("required|regex_match[/^[a-zA-Z0-9가-힣\-]+$/]|min_length[4]|max_length[20]%s", in_array($action, ["create"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
||||
break;
|
||||
case "user_uid":
|
||||
$rule = "required|numeric";
|
||||
|
||||
@ -11,12 +11,8 @@ class ClientForm extends CustomerForm
|
||||
public function getFormRule(string $action, string $field): string
|
||||
{
|
||||
switch ($field) {
|
||||
case "user_uid":
|
||||
$rule = "required|numeric";
|
||||
break;
|
||||
case "name":
|
||||
$rule = "required|trim|string";
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
$rule = sprintf("required|trim|string%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
||||
break;
|
||||
case "site":
|
||||
case "role":
|
||||
|
||||
@ -8,25 +8,4 @@ class CouponForm extends CustomerForm
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
public function getFormRule(string $action, string $field): string
|
||||
{
|
||||
switch ($field) {
|
||||
case "user_uid":
|
||||
case "clientinfo_uid":
|
||||
case "cnt":
|
||||
$rule = "required|numeric";
|
||||
break;
|
||||
case "title":
|
||||
case "status":
|
||||
$rule = "required|trim|string";
|
||||
break;
|
||||
case "content":
|
||||
$rule = "permit_empty|trim|string";
|
||||
break;
|
||||
default:
|
||||
$rule = parent::getFormRule($action, $field);
|
||||
break;
|
||||
}
|
||||
return $rule;
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,27 +10,4 @@ abstract class CustomerForm extends CommonForm
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
public function getFormRule(string $action, string $field): string
|
||||
{
|
||||
switch ($field) {
|
||||
case "title":
|
||||
$rule = "required|trim|string";
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
break;
|
||||
case "user_uid":
|
||||
case "clientinfo_uid":
|
||||
$rule = "required|numeric";
|
||||
break;
|
||||
case "price":
|
||||
$rule = "required|numeric";
|
||||
break;
|
||||
case "status":
|
||||
$rule = "permit_empty|trim|string";
|
||||
break;
|
||||
default:
|
||||
$rule = parent::getFormRule($action, $field);
|
||||
break;
|
||||
}
|
||||
return $rule;
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,6 @@ class PointForm extends CustomerForm
|
||||
public function getFormRule(string $action, string $field): string
|
||||
{
|
||||
switch ($field) {
|
||||
case "user_uid":
|
||||
case "clientinfo_uid":
|
||||
case "amount":
|
||||
$rule = "required|numeric";
|
||||
|
||||
@ -11,7 +11,6 @@ class ServiceForm extends CustomerForm
|
||||
public function getFormRule(string $action, string $field): string
|
||||
{
|
||||
switch ($field) {
|
||||
case "user_uid":
|
||||
case "clientinfo_uid":
|
||||
case "serverinfo_uid":
|
||||
case "amount":
|
||||
@ -20,7 +19,6 @@ class ServiceForm extends CustomerForm
|
||||
$rule = "required|numeric";
|
||||
break;
|
||||
case "sale":
|
||||
case "payment_uid":
|
||||
$rule = "permit_empty|numeric";
|
||||
break;
|
||||
case "site":
|
||||
|
||||
@ -10,29 +10,4 @@ abstract class EquipmentForm extends CommonForm
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
public function getFormRule(string $action, string $field): string
|
||||
{
|
||||
switch ($field) {
|
||||
case "title":
|
||||
$rule = "required|trim|string";
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
break;
|
||||
case "user_uid":
|
||||
case "clientinfo_uid":
|
||||
case "serviceinfo_uid":
|
||||
case "serverinfo_uid":
|
||||
$rule = "permit_empty|numeric";
|
||||
break;
|
||||
case "price":
|
||||
$rule = "required|numeric";
|
||||
break;
|
||||
case "status":
|
||||
$rule = "permit_empty|trim|string";
|
||||
break;
|
||||
default:
|
||||
$rule = parent::getFormRule($action, $field);
|
||||
break;
|
||||
}
|
||||
return $rule;
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,8 +12,7 @@ class ServerForm extends EquipmentForm
|
||||
{
|
||||
switch ($field) {
|
||||
case "switchinfo_uid":
|
||||
$rule = "permit_empty|numeric";
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
$rule = sprintf("permit_empty|numeric%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
||||
break;
|
||||
case "code":
|
||||
case "title":
|
||||
@ -26,9 +25,8 @@ class ServerForm extends EquipmentForm
|
||||
case "status":
|
||||
$rule = "required|trim|string";
|
||||
break;
|
||||
case "ip":
|
||||
$rule = "permit_empty|trim|valid_ip[both]"; //ipv4 , ipv6 , both(ipv4,ipv6)
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
case "ip": //ipv4 , ipv6 , both(ipv4,ipv6)
|
||||
$rule = sprintf("permit_empty|trim|valid_ip[both]%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
||||
break;
|
||||
case "os":
|
||||
$rule = "permit_empty|trim|string";
|
||||
|
||||
@ -21,7 +21,6 @@ class ServerPartForm extends EquipmentForm
|
||||
break;
|
||||
case "clientinfo_uid":
|
||||
case "serviceinfo_uid":
|
||||
case "payment_uid":
|
||||
$rule = "permit_empty|numeric";
|
||||
break;
|
||||
case "title":
|
||||
|
||||
@ -11,7 +11,7 @@ class CPUForm extends PartForm
|
||||
public function getFormRule(string $action, string $field): string
|
||||
{
|
||||
switch ($field) {
|
||||
case "format":
|
||||
case "used":
|
||||
$rule = "required|numeric";
|
||||
break;
|
||||
default:
|
||||
|
||||
@ -14,9 +14,8 @@ class CSForm extends PartForm
|
||||
case "type":
|
||||
$rule = "required|trim|string";
|
||||
break;
|
||||
case "ip":
|
||||
$rule = "required|trim|valid_ip[both]"; //ipv4 , ipv6 , both(ipv4,ipv6)
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
case "ip": //ipv4 , ipv6 , both(ipv4,ipv6)
|
||||
$rule = sprintf("required|trim|valid_ip[both]%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
||||
break;
|
||||
case "accountid":
|
||||
case "domain":
|
||||
|
||||
@ -11,6 +11,12 @@ class DISKForm extends PartForm
|
||||
public function getFormRule(string $action, string $field): string
|
||||
{
|
||||
switch ($field) {
|
||||
case "used":
|
||||
$rule = "required|numeric";
|
||||
break;
|
||||
case "format":
|
||||
$rule = "required|numeric";
|
||||
break;
|
||||
default:
|
||||
$rule = parent::getFormRule($action, $field);
|
||||
break;
|
||||
|
||||
@ -14,9 +14,8 @@ class IPForm extends PartForm
|
||||
case "lineinfo_uid":
|
||||
$rule = "required|numeric";
|
||||
break;
|
||||
case "ip":
|
||||
$rule = "required|trim|valid_ip[both]"; //ipv4 , ipv6 , both(ipv4,ipv6)
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
case "ip": //ipv4 , ipv6 , both(ipv4,ipv6)
|
||||
$rule = sprintf("required|trim|valid_ip[both]%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
||||
break;
|
||||
case "status":
|
||||
$rule = "required|trim|string";
|
||||
|
||||
@ -14,8 +14,7 @@ abstract class PartForm extends CommonForm
|
||||
{
|
||||
switch ($field) {
|
||||
case "title":
|
||||
$rule = "required|trim|string";
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
$rule = sprintf("required|trim|string%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
||||
break;
|
||||
case "clientinfo_uid":
|
||||
case "serviceinfo_uid":
|
||||
|
||||
@ -11,6 +11,9 @@ class RAMForm extends PartForm
|
||||
public function getFormRule(string $action, string $field): string
|
||||
{
|
||||
switch ($field) {
|
||||
case "used":
|
||||
$rule = "required|numeric";
|
||||
break;
|
||||
default:
|
||||
$rule = parent::getFormRule($action, $field);
|
||||
break;
|
||||
|
||||
@ -26,18 +26,16 @@ class UserForm extends CommonForm
|
||||
{
|
||||
switch ($field) {
|
||||
case "id":
|
||||
$rule = "required|trim|min_length[4]|max_length[20]";
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "";
|
||||
$rule = sprintf("required|trim|min_length[4]|max_length[20]%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
||||
break;
|
||||
case "passwd":
|
||||
$rule = in_array($action, ["create", "create_form"]) ? "required" : "permit_empty" . "|trim|string";
|
||||
$rule = sprintf("%s|%s", in_array($action, ["create", "create_form"]) ? "required" : "permit_empty", "trim|string");
|
||||
break;
|
||||
case "confirmpassword":
|
||||
$rule = in_array($action, ["create", "create_form"]) ? "required" : "permit_empty" . "|trim|string|matches[passwd]";
|
||||
$rule = sprintf("%s|%s", in_array($action, ["create", "create_form"]) ? "required" : "permit_empty", "trim|string|matches[passwd]");
|
||||
break;
|
||||
case "email":
|
||||
$rule = "required|trim|valid_email";
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "" . "|trim|valid_email";
|
||||
$rule = sprintf("required|trim|valid_email%s", in_array($action, ["create", "create_form"]) ? "|is_unique[{$this->getAttribute('table')}.{$field}]" : "");
|
||||
break;
|
||||
case "role":
|
||||
$rule = "required|trim|string";
|
||||
|
||||
@ -19,7 +19,6 @@ class ServiceModel extends CustomerModel
|
||||
"user_uid",
|
||||
"clientinfo_uid",
|
||||
"serverinfo_uid",
|
||||
"payment_uid",
|
||||
"code",
|
||||
"title",
|
||||
"site",
|
||||
|
||||
@ -18,7 +18,6 @@ class ServerPartModel extends EquipmentModel
|
||||
"clientinfo_uid",
|
||||
"serverinfo_uid",
|
||||
"serviceinfo_uid",
|
||||
"payment_uid",
|
||||
"title",
|
||||
"type",
|
||||
"billing",
|
||||
|
||||
@ -18,8 +18,7 @@ abstract class PartModel extends CommonModel
|
||||
}
|
||||
switch ($field) {
|
||||
case "title":
|
||||
$rule = "required|trim|string";
|
||||
$rule .= in_array($action, ["create", "create_form"]) ? "|is_unique[" . $this->getTable() . "." . $field . "]" : "";
|
||||
$rule = sprintf("required|trim|string", in_array($action, ["create", "create_form"]) ? "|is_unique[" . $this->getTable() . "." . $field . "]" : "");
|
||||
break;
|
||||
case "clientinfo_uid":
|
||||
case "serviceinfo_uid":
|
||||
|
||||
@ -2,38 +2,30 @@
|
||||
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\DTOs\Auth\AuthDTO;
|
||||
use App\Entities\CommonEntity;
|
||||
use App\DTOs\Auth\GoogleDTO;
|
||||
use App\DTOs\Auth\LocalDTO;
|
||||
use App\Entities\UserEntity;
|
||||
use App\Helpers\AuthHelper;
|
||||
use App\Libraries\AuthContext;
|
||||
use App\Models\CommonModel;
|
||||
use CodeIgniter\Validation\Exceptions\ValidationException;
|
||||
use App\Services\CommonService;
|
||||
|
||||
/**
|
||||
* AuthService
|
||||
* 인증(로그인) 워크플로우를 정의하는 템플릿 클래스입니다.
|
||||
* CommonService를 상속받지 않아 불필요한 CRUD 구현을 요구하지 않습니다.
|
||||
*/
|
||||
abstract class AuthService
|
||||
abstract class AuthService extends CommonService
|
||||
{
|
||||
private $_helper = null;
|
||||
private ?AuthContext $_authContext = null;
|
||||
private array $_classPaths = [];
|
||||
protected ?CommonModel $model = null;
|
||||
|
||||
protected function __construct(CommonModel $model)
|
||||
{
|
||||
$this->model = $model; // 모델을 직접 주입받아 자식에게 전달
|
||||
parent::__construct($model);
|
||||
$this->addClassPaths('Auth');
|
||||
}
|
||||
abstract public function action_init_process(string $action);
|
||||
public function getEntityClass(): string
|
||||
{
|
||||
return UserEntity::class;
|
||||
}
|
||||
abstract public function getFormService(): mixed;
|
||||
final public function getHelper(): AuthHelper
|
||||
{
|
||||
if ($this->_helper === null) {
|
||||
$this->_helper = new AuthHelper();
|
||||
// AuthHelper에 필요한 기본 메타데이터만 설정합니다. (CRUD 제거)
|
||||
$this->_helper->setAttributes([
|
||||
'pk_field' => $this->model->getPKField(),
|
||||
'title_field' => $this->model->getTitleField(),
|
||||
@ -42,72 +34,12 @@ abstract class AuthService
|
||||
}
|
||||
return $this->_helper;
|
||||
}
|
||||
//인증세션용
|
||||
final public function getAuthContext(): AuthContext
|
||||
{
|
||||
if ($this->_authContext === null) {
|
||||
$this->_authContext = new AuthContext();
|
||||
}
|
||||
return $this->_authContext;
|
||||
}
|
||||
final protected function addClassPaths(string $path): void
|
||||
{
|
||||
$this->_classPaths[] = $path;
|
||||
}
|
||||
final public function getClassPaths($isArray = true, $delimeter = DIRECTORY_SEPARATOR): array|string
|
||||
{
|
||||
return $isArray ? $this->_classPaths : implode($delimeter, $this->_classPaths);
|
||||
}
|
||||
abstract protected function getEntity_process(mixed $entity): CommonEntity;
|
||||
final public function getEntity(string|int|array $where, ?string $message = null): mixed
|
||||
{
|
||||
try {
|
||||
$entity = is_array($where) ? $this->model->where($where)->first() : $this->model->find($where);
|
||||
if (!$entity) {
|
||||
return null;
|
||||
}
|
||||
if (is_array($entity)) {
|
||||
throw new \Exception(__METHOD__ . "에서 결과값 Array 오류발생:\n" . var_export($entity, true));
|
||||
}
|
||||
return $this->getEntity_process($entity);
|
||||
} catch (\Exception $e) {
|
||||
$message = sprintf(
|
||||
"\n------%s SQL오류-----<BR>\n%s\n%s\n------------------------------\n",
|
||||
__FUNCTION__,
|
||||
$this->model->getLastQuery(),
|
||||
$e->getMessage()
|
||||
);
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
final protected function getValidationRules(string $action, array $rules): array
|
||||
{
|
||||
$dynamicRules = [];
|
||||
foreach ($rules as $field => $rule) {
|
||||
//field별 추가 커스텀 룰 적용
|
||||
list($field, $rule) = $this->getValidationRule($field, $rule);
|
||||
$dynamicRules[$field] = $rule;
|
||||
}
|
||||
return $dynamicRules;
|
||||
}
|
||||
protected function getValidationRule(string $field, string $rule): array
|
||||
{
|
||||
return array($field, $rule);
|
||||
}
|
||||
|
||||
//로그인
|
||||
abstract protected function login_process(array $formDatas): UserEntity;
|
||||
public function login(AuthDTO $dto): UserEntity
|
||||
final public function login(LocalDTO|GoogleDTO $dto): UserEntity
|
||||
{
|
||||
$formDatas = $dto->toArray();
|
||||
// dd($formDatas);
|
||||
//입력값 검증
|
||||
if (!$this->getFormService()->validate($formDatas)) {
|
||||
throw new ValidationException(implode("\n", service('validation')->getErrors()));
|
||||
}
|
||||
//인증처리
|
||||
$entity = $this->login_process($formDatas);
|
||||
//세션처리
|
||||
$entity = $this->login_process($dto->toArray());
|
||||
//인증 세션처리
|
||||
$this->getAuthContext()->setAuthSession($entity);
|
||||
return $entity;
|
||||
}
|
||||
|
||||
@ -3,13 +3,12 @@
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\DTOs\Auth\GoogleDTO;
|
||||
use App\DTOs\Auth\AuthDTO;
|
||||
use App\Entities\UserEntity;
|
||||
use App\Forms\Auth\GoogleForm;
|
||||
use App\Libraries\MySocket\GoogleSocket\CURL;
|
||||
use App\Models\UserModel;
|
||||
use CodeIgniter\Exceptions\PageNotFoundException;
|
||||
use RuntimeException;
|
||||
use CodeIgniter\Validation\Exceptions\ValidationException;
|
||||
|
||||
class GoogleService extends AuthService
|
||||
{
|
||||
@ -19,6 +18,14 @@ class GoogleService extends AuthService
|
||||
parent::__construct($model);
|
||||
$this->addClassPaths('Google');
|
||||
}
|
||||
public function createDTO(array $formDatas): GoogleDTO
|
||||
{
|
||||
return new GoogleDTO($formDatas);
|
||||
}
|
||||
protected function getDTOClass(): string
|
||||
{
|
||||
return GoogleDTO::class;
|
||||
}
|
||||
public function getFormService(): GoogleForm
|
||||
{
|
||||
if ($this->_form === null) {
|
||||
@ -33,7 +40,7 @@ class GoogleService extends AuthService
|
||||
}
|
||||
return $this->_form;
|
||||
}
|
||||
public function action_init_process(string $action): void
|
||||
public function action_init_process(string $action, array $formDatas = []): void
|
||||
{
|
||||
$fields = ['access_code'];
|
||||
$filters = [];
|
||||
@ -56,6 +63,11 @@ class GoogleService extends AuthService
|
||||
protected function login_process(array $formDatas): UserEntity
|
||||
{
|
||||
try {
|
||||
//입력값 검증
|
||||
if (!$this->getFormService()->validate($formDatas)) {
|
||||
throw new ValidationException(implode("\n", service('validation')->getErrors()));
|
||||
}
|
||||
|
||||
$this->socket->setToken($formDatas['access_code']);
|
||||
$sns_entity = $this->socket->signup();
|
||||
// local db 사용와의 연결 확인
|
||||
@ -72,11 +84,4 @@ class GoogleService extends AuthService
|
||||
throw new PageNotFoundException("관리자에게 문의하시기 바랍니다.\n{$e->getMessage()}");
|
||||
}
|
||||
}
|
||||
public function login(AuthDTO $dto): UserEntity
|
||||
{
|
||||
if (!$dto instanceof GoogleDTO) {
|
||||
throw new RuntimeException(__METHOD__ . "에서 오류발생: " . get_class($dto) . " DTO는 사용할 수 없습니다. LocalDTO만 허용됩니다.");
|
||||
}
|
||||
return parent::login($dto);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,13 +2,11 @@
|
||||
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\DTOs\Auth\AuthDTO; // 부모 클래스의 타입 힌트를 위해 사용 (알리아스 아님)
|
||||
use App\DTOs\Auth\LocalDTO; // LocalDTO를 직접 사용
|
||||
use App\DTOs\Auth\LocalDTO;
|
||||
use App\Entities\UserEntity;
|
||||
use App\Forms\Auth\LocalForm;
|
||||
use App\Models\UserModel;
|
||||
use RuntimeException;
|
||||
|
||||
use CodeIgniter\Validation\Exceptions\ValidationException;
|
||||
|
||||
class LocalService extends AuthService
|
||||
{
|
||||
@ -18,7 +16,14 @@ class LocalService extends AuthService
|
||||
parent::__construct($model);
|
||||
$this->addClassPaths('Local');
|
||||
}
|
||||
|
||||
public function createDTO(array $formDatas): LocalDTO
|
||||
{
|
||||
return new LocalDTO($formDatas);
|
||||
}
|
||||
protected function getDTOClass(): string
|
||||
{
|
||||
return LocalDTO::class;
|
||||
}
|
||||
public function getFormService(): LocalForm
|
||||
{
|
||||
if ($this->_form === null) {
|
||||
@ -33,7 +38,7 @@ class LocalService extends AuthService
|
||||
}
|
||||
return $this->_form;
|
||||
}
|
||||
public function action_init_process(string $action): void
|
||||
public function action_init_process(string $action, array $formDatas = []): void
|
||||
{
|
||||
$fields = ['id', 'passwd'];
|
||||
$filters = [];
|
||||
@ -54,7 +59,12 @@ class LocalService extends AuthService
|
||||
}
|
||||
protected function login_process(array $formDatas): UserEntity
|
||||
{
|
||||
$entity = $this->getEntity(['id' => $formDatas['id'], 'status' => 'AVAILABLE'], true);
|
||||
//입력값 검증
|
||||
if (!$this->getFormService()->validate($formDatas)) {
|
||||
throw new ValidationException(implode("\n", service('validation')->getErrors()));
|
||||
}
|
||||
//로그인 정보확인
|
||||
$entity = $this->getEntity(['id' => $formDatas['id'], 'status' => 'AVAILABLE']);
|
||||
if (!$entity instanceof UserEntity) {
|
||||
throw new \Exception("{$formDatas['id']}에 대한 로그인 정보를 찾을수 없습니다.");
|
||||
}
|
||||
@ -63,12 +73,4 @@ class LocalService extends AuthService
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
|
||||
public function login(AuthDTO $dto): UserEntity
|
||||
{
|
||||
if (!$dto instanceof LocalDTO) {
|
||||
throw new RuntimeException(__METHOD__ . "에서 오류발생: " . get_class($dto) . " DTO는 사용할 수 없습니다. LocalDTO만 허용됩니다.");
|
||||
}
|
||||
return parent::login($dto);
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,13 +49,9 @@ abstract class CommonService
|
||||
}
|
||||
/**
|
||||
* 단일 엔티티를 조회합니다.
|
||||
* @return CommonEntity|null CommonEntity 인스턴스 또는 찾지 못했을 경우 null
|
||||
*/
|
||||
protected function getEntity_process(CommonEntity $entity): CommonEntity
|
||||
{
|
||||
return $entity;
|
||||
}
|
||||
public function getEntity(string|int|array $where, ?string $message = null): ?object
|
||||
abstract protected function getEntity_process(CommonEntity $entity): CommonEntity;
|
||||
final public function getEntity(string|int|array $where, ?string $message = null): ?object
|
||||
{
|
||||
try {
|
||||
$entity = is_array($where) ? $this->model->where($where)->first() : $this->model->find($where);
|
||||
@ -186,7 +182,7 @@ abstract class CommonService
|
||||
}
|
||||
return $this->save_process($entity);
|
||||
}
|
||||
final public function create(object $dto): CommonEntity
|
||||
final public function create(object $dto): object
|
||||
{
|
||||
$db = \Config\Database::connect();
|
||||
try {
|
||||
@ -197,10 +193,7 @@ abstract class CommonService
|
||||
if (!$dto instanceof $dtoClass) {
|
||||
throw new RuntimeException(__METHOD__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)");
|
||||
}
|
||||
// NOTE: create_process에서 엔티티를 생성할 때, 자동 증가(AUTO_INCREMENT) 필드는
|
||||
// DB가 처리하도록 NULL이나 빈 값(0)으로 두는 것이 일반적입니다.
|
||||
$entity = $this->create_process($dto->toArray());
|
||||
// 트랜잭션 완료 및 커밋
|
||||
$db->transComplete();
|
||||
return $entity;
|
||||
} catch (DatabaseException $e) {
|
||||
@ -226,7 +219,7 @@ abstract class CommonService
|
||||
implode("\n", service('validation')->getErrors())
|
||||
);
|
||||
}
|
||||
// 관리자 정보 추가
|
||||
//관리자 정보추가용
|
||||
$formDatas['user_uid'] = $this->getAuthContext()->getUID();
|
||||
//PK 추가
|
||||
$pkField = $this->model->getPKField();
|
||||
@ -234,15 +227,20 @@ abstract class CommonService
|
||||
// original에 있는 PK 값을 attributes에 명시적으로 복사합니다.
|
||||
$formDatas[$pkField] = $entity->getPK();
|
||||
}
|
||||
$entity->fill($formDatas);
|
||||
// dd($formDatas);
|
||||
foreach ($formDatas as $key => $value) {
|
||||
if ($value !== null) {
|
||||
$entity->$key = $value;
|
||||
}
|
||||
}
|
||||
// dd($entity);
|
||||
return $this->save_process($entity);
|
||||
}
|
||||
|
||||
final public function modify(string|int $uid, object $dto): CommonEntity
|
||||
final public function modify(string|int $uid, object $dto): object
|
||||
{
|
||||
$db = \Config\Database::connect();
|
||||
try {
|
||||
//트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정
|
||||
$db->transException(true)->transStart();
|
||||
//DTO 타입 체크 로직을 일반화
|
||||
$dtoClass = $this->getDTOClass();
|
||||
@ -268,7 +266,7 @@ abstract class CommonService
|
||||
}
|
||||
|
||||
//배치 작업용 수정
|
||||
protected function batchjob_process(string|int $uid, array $formDatas): CommonEntity
|
||||
protected function batchjob_process(string|int $uid, array $formDatas): object
|
||||
{
|
||||
// modify_process를 호출하여 로직 재사용 (PK 로드 및 PK 제거/방어 로직 포함)
|
||||
$entity = $this->modify_process($this->getEntity($uid), $formDatas);
|
||||
@ -278,7 +276,6 @@ abstract class CommonService
|
||||
{
|
||||
$db = \Config\Database::connect();
|
||||
try {
|
||||
//트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정
|
||||
$db->transException(true)->transStart();
|
||||
//DTO 타입 체크 로직을 일반화
|
||||
$dtoClass = $this->getDTOClass();
|
||||
@ -308,7 +305,7 @@ abstract class CommonService
|
||||
}
|
||||
|
||||
//삭제용 (일반)
|
||||
protected function delete_process(string|int $uid): CommonEntity
|
||||
protected function delete_process(string|int $uid): object
|
||||
{
|
||||
if (!$uid) {
|
||||
throw new \Exception("삭제에 필요한 PrimaryKey 가 정의 되지 않았습니다.");
|
||||
@ -332,11 +329,10 @@ abstract class CommonService
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
final public function delete(string|int $uid): CommonEntity
|
||||
final public function delete(string|int $uid): object
|
||||
{
|
||||
$db = \Config\Database::connect();
|
||||
try {
|
||||
//트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정
|
||||
$db->transException(true)->transStart();
|
||||
$entity = $this->delete_process($uid);
|
||||
// 트랜잭션 완료 및 커밋
|
||||
@ -357,7 +353,7 @@ abstract class CommonService
|
||||
}
|
||||
|
||||
//삭제용 (배치 작업)
|
||||
protected function batchjob_delete_process(string|int $uid): CommonEntity
|
||||
protected function batchjob_delete_process(string|int $uid): object
|
||||
{
|
||||
// delete_process를 호출하여 로직 재사용 (CommonEntity 로드 및 유효성 검사)
|
||||
$entity = $this->delete_process($uid);
|
||||
@ -368,7 +364,6 @@ abstract class CommonService
|
||||
{
|
||||
$db = \Config\Database::connect();
|
||||
try {
|
||||
//트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정
|
||||
$db->transException(true)->transStart();
|
||||
//일괄작업처리
|
||||
$entities = [];
|
||||
|
||||
@ -101,30 +101,6 @@ class UserService extends CommonService
|
||||
{
|
||||
return $entity;
|
||||
}
|
||||
protected function create_process(array $formDatas): UserEntity
|
||||
{
|
||||
//confirmpassword 필드는 Entity에 필요없으므로 제거
|
||||
if (isset($formDatas['confirmpassword'])) {
|
||||
unset($formDatas['confirmpassword']);
|
||||
}
|
||||
$entity = parent::create_process($formDatas);
|
||||
if (!$entity instanceof UserEntity) {
|
||||
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능");
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
protected function modify_process($entity, array $formDatas): UserEntity
|
||||
{
|
||||
//confirmpassword 필드는 Entity에 필요없으므로 제거
|
||||
if (isset($formDatas['confirmpassword'])) {
|
||||
unset($formDatas['confirmpassword']);
|
||||
}
|
||||
$entity = parent::modify_process($entity, $formDatas);
|
||||
if (!$entity instanceof UserEntity) {
|
||||
throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 UserEntity만 가능");
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
//List 검색용
|
||||
//FormFilter 조건절 처리
|
||||
public function setFilter(string $field, mixed $filter_value): void
|
||||
|
||||
Loading…
Reference in New Issue
Block a user