diff --git a/app/Controllers/AbstractCRUDController.php b/app/Controllers/AbstractCRUDController.php index 26ed81b..d756dab 100644 --- a/app/Controllers/AbstractCRUDController.php +++ b/app/Controllers/AbstractCRUDController.php @@ -15,10 +15,7 @@ abstract class AbstractCRUDController extends AbstractWebController { // ๐Ÿ’ก ํ•ต์‹ฌ 1: ๊ฐ ์ž์‹ ํด๋ž˜์Šค๊ฐ€ ์‚ฌ์šฉํ•  Entity ํด๋ž˜์Šค ๊ฒฝ๋กœ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ๊ฐ•์ œ // ์ด ๋ฉ”์„œ๋“œ๋Š” ์ž์‹ ํด๋ž˜์Šค์—์„œ ๋ฐ˜๋“œ์‹œ ๊ตฌํ˜„๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. - abstract protected function getEntityClass(): string; - // --- ์ƒ์„ฑ (Create) --- - protected function create_form_process(array $formDatas = []): array { //์ดˆ๊ธฐ ๊ธฐ๋ณธ Default๊ฐ’ ์ง€์ • @@ -64,7 +61,7 @@ abstract class AbstractCRUDController extends AbstractWebController $this->action_init_process($action); $entity = $this->create_process(); // ๐Ÿ’ก ๋™์ ์œผ๋กœ ๊ฐ€์ ธ์˜จ Entity ํด๋ž˜์Šค ์ด๋ฆ„์œผ๋กœ instanceof ๊ฒ€์‚ฌ - $entityClass = $this->getEntityClass(); + $entityClass = $this->service->getEntityClass(); if (!$entity instanceof $entityClass) { throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ {$entityClass}๋งŒ ๊ฐ€๋Šฅ"); } @@ -97,7 +94,7 @@ abstract class AbstractCRUDController extends AbstractWebController try { $entity = $this->modify_form_process($uid); // ๐Ÿ’ก ๋™์ ์œผ๋กœ ๊ฐ€์ ธ์˜จ Entity ํด๋ž˜์Šค ์ด๋ฆ„์œผ๋กœ instanceof ๊ฒ€์‚ฌ - $entityClass = $this->getEntityClass(); + $entityClass = $this->service->getEntityClass(); if (!$entity instanceof $entityClass) { throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ {$entityClass}๋งŒ ๊ฐ€๋Šฅ"); } @@ -131,7 +128,7 @@ abstract class AbstractCRUDController extends AbstractWebController $this->action_init_process($action); $entity = $this->modify_process($uid); // ๐Ÿ’ก ๋™์ ์œผ๋กœ ๊ฐ€์ ธ์˜จ Entity ํด๋ž˜์Šค ์ด๋ฆ„์œผ๋กœ instanceof ๊ฒ€์‚ฌ - $entityClass = $this->getEntityClass(); + $entityClass = $this->service->getEntityClass(); if (!$entity instanceof $entityClass) { throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ {$entityClass}๋งŒ ๊ฐ€๋Šฅ"); } @@ -158,7 +155,7 @@ abstract class AbstractCRUDController extends AbstractWebController try { $entity = $this->delete_process($uid); // ๐Ÿ’ก ๋™์ ์œผ๋กœ ๊ฐ€์ ธ์˜จ Entity ํด๋ž˜์Šค ์ด๋ฆ„์œผ๋กœ instanceof ๊ฒ€์‚ฌ - $entityClass = $this->getEntityClass(); + $entityClass = $this->service->getEntityClass(); if (!$entity instanceof $entityClass) { throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ {$entityClass}๋งŒ ๊ฐ€๋Šฅ"); } @@ -194,7 +191,7 @@ abstract class AbstractCRUDController extends AbstractWebController $this->action_init_process($action); $entity = $this->view_process($uid); // ๐Ÿ’ก ๋™์ ์œผ๋กœ ๊ฐ€์ ธ์˜จ Entity ํด๋ž˜์Šค ์ด๋ฆ„์œผ๋กœ instanceof ๊ฒ€์‚ฌ - $entityClass = $this->getEntityClass(); + $entityClass = $this->service->getEntityClass(); if (!$entity instanceof $entityClass) { throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ {$entityClass}๋งŒ ๊ฐ€๋Šฅ"); } diff --git a/app/Controllers/Admin/BoardController.php b/app/Controllers/Admin/BoardController.php index 383fd11..7cab8a2 100644 --- a/app/Controllers/Admin/BoardController.php +++ b/app/Controllers/Admin/BoardController.php @@ -18,10 +18,6 @@ class BoardController extends AdminController $this->addActionPaths('board'); } //Action์ž‘์—…๊ด€๋ จ - protected function getEntityClass(): string - { - return BoardEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ public function latest(string $category): ResponseInterface diff --git a/app/Controllers/Admin/Customer/AccountController.php b/app/Controllers/Admin/Customer/AccountController.php index 378b2c1..8b36c9b 100644 --- a/app/Controllers/Admin/Customer/AccountController.php +++ b/app/Controllers/Admin/Customer/AccountController.php @@ -17,10 +17,6 @@ class AccountController extends CustomerController } $this->addActionPaths('account'); } - protected function getEntityClass(): string - { - return AccountEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Controllers/Admin/Customer/ClientController.php b/app/Controllers/Admin/Customer/ClientController.php index 1abf754..d17f56f 100644 --- a/app/Controllers/Admin/Customer/ClientController.php +++ b/app/Controllers/Admin/Customer/ClientController.php @@ -18,10 +18,6 @@ class ClientController extends CustomerController } $this->addActionPaths('client'); } - protected function getEntityClass(): string - { - return ClientEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ //๊ณ ๊ฐ ์ƒ์„ธ์ •๋ณด diff --git a/app/Controllers/Admin/Customer/CouponController.php b/app/Controllers/Admin/Customer/CouponController.php index 2724177..a62154a 100644 --- a/app/Controllers/Admin/Customer/CouponController.php +++ b/app/Controllers/Admin/Customer/CouponController.php @@ -17,10 +17,6 @@ class CouponController extends CustomerController } $this->addActionPaths('coupon'); } - protected function getEntityClass(): string - { - return CouponEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Controllers/Admin/Customer/PointController.php b/app/Controllers/Admin/Customer/PointController.php index 3bcefe4..4b537a0 100644 --- a/app/Controllers/Admin/Customer/PointController.php +++ b/app/Controllers/Admin/Customer/PointController.php @@ -17,10 +17,6 @@ class PointController extends CustomerController } $this->addActionPaths('point'); } - protected function getEntityClass(): string - { - return PointEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Controllers/Admin/Customer/ServiceController.php b/app/Controllers/Admin/Customer/ServiceController.php index 2dabcdd..b42833d 100644 --- a/app/Controllers/Admin/Customer/ServiceController.php +++ b/app/Controllers/Admin/Customer/ServiceController.php @@ -19,10 +19,6 @@ class ServiceController extends CustomerController $this->addActionPaths('service'); $this->layouts['javascripts'][] = ''; } - protected function getEntityClass(): string - { - return ServiceEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ public function create_form_process(array $formDatas = []): array diff --git a/app/Controllers/Admin/Equipment/LineController.php b/app/Controllers/Admin/Equipment/LineController.php index 19cfbbe..78541f6 100644 --- a/app/Controllers/Admin/Equipment/LineController.php +++ b/app/Controllers/Admin/Equipment/LineController.php @@ -18,10 +18,6 @@ class LineController extends EquipmentController } $this->addActionPaths('line'); } - protected function getEntityClass(): string - { - return LineEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Controllers/Admin/Equipment/ServerController.php b/app/Controllers/Admin/Equipment/ServerController.php index 32d7a2f..d5a8e52 100644 --- a/app/Controllers/Admin/Equipment/ServerController.php +++ b/app/Controllers/Admin/Equipment/ServerController.php @@ -19,10 +19,6 @@ class ServerController extends EquipmentController $this->addActionPaths('server'); $this->layouts['javascripts'][] = ''; } - protected function getEntityClass(): string - { - return ServerEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ public function create_form_process(array $formDatas = []): array diff --git a/app/Controllers/Admin/Equipment/ServerPartController.php b/app/Controllers/Admin/Equipment/ServerPartController.php index dcd6cd3..e43e18d 100644 --- a/app/Controllers/Admin/Equipment/ServerPartController.php +++ b/app/Controllers/Admin/Equipment/ServerPartController.php @@ -17,10 +17,6 @@ class ServerPartController extends EquipmentController } $this->addActionPaths('serverpart'); } - protected function getEntityClass(): string - { - return ServerPartEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ protected function create_form_process(array $formDatas = []): array diff --git a/app/Controllers/Admin/MylogController.php b/app/Controllers/Admin/MylogController.php index 1b9857e..366426e 100644 --- a/app/Controllers/Admin/MylogController.php +++ b/app/Controllers/Admin/MylogController.php @@ -17,10 +17,6 @@ class MylogController extends AdminController } $this->addActionPaths('mylog'); } - protected function getEntityClass(): string - { - return MylogEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Controllers/Admin/Part/CPUController.php b/app/Controllers/Admin/Part/CPUController.php index dda0192..96d14ff 100644 --- a/app/Controllers/Admin/Part/CPUController.php +++ b/app/Controllers/Admin/Part/CPUController.php @@ -17,10 +17,6 @@ class CPUController extends PartController } $this->addActionPaths('cpu'); } - protected function getEntityClass(): string - { - return CPUEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Controllers/Admin/Part/CSController.php b/app/Controllers/Admin/Part/CSController.php index fbb9f8f..527a27f 100644 --- a/app/Controllers/Admin/Part/CSController.php +++ b/app/Controllers/Admin/Part/CSController.php @@ -17,10 +17,6 @@ class CSController extends PartController } $this->addActionPaths('cs'); } - protected function getEntityClass(): string - { - return CSEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Controllers/Admin/Part/DISKController.php b/app/Controllers/Admin/Part/DISKController.php index a4b5734..b5be075 100644 --- a/app/Controllers/Admin/Part/DISKController.php +++ b/app/Controllers/Admin/Part/DISKController.php @@ -17,10 +17,6 @@ class DISKController extends PartController } $this->addActionPaths('disk'); } - protected function getEntityClass(): string - { - return DISKEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Controllers/Admin/Part/IPController.php b/app/Controllers/Admin/Part/IPController.php index 2b2db53..a3a7365 100644 --- a/app/Controllers/Admin/Part/IPController.php +++ b/app/Controllers/Admin/Part/IPController.php @@ -17,10 +17,6 @@ class IPController extends PartController } $this->addActionPaths('ip'); } - protected function getEntityClass(): string - { - return IPEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Controllers/Admin/Part/RAMController.php b/app/Controllers/Admin/Part/RAMController.php index 10c5f7e..7c68fa6 100644 --- a/app/Controllers/Admin/Part/RAMController.php +++ b/app/Controllers/Admin/Part/RAMController.php @@ -17,10 +17,6 @@ class RAMController extends PartController } $this->addActionPaths('ram'); } - protected function getEntityClass(): string - { - return RAMEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Controllers/Admin/Part/SOFTWAREController.php b/app/Controllers/Admin/Part/SOFTWAREController.php index 970d527..6f41b0f 100644 --- a/app/Controllers/Admin/Part/SOFTWAREController.php +++ b/app/Controllers/Admin/Part/SOFTWAREController.php @@ -17,10 +17,6 @@ class SOFTWAREController extends PartController } $this->addActionPaths('software'); } - protected function getEntityClass(): string - { - return SOFTWAREEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Controllers/Admin/Part/SWITCHController.php b/app/Controllers/Admin/Part/SWITCHController.php index cd346bb..4fad598 100644 --- a/app/Controllers/Admin/Part/SWITCHController.php +++ b/app/Controllers/Admin/Part/SWITCHController.php @@ -17,10 +17,6 @@ class SWITCHController extends PartController } $this->addActionPaths('switch'); } - protected function getEntityClass(): string - { - return SWITCHEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Controllers/Admin/PaymentController.php b/app/Controllers/Admin/PaymentController.php index 252cc4c..17884e1 100644 --- a/app/Controllers/Admin/PaymentController.php +++ b/app/Controllers/Admin/PaymentController.php @@ -21,10 +21,6 @@ class PaymentController extends AdminController $this->addActionPaths('payment'); } //Action์ž‘์—…๊ด€๋ จ - protected function getEntityClass(): string - { - return PaymentEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ //์ผํšŒ์„ฑ ์ถ”๊ฐ€์šฉ diff --git a/app/Controllers/Admin/SearchController.php b/app/Controllers/Admin/SearchController.php index 0f9a35f..b3cab2d 100644 --- a/app/Controllers/Admin/SearchController.php +++ b/app/Controllers/Admin/SearchController.php @@ -18,10 +18,6 @@ class SearchController extends AdminController $this->addActionPaths('service'); } //Action์ž‘์—…๊ด€๋ จ - protected function getEntityClass(): string - { - return ServiceEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ protected function index_entities_process(array $entities = []): array diff --git a/app/Controllers/Admin/UserController.php b/app/Controllers/Admin/UserController.php index 3a4810c..2133e3a 100644 --- a/app/Controllers/Admin/UserController.php +++ b/app/Controllers/Admin/UserController.php @@ -18,10 +18,6 @@ class UserController extends AdminController $this->addActionPaths('user'); } //Action์ž‘์—…๊ด€๋ จ - protected function getEntityClass(): string - { - return UserEntity::class; - } //๊ธฐ๋ณธ ํ•จ์ˆ˜ ์ž‘์—… //Custom ์ถ”๊ฐ€ ํ•จ์ˆ˜ } diff --git a/app/Entities/Part/CPUEntity.php b/app/Entities/Part/CPUEntity.php index c2fb329..f06a181 100644 --- a/app/Entities/Part/CPUEntity.php +++ b/app/Entities/Part/CPUEntity.php @@ -9,15 +9,15 @@ class CPUEntity extends PartEntity const PK = CPUModel::PK; const TITLE = CPUModel::TITLE; //๊ธฐ๋ณธ๊ธฐ๋Šฅ - final public function getUsed(): int - { - return $this->attributes['used']; - } - final public function getStock(): int + public function getStock(): int { return $this->attributes['stock']; } - final public function getAvailable(): int + public function getUsed(): int + { + return $this->attributes['used']; + } + public function getAvailable(): int { return $this->getStock() - $this->getUsed(); } diff --git a/app/Entities/Part/CSEntity.php b/app/Entities/Part/CSEntity.php index c90f625..bee94fb 100644 --- a/app/Entities/Part/CSEntity.php +++ b/app/Entities/Part/CSEntity.php @@ -22,4 +22,13 @@ class CSEntity extends PartEntity { return $this->attributes['domain'] ?? null; } + //abstract ์„ ์–ธ์ฒ˜๋ฆฌ์šฉ + public function getUsed(): int + { + return 0; + } + public function getAvailable(): int + { + return 0; + } } diff --git a/app/Entities/Part/DISKEntity.php b/app/Entities/Part/DISKEntity.php index 71ef342..32e63c4 100644 --- a/app/Entities/Part/DISKEntity.php +++ b/app/Entities/Part/DISKEntity.php @@ -9,11 +9,7 @@ class DISKEntity extends PartEntity const PK = DISKModel::PK; const TITLE = DISKModel::TITLE; //๊ธฐ๋ณธ๊ธฐ๋Šฅ - final public function getUsed(): int - { - return $this->attributes['used']; - } - final public function getStock(): int + public function getStock(): int { return $this->attributes['stock']; } @@ -21,7 +17,11 @@ class DISKEntity extends PartEntity { return intval($this->attributes['format'] ?? 0); } - final public function getAvailable(): int + public function getUsed(): int + { + return $this->attributes['used']; + } + public function getAvailable(): int { return $this->getStock() - $this->getUsed() - $this->getFormat(); } diff --git a/app/Entities/Part/IPEntity.php b/app/Entities/Part/IPEntity.php index df57edf..9f342fd 100644 --- a/app/Entities/Part/IPEntity.php +++ b/app/Entities/Part/IPEntity.php @@ -8,11 +8,11 @@ class IPEntity extends PartEntity { const PK = IPModel::PK; const TITLE = IPModel::TITLE; - final public function getLineInfoUID(): int|null + public function getLineInfoUID(): int|null { return $this->attributes['lineinfo_uid'] ?? null; } - final public function getOldClientInfoUID(): int|null + public function getOldClientInfoUID(): int|null { return $this->attributes['old_clientinfo_uid'] ?? null; } @@ -21,4 +21,13 @@ class IPEntity extends PartEntity { return $this->attributes['ip']; } + //abstract ์„ ์–ธ์ฒ˜๋ฆฌ์šฉ + public function getUsed(): int + { + return 0; + } + public function getAvailable(): int + { + return 0; + } } diff --git a/app/Entities/Part/PartEntity.php b/app/Entities/Part/PartEntity.php index b51531b..e242a2b 100644 --- a/app/Entities/Part/PartEntity.php +++ b/app/Entities/Part/PartEntity.php @@ -10,6 +10,8 @@ abstract class PartEntity extends CommonEntity { parent::__construct($data); } + abstract public function getAvailable(): int; + abstract public function getUsed(): int; final public function getClientInfoUID(): int|null { return $this->attributes['clientinfo_uid']; diff --git a/app/Entities/Part/RAMEntity.php b/app/Entities/Part/RAMEntity.php index 7d36257..70a1316 100644 --- a/app/Entities/Part/RAMEntity.php +++ b/app/Entities/Part/RAMEntity.php @@ -9,15 +9,15 @@ class RAMEntity extends PartEntity const PK = RAMModel::PK; const TITLE = RAMModel::TITLE; //๊ธฐ๋ณธ๊ธฐ๋Šฅ - final public function getUsed(): int - { - return $this->attributes['used']; - } - final public function getStock(): int + public function getStock(): int { return $this->attributes['stock']; } - final public function getAvailable(): int + public function getUsed(): int + { + return $this->attributes['used']; + } + public function getAvailable(): int { return $this->getStock() - $this->getUsed(); } diff --git a/app/Entities/Part/SOFTWAREEntity.php b/app/Entities/Part/SOFTWAREEntity.php index 2d9ec46..5d66d14 100644 --- a/app/Entities/Part/SOFTWAREEntity.php +++ b/app/Entities/Part/SOFTWAREEntity.php @@ -9,15 +9,15 @@ class SOFTWAREEntity extends PartEntity const PK = SOFTWAREModel::PK; const TITLE = SOFTWAREModel::TITLE; //๊ธฐ๋ณธ๊ธฐ๋Šฅ - final public function getUsed(): int - { - return $this->attributes['used']; - } - final public function getStock(): int + public function getStock(): int { return $this->attributes['stock']; } - final public function getAvailable(): int + public function getUsed(): int + { + return $this->attributes['used']; + } + public function getAvailable(): int { return $this->getStock() - $this->getUsed(); } diff --git a/app/Entities/Part/SWITCHEntity.php b/app/Entities/Part/SWITCHEntity.php index beb334e..cd2d263 100644 --- a/app/Entities/Part/SWITCHEntity.php +++ b/app/Entities/Part/SWITCHEntity.php @@ -8,8 +8,17 @@ class SWITCHEntity extends PartEntity { const PK = SWITCHModel::PK; const TITLE = SWITCHModel::TITLE; - final public function getCode(): string + public function getCode(): string { return $this->attributes['code'] ?? ""; } + //abstract ์„ ์–ธ์ฒ˜๋ฆฌ์šฉ + public function getUsed(): int + { + return 0; + } + public function getAvailable(): int + { + return 0; + } } diff --git a/app/Services/BoardService.php b/app/Services/BoardService.php index 47f40e1..aa2c004 100644 --- a/app/Services/BoardService.php +++ b/app/Services/BoardService.php @@ -7,6 +7,7 @@ use App\Entities\BoardEntity; use App\Forms\BoardForm; use App\Helpers\BoardHelper; use App\Models\BoardModel; +use RuntimeException; class BoardService extends CommonService { @@ -25,6 +26,10 @@ class BoardService extends CommonService { return new BoardDTO($formDatas); } + public function getEntityClass(): string + { + return BoardEntity::class; + } public function getFormService(): BoardForm { if ($this->_form === null) { @@ -122,11 +127,19 @@ class BoardService extends CommonService } protected function create_process(array $formDatas): BoardEntity { - return new BoardEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof BoardEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ BoardEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): BoardEntity { - return parent::modify_process($uid, $formDatas); + $entity = parent::modify_process($uid, $formDatas); + if (!$entity instanceof BoardEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ BoardEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } //List ๊ฒ€์ƒ‰์šฉ //FormFilter ์กฐ๊ฑด์ ˆ ์ฒ˜๋ฆฌ diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 5569321..cb146b6 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -18,8 +18,10 @@ abstract class CommonService private array $_classPaths = []; protected $title = null; protected function __construct(protected CommonModel $model) {} + abstract public function action_init_process(string $action, array $formDatas = []): void; abstract protected function getDTOClass(): string; abstract public function createDTO(array $formDatas): CommonDTO; + abstract public function getEntityClass(): string; abstract public function getFormService(): mixed; abstract public function getHelper(): mixed; final protected function addClassPaths(string $path): void @@ -30,12 +32,17 @@ abstract class CommonService { return $isArray ? $this->_classPaths : implode($delimeter, $this->_classPaths); } - abstract public function action_init_process(string $action, array $formDatas = []): void; + final public function getNextPK(): int + { + $pkField = $this->model->getPKField(); + $row = $this->model->selectMax($pkField)->get()->getRow(); + return isset($row->{$pkField}) ? ((int)$row->{$pkField} + 1) : 1; + } /** * ๋‹จ์ผ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค. * @return CommonEntity|null CommonEntity ์ธ์Šคํ„ด์Šค ๋˜๋Š” ์ฐพ์ง€ ๋ชปํ–ˆ์„ ๊ฒฝ์šฐ null */ - final public function getEntity(string|int|array $where, ?string $message = null): ?CommonEntity + public function getEntity(string|int|array $where, ?string $message = null): ?CommonEntity { try { $entity = is_array($where) ? $this->model->where($where)->first() : $this->model->find($where); @@ -64,7 +71,7 @@ abstract class CommonService throw new \Exception($errorMessage, $e->getCode(), $e); } } - final public function getEntities(?array $where = null, array $columns = ['*']): array + public function getEntities(?array $where = null, array $columns = ['*']): array { try { $entities = $this->getEntities_process($where, $columns); @@ -88,13 +95,6 @@ abstract class CommonService throw new \Exception($errorMessage, $e->getCode(), $e); } } - final public function getNextPK(): int - { - $pkField = $this->model->getPKField(); - $row = $this->model->selectMax($pkField)->get()->getRow(); - return isset($row->{$pkField}) ? ((int)$row->{$pkField} + 1) : 1; - } - //Entity๊ด€๋ จ protected function getEntity_process(CommonEntity $entity): CommonEntity { @@ -153,16 +153,23 @@ abstract class CommonService // INSERT ์‹œ Entity์˜ PK๋Š” 0 ๋˜๋Š” NULL์ด์–ด์•ผ ํ•จ (DB๊ฐ€ ID๋ฅผ ์ƒ์„ฑํ•˜๋„๋ก) $initialPK = $entity->getPK(); $result = $this->model->save($entity); - // ์ตœ์ข…์ ์œผ๋กœ DB์— ๋ฐ˜์˜๋œ PK๋ฅผ ๋ฐ˜ํ™˜๋ฐ›์Šต๋‹ˆ๋‹ค. (UPDATE์ด๋ฉด ๊ธฐ์กด PK, INSERT์ด๋ฉด ์ƒˆ PK) $finalPK = $this->handle_save_result($result, $initialPK); - // handle_save_result์—์„œ ํ™•์ธ๋œ ์ตœ์ข… PK๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ DB์—์„œ ์ตœ์‹  ์—”ํ‹ฐํ‹ฐ๋ฅผ ๊ฐ€์ ธ์˜ด return $this->getEntity($finalPK); } //์ƒ์„ฑ์šฉ - abstract protected function create_process(array $formDatas): CommonEntity; + protected function create_process(array $formDatas): CommonEntity + { + // ๐Ÿ’ก ๋™์ ์œผ๋กœ ๊ฐ€์ ธ์˜จ Entity ํด๋ž˜์Šค ์ด๋ฆ„์œผ๋กœ instanceof ๊ฒ€์‚ฌ + $entityClass = $this->getEntityClass(); + $entity = new $entityClass($formDatas); + if (!$entity instanceof $entityClass) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ {$entityClass}๋งŒ ๊ฐ€๋Šฅ"); + } + return $this->save_process($entity); + } final public function create(object $dto): CommonEntity { //DTO ํƒ€์ž… ์ฒดํฌ ๋กœ์ง์„ ์ผ๋ฐ˜ํ™” @@ -170,15 +177,13 @@ abstract class CommonService if (!$dto instanceof $dtoClass) { throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: " . get_class($dto) . "๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ({$dtoClass} ํ•„์š”)"); } - $formDatas = $dto->toArray(); if (!$this->getFormService()->validate($formDatas)) { throw new ValidationException(implode("\n", service('validation')->getErrors())); } // NOTE: create_process์—์„œ ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ƒ์„ฑํ•  ๋•Œ, ์ž๋™ ์ฆ๊ฐ€(AUTO_INCREMENT) ํ•„๋“œ๋Š” // DB๊ฐ€ ์ฒ˜๋ฆฌํ•˜๋„๋ก NULL์ด๋‚˜ ๋นˆ ๊ฐ’(0)์œผ๋กœ ๋‘๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ ์ž…๋‹ˆ๋‹ค. - $entity = $this->create_process($formDatas); - return $this->save_process($entity); + return $this->create_process($formDatas); } //์ˆ˜์ •์šฉ @@ -188,17 +193,13 @@ abstract class CommonService if (!$entity) { throw new \Exception(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: {$uid}์— ํ•ด๋‹นํ•˜๋Š” ์ •๋ณด์„ ์ฐพ์„์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); } - $pkField = $this->model->getPKField(); - // DTO ๋ฐ์ดํ„ฐ์—์„œ PK ํ•„๋“œ๊ฐ€ ์žˆ๋‹ค๋ฉด ์ œ๊ฑฐํ•˜์—ฌ, fill()์—์„œ ๊ธฐ์กด PK๋ฅผ ๋ฎ์–ด์“ฐ์ง€ ์•Š๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. if (isset($formDatas[$pkField])) { unset($formDatas[$pkField]); } - // 1. ๋ฐ์ดํ„ฐ๋ฅผ Entity์— ์ฑ„์›๋‹ˆ๋‹ค. $entity->fill($formDatas); - // 2. (ํ•ต์‹ฌ ๋ฐฉ์–ด) fill() ์ž‘์—…์ด Entity์˜ PK๋ฅผ ํ›ผ์†ํ–ˆ๋”๋ผ๋„, // ๊ธฐ์กด $uid ๊ฐ’์„ ์‚ฌ์šฉํ•˜์—ฌ Entity์˜ PK๋ฅผ ๊ฐ•์ œ๋กœ ๋ณต์›ํ•ฉ๋‹ˆ๋‹ค. // ์ด๊ฒƒ์ด Model::save()๊ฐ€ UPDATE๋ฅผ ์‹คํ–‰ํ•˜๋„๋ก ๋ณด์žฅํ•˜๋Š” ์ตœ์ข… ๋ฐฉ์–ด์„ ์ž…๋‹ˆ๋‹ค. @@ -207,10 +208,8 @@ abstract class CommonService log_message('warning', "modify_process: Entity PK ํ›ผ์† ๊ฐ์ง€. '{$currentPK}' ๋Œ€์‹  ์›๋ณธ UID '{$uid}'๋กœ ๊ฐ•์ œ ๋ณต์›."); $entity->{$pkField} = $uid; } - log_message('debug', "save_process ์ง„์ž… ์ „ Entity PK: " . $entity->getPK() . " (๊ธฐ๋Œ€๊ฐ’: {$uid})"); - - return $entity; + return $this->save_process($entity); } final public function modify(string|int $uid, object $dto): CommonEntity { @@ -219,13 +218,11 @@ abstract class CommonService if (!$dto instanceof $dtoClass) { throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: " . get_class($dto) . "๋Š” ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ({$dtoClass} ํ•„์š”)"); } - $formDatas = $dto->toArray(); if (!$this->getFormService()->validate($formDatas)) { throw new ValidationException(implode("\n", service('validation')->getErrors())); } - $entity = $this->modify_process($uid, $formDatas); - return $this->save_process($entity); + return $this->modify_process($uid, $formDatas); } //๋ฐฐ์น˜ ์ž‘์—…์šฉ ์ˆ˜์ • @@ -247,8 +244,7 @@ abstract class CommonService if (!$this->getFormService()->validate($formDatas)) { throw new ValidationException(implode("\n", service('validation')->getErrors())); } - $entity = $this->batchjob_process($uid, $formDatas); - return $this->save_process($entity); + return $this->batchjob_process($uid, $formDatas); } //์‚ญ์ œ์šฉ (์ผ๋ฐ˜) @@ -287,7 +283,6 @@ abstract class CommonService final public function batchjob_delete(string|int $uid): CommonEntity { $entity = $this->batchjob_delete_process($uid); - $result = $this->model->delete($entity->getPK()); log_message('debug', $this->model->getLastQuery()); if ($result === false) { diff --git a/app/Services/Customer/AccountService.php b/app/Services/Customer/AccountService.php index ac1bca0..3c4d8b9 100644 --- a/app/Services/Customer/AccountService.php +++ b/app/Services/Customer/AccountService.php @@ -26,6 +26,10 @@ class AccountService extends CustomerService { return new AccountDTO($formDatas); } + public function getEntityClass(): string + { + return AccountEntity::class; + } public function getFormService(): AccountForm { if ($this->_form === null) { @@ -112,7 +116,11 @@ class AccountService extends CustomerService } protected function create_process(array $formDatas): AccountEntity { - return new AccountEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof AccountEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ AccountEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): AccountEntity { diff --git a/app/Services/Customer/ClientService.php b/app/Services/Customer/ClientService.php index 97a1413..2fa2aa6 100644 --- a/app/Services/Customer/ClientService.php +++ b/app/Services/Customer/ClientService.php @@ -26,6 +26,10 @@ class ClientService extends CustomerService { return new ClientDTO($formDatas); } + public function getEntityClass(): string + { + return ClientEntity::class; + } public function getFormService(): ClientForm { if ($this->_form === null) { @@ -112,7 +116,11 @@ class ClientService extends CustomerService } protected function create_process(array $formDatas): ClientEntity { - return new ClientEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof ClientEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ ClientEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): ClientEntity { diff --git a/app/Services/Customer/CouponService.php b/app/Services/Customer/CouponService.php index 2688630..d5a1542 100644 --- a/app/Services/Customer/CouponService.php +++ b/app/Services/Customer/CouponService.php @@ -26,6 +26,10 @@ class CouponService extends CustomerService { return new CouponDTO($formDatas); } + public function getEntityClass(): string + { + return CouponEntity::class; + } public function getFormService(): CouponForm { if ($this->_form === null) { @@ -103,7 +107,11 @@ class CouponService extends CustomerService } protected function create_process(array $formDatas): CouponEntity { - return new CouponEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof CouponEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ CouponEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): CouponEntity { diff --git a/app/Services/Customer/PointService.php b/app/Services/Customer/PointService.php index 544ac0a..a7cf1bd 100644 --- a/app/Services/Customer/PointService.php +++ b/app/Services/Customer/PointService.php @@ -26,6 +26,10 @@ class PointService extends CustomerService { return new PointDTO($formDatas); } + public function getEntityClass(): string + { + return PointEntity::class; + } public function getFormService(): PointForm { if ($this->_form === null) { @@ -103,7 +107,11 @@ class PointService extends CustomerService } protected function create_process(array $formDatas): PointEntity { - return new PointEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof PointEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ PointEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): PointEntity { diff --git a/app/Services/Customer/ServiceService.php b/app/Services/Customer/ServiceService.php index 60307eb..ca42884 100644 --- a/app/Services/Customer/ServiceService.php +++ b/app/Services/Customer/ServiceService.php @@ -28,6 +28,10 @@ class ServiceService extends CustomerService { return new ServiceDTO($formDatas); } + public function getEntityClass(): string + { + return ServiceEntity::class; + } public function getFormService(): ServiceForm { if ($this->_form === null) { @@ -129,7 +133,11 @@ class ServiceService extends CustomerService } protected function create_process(array $formDatas): ServiceEntity { - return new ServiceEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof ServiceEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ ServiceEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): ServiceEntity { diff --git a/app/Services/Equipment/LineService.php b/app/Services/Equipment/LineService.php index 90012c1..99ce2bc 100644 --- a/app/Services/Equipment/LineService.php +++ b/app/Services/Equipment/LineService.php @@ -26,6 +26,10 @@ class LineService extends EquipmentService { return new LineDTO($formDatas); } + public function getEntityClass(): string + { + return LineEntity::class; + } public function getFormService(): LineForm { if ($this->_form === null) { @@ -98,7 +102,11 @@ class LineService extends EquipmentService } protected function create_process(array $formDatas): LineEntity { - return new LineEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof LineEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ LineEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): LineEntity { diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index 26e8a23..c0fc70b 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -3,12 +3,13 @@ namespace App\Services\Equipment; use App\DTOs\Equipment\ServerPartDTO; -use App\DTOs\UserDTO; +use App\Entities\Equipment\ServerEntity; use App\Entities\Equipment\ServerPartEntity; +use App\Entities\Part\PartEntity; use App\Forms\Equipment\ServerPartForm; use App\Helpers\Equipment\ServerPartHelper; use App\Models\Equipment\ServerPartModel; -use App\Services\CommonService; +use App\Services\Part\PartService; use RuntimeException; class ServerPartService extends EquipmentService @@ -28,6 +29,10 @@ class ServerPartService extends EquipmentService { return new ServerPartDTO($formDatas); } + public function getEntityClass(): string + { + return ServerPartEntity::class; + } public function getFormService(): ServerPartForm { if ($this->_form === null) { @@ -100,33 +105,40 @@ class ServerPartService extends EquipmentService $this->getFormService()->setIndexFilters($indexFilter); $this->getFormService()->setBatchjobFilters($batchjobFilters); } - //๊ธฐ๋ณธ ๊ธฐ๋Šฅ๋ถ€๋ถ„ - private function getPartService(string $type): CommonService + //๊ฐ ํŒŒํŠธ๋ณ„ ์„œ๋น„์Šค + private function getPartService(string $type): PartService { return service('part_' . strtolower($type) . 'service'); } + //๊ธฐ๋ณธ ๊ธฐ๋Šฅ๋ถ€๋ถ„ protected function getEntity_process(mixed $entity): ServerPartEntity { return $entity; } protected function create_process(array $formDatas): ServerPartEntity { - if (!array_key_exists('title', $formDatas)) { - if (!array_key_exists('type', $formDatas)) { - throw new \Exception(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:๋ถ€ํ’ˆํ˜•์‹์ด ์ง€์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."); - } - $formDatas['title'] = $this->getPartService($formDatas['type']->getTitle()); + if (!array_key_exists('type', $formDatas)) { + throw new \Exception(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:๋ถ€ํ’ˆํ˜•์‹์ด ์ง€์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."); } - return new ServerPartEntity($formDatas); + //๊ฐ ํŒŒํŠธ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ + $partEntity = $this->getPartService($formDatas['type'])->getEntity($formDatas['part_uid']); + //์„œ๋ฒ„ํŒŒํŠธ์ •๋ณด Title ์„ค์ •์šฉ + $formDatas['title'] = $partEntity->getTitle(); + $entity = parent::create_process($formDatas); + if (!$entity instanceof ServerPartEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ ServerPartEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): ServerPartEntity { - if (!array_key_exists('title', $formDatas)) { - if (!array_key_exists('type', $formDatas)) { - throw new \Exception(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:๋ถ€ํ’ˆํ˜•์‹์ด ์ง€์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."); - } - $formDatas['title'] = $this->getPartService($formDatas['type']->getTitle()); + if (!array_key_exists('type', $formDatas)) { + throw new \Exception(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:๋ถ€ํ’ˆํ˜•์‹์ด ์ง€์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."); } + //๊ฐ ํŒŒํŠธ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ + $partEntity = $this->getPartService($formDatas['type'])->getEntity($formDatas['part_uid']); + //์„œ๋ฒ„ํŒŒํŠธ์ •๋ณด Title ์„ค์ •์šฉ + $formDatas['title'] = $partEntity->getTitle(); $entity = parent::modify_process($uid, $formDatas); if (!$entity instanceof ServerPartEntity) { throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ ServerPartEntity๋งŒ ๊ฐ€๋Šฅ"); @@ -136,4 +148,34 @@ class ServerPartService extends EquipmentService //List ๊ฒ€์ƒ‰์šฉ //FormFilter ์กฐ๊ฑด์ ˆ ์ฒ˜๋ฆฌ //๊ฒ€์ƒ‰์–ด์กฐ๊ฑด์ ˆ์ฒ˜๋ฆฌ + + //์„œ๋ฒ„์ถ”๊ฐ€์‹œ ์„œ๋ฒ„ํŒŒํŠธ ์ž๋™์ถ”๊ฐ€์šฉ + public function attachToServer(ServerEntity $serverEntity): void + { + //*์„œ๋ฒ„์˜ Title ๋Œ€์†Œ๋ฌธ์ž๊ตฌ๋ถ„ ํ•„์š”->์„œ๋ฒ„์˜ Title๋กœ ๊ตฌ๋ถ„ํ•ด์„œ ๊ธฐ๋ณธ๋ถ€ํ’ˆ ์ถ”๊ฐ€ + foreach (SERVERPART['SERVER_PARTTYPES'] as $parttype) { + //ํ•ด๋‹น server_type์˜ ์ •์˜๋œ ์ƒ์ˆ˜๊ฐ’์ด ์žˆ์œผ๋ฉด + if (array_key_exists($serverEntity->getTitle(), SERVERPART[$parttype])) { + foreach (SERVERPART[$parttype][$serverEntity->getTitle()] as $part) { + //ํ•ด๋‹น ํŒŒํŠธ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ + $partEntity = $this->getPartService($parttype)->getEntity($part['UID']); + if (!$partEntity instanceof PartEntity) { + throw new \Exception(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: {$part['UID']} ์„œ๋ฒ„ ์ •๋ณด๋ฅผ ์ฐพ์„์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + } + //์„œ๋ฒ„ํŒŒํŠธ์ •๋ณด ์ƒ์„ฑ + $formDatas = []; + $formDatas['serverinfo_uid'] = $serverEntity->getPK(); + $formDatas["part_uid"] = $partEntity->getPK(); + $formDatas['billing'] = PAYMENT['BILLING']['BASE']; + $formDatas['type'] = $parttype; + $formDatas['title'] = $partEntity->getTitle(); //ํŒŒํŠธ ์ œ๋ชฉ + $formDatas['amount'] = $partEntity->getPrice(); //ํŒŒํŠธ ๊ธˆ์•ก + $formDatas['cnt'] = $part["CNT"]; + $formDatas['extra'] = $part["EXTRA"]; + $entity = $this->model->create($formDatas); + $this->getPartService($entity->getType())->attachToServerPart($entity); + } + } + } + } } diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 7055cbf..49002fd 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -26,6 +26,10 @@ class ServerService extends EquipmentService { return new ServerDTO($formDatas); } + public function getEntityClass(): string + { + return ServerEntity::class; + } public function getFormService(): ServerForm { if ($this->_form === null) { @@ -120,7 +124,13 @@ class ServerService extends EquipmentService } protected function create_process(array $formDatas): ServerEntity { - return new ServerEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof ServerEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ ServerEntity๋งŒ ๊ฐ€๋Šฅ"); + } + //์„œ๋ฒ„์ถ”๊ฐ€์‹œ ์„œ๋ฒ„ํŒŒํŠธ ์ž๋™์ถ”๊ฐ€์šฉ + service('equipment_serverpartservice')->attachToServer($entity); + return $entity; } protected function modify_process($uid, array $formDatas): ServerEntity { diff --git a/app/Services/MylogService.php b/app/Services/MylogService.php index 6e83282..996f6df 100644 --- a/app/Services/MylogService.php +++ b/app/Services/MylogService.php @@ -28,6 +28,10 @@ class MylogService extends CommonService implements PipelineStepInterface { return new MylogDTO($formDatas); } + public function getEntityClass(): string + { + return MylogEntity::class; + } public function getFormService(): MylogForm { if ($this->_form === null) { @@ -113,10 +117,18 @@ class MylogService extends CommonService implements PipelineStepInterface } protected function create_process(array $formDatas): MylogEntity { - return new MylogEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof MylogEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ MylogEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } - protected function modify_process($uid, array $formDatas): MyLogEntity + protected function modify_process($uid, array $formDatas): MylogEntity { - return parent::modify_process($uid, $formDatas); + $entity = parent::modify_process($uid, $formDatas); + if (!$entity instanceof MylogEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ MylogEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } } diff --git a/app/Services/Part/CPUService.php b/app/Services/Part/CPUService.php index 71769ba..8754c46 100644 --- a/app/Services/Part/CPUService.php +++ b/app/Services/Part/CPUService.php @@ -26,6 +26,10 @@ class CPUService extends PartService { return new CPUDTO($formDatas); } + public function getEntityClass(): string + { + return CPUEntity::class; + } public function getFormService(): CPUForm { if ($this->_form === null) { @@ -95,7 +99,11 @@ class CPUService extends PartService } protected function create_process(array $formDatas): CPUEntity { - return new CPUEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof CPUEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ CPUEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): CPUEntity { @@ -108,4 +116,10 @@ class CPUService extends PartService //List ๊ฒ€์ƒ‰์šฉ //FormFilter ์กฐ๊ฑด์ ˆ ์ฒ˜๋ฆฌ //๊ฒ€์ƒ‰์–ด์กฐ๊ฑด์ ˆ์ฒ˜๋ฆฌ + //OrderBy ์ฒ˜๋ฆฌ + public function setOrderBy(mixed $field = null, mixed $value = null): void + { + $this->model->orderBy('title ASC'); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Part/CSService.php b/app/Services/Part/CSService.php index b905445..ad89125 100644 --- a/app/Services/Part/CSService.php +++ b/app/Services/Part/CSService.php @@ -3,6 +3,7 @@ namespace App\Services\Part; use App\DTOs\Part\CSDTO; +use App\Entities\Equipment\ServerPartEntity; use App\Entities\Part\CSEntity; use App\Forms\Part\CSForm; use App\Helpers\Part\CSHelper; @@ -26,6 +27,10 @@ class CSService extends PartService { return new CSDTO($formDatas); } + public function getEntityClass(): string + { + return CSEntity::class; + } public function getFormService(): CSForm { if ($this->_form === null) { @@ -122,7 +127,11 @@ class CSService extends PartService } protected function create_process(array $formDatas): CSEntity { - return new CSEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof CSEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ CSEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): CSEntity { @@ -141,4 +150,49 @@ class CSService extends PartService $this->model->orderBy("INET_ATON(ip) ASC"); parent::setOrderBy($field, $value); } + + //์„œ๋ฒ„ํŒŒํŠธ๊ด€๋ จ ์ž‘์—… + public function attachToServerPart(ServerPartEntity $serverPartEntity): CSEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); + $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); + $formDatas['status'] = STATUS['OCCUPIED']; + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: CS์ƒํƒœ๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."); + } + //CS์ •๋ณด๊ฐ€์ ธ์˜ค๊ธฐ + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof CSEntity) { + throw new \Exception(message: "{$serverPartEntity->getPartUID()}์— ํ•ด๋‹นํ•˜๋Š” CS์ •๋ณด๋ฅผ ์ฐพ์„์ˆ˜์—†์Šต๋‹ˆ๋‹ค."); + } + //CS์ •๋ณด์—์„œ ํ•ด๋‹นํ•˜๋Š” CS๊ฐ€ ์žˆ์œผ๋ฉด ๊ฐ€์ ธ์™€์„œ ์‚ฌ์šฉ์ค‘์ธ์ง€ ์ฒดํฌ ํ›„ ์ˆ˜์ • + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if ($entity instanceof CSEntity) { + if ($entity->getStatus() !== STATUS['AVAILABLE']) { + throw new \Exception(__METHOD__ . ":์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: {$serverPartEntity->getTitle()}๋Š” ์‚ฌ์šฉ์ค‘์ž…๋‹ˆ๋‹ค."); + } + $entity = $this->model->modify($entity, $formDatas); + } + return $entity; + } + public function detachFromServerPart(ServerPartEntity $serverPartEntity): CSEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['serverinfo_uid'] = null; + $formDatas['status'] = STATUS['AVAILABLE']; + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: CS์ƒํƒœ๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."); + } + //CS์ •๋ณด๊ฐ€์ ธ์˜ค๊ธฐ + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof CSEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}์— ํ•ด๋‹นํ•˜๋Š” CS์ •๋ณด๋ฅผ ์ฐพ์„์ˆ˜์—†์Šต๋‹ˆ๋‹ค."); + } + //CS์ •๋ณด ์ˆ˜์ • + return $this->model->modify($entity, $formDatas); + } } diff --git a/app/Services/Part/DISKService.php b/app/Services/Part/DISKService.php index dfb9032..07c4161 100644 --- a/app/Services/Part/DISKService.php +++ b/app/Services/Part/DISKService.php @@ -26,6 +26,10 @@ class DISKService extends PartService { return new DISKDTO($formDatas); } + public function getEntityClass(): string + { + return DISKEntity::class; + } public function getFormService(): DISKForm { if ($this->_form === null) { @@ -97,7 +101,11 @@ class DISKService extends PartService } protected function create_process(array $formDatas): DISKEntity { - return new DISKEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof DISKEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ DISKEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): DISKEntity { @@ -110,4 +118,10 @@ class DISKService extends PartService //List ๊ฒ€์ƒ‰์šฉ //FormFilter ์กฐ๊ฑด์ ˆ ์ฒ˜๋ฆฌ //๊ฒ€์ƒ‰์–ด์กฐ๊ฑด์ ˆ์ฒ˜๋ฆฌ + //OrderBy ์ฒ˜๋ฆฌ + public function setOrderBy(mixed $field = null, mixed $value = null): void + { + $this->model->orderBy('title ASC'); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Part/IPService.php b/app/Services/Part/IPService.php index 5bfc02a..efecc64 100644 --- a/app/Services/Part/IPService.php +++ b/app/Services/Part/IPService.php @@ -3,6 +3,8 @@ namespace App\Services\Part; use App\DTOs\Part\IPDTO; +use App\Entities\Equipment\ServerEntity; +use App\Entities\Equipment\ServerPartEntity; use App\Entities\Part\IPEntity; use App\Forms\Part\IPForm; use App\Helpers\Part\IPHelper; @@ -26,6 +28,10 @@ class IPService extends PartService { return new IPDTO($formDatas); } + public function getEntityClass(): string + { + return IPEntity::class; + } public function getFormService(): IPForm { if ($this->_form === null) { @@ -113,7 +119,11 @@ class IPService extends PartService } protected function create_process(array $formDatas): IPEntity { - return new IPEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof IPEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ IPEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): IPEntity { @@ -132,4 +142,74 @@ class IPService extends PartService $this->model->orderBy("INET_ATON(ip) ASC"); parent::setOrderBy($field, $value); } + + //์„œ๋ฒ„๊ด€๋ จ ์ž‘์—… + public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): IPEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = $serverEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverEntity->getServiceInfoUID(); + $formDatas['serverinfo_uid'] = $serverEntity->getPK(); + $formDatas['status'] = STATUS['OCCUPIED']; + //IP์ •๋ณด์—์„œ ํ•ด๋‹นํ•˜๋Š” IP๊ฐ€ ์žˆ์œผ๋ฉด ๊ฐ€์ ธ์™€์„œ ์‚ฌ์šฉ์ค‘์ธ์ง€ ์ฒดํฌ ํ›„ ์ˆ˜์ • + $entity = $this->getEntity(['ip' => $serverEntity->getIP()]); + if (!$entity instanceof IPEntity) { + throw new \Exception("{$serverEntity->getIP()}์— ํ•ด๋‹นํ•˜๋Š” IP์ •๋ณด๋ฅผ ์ฐพ์„์ˆ˜์—†์Šต๋‹ˆ๋‹ค."); + } + if ($entity->getStatus() !== STATUS['AVAILABLE']) { + throw new \Exception(__METHOD__ . ":์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: {$serverEntity->getTitle()}๋Š” ์‚ฌ์šฉ์ค‘์ž…๋‹ˆ๋‹ค."); + } + return $this->model->modify($entity, $formDatas); + } + public function detachFromServer(ServerEntity $serverEntity): IPEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['serverinfo_uid'] = null; + $formDatas['old_clientinfo_uid'] = $serverEntity->getClientInfoUID() ?? null; + $formDatas['status'] = STATUS['AVAILABLE']; + //IP์ •๋ณด๊ฐ€์ ธ์˜ค๊ธฐ + $entity = $this->getEntity(['ip' => $serverEntity->getIP()]); + if (!$entity instanceof IPEntity) { + throw new \Exception("{$serverEntity->getIP()}์— ํ•ด๋‹นํ•˜๋Š” IP์ •๋ณด๋ฅผ ์ฐพ์„์ˆ˜์—†์Šต๋‹ˆ๋‹ค."); + } + //IP์ •๋ณด ์ˆ˜์ • + return $this->model->modify($entity, $formDatas); + } + + //์„œ๋ฒ„ํŒŒํŠธ๊ด€๋ จ ์ž‘์—… + public function attachToServerPart(ServerPartEntity $serverPartEntity): IPEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); + $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); + $formDatas['status'] = STATUS['OCCUPIED']; + //IP์ •๋ณด์—์„œ ํ•ด๋‹นํ•˜๋Š” IP๊ฐ€ ์žˆ์œผ๋ฉด ๊ฐ€์ ธ์™€์„œ ์‚ฌ์šฉ์ค‘์ธ์ง€ ์ฒดํฌ ํ›„ ์ˆ˜์ • + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if ($entity instanceof IPEntity) { + if ($entity->getStatus() !== STATUS['AVAILABLE']) { + throw new \Exception(__METHOD__ . ":์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: {$entity->getTitle()}๋Š” ์‚ฌ์šฉ์ค‘์ž…๋‹ˆ๋‹ค."); + } + $entity = $this->model->modify($entity, $formDatas); + } + return $entity; + } + public function detachFromServerPart(ServerPartEntity $serverPartEntity): IPEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['serverinfo_uid'] = null; + $formDatas['old_clientinfo_uid'] = $serverPartEntity->getClientInfoUID() ?? null; + $formDatas['status'] = STATUS['AVAILABLE']; + //IP์ •๋ณด๊ฐ€์ ธ์˜ค๊ธฐ + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof IPEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}์— ํ•ด๋‹นํ•˜๋Š” IP์ •๋ณด๋ฅผ ์ฐพ์„์ˆ˜์—†์Šต๋‹ˆ๋‹ค."); + } + //IP์ •๋ณด ์ˆ˜์ • + return $this->model->modify($entity, $formDatas); + } } diff --git a/app/Services/Part/PartService.php b/app/Services/Part/PartService.php index 7ff7aa2..a2c3f35 100644 --- a/app/Services/Part/PartService.php +++ b/app/Services/Part/PartService.php @@ -2,6 +2,8 @@ namespace App\Services\Part; +use App\Entities\Equipment\ServerPartEntity; +use App\Entities\Part\PartEntity; use App\Models\CommonModel; use App\Services\CommonService; @@ -12,4 +14,38 @@ abstract class PartService extends CommonService parent::__construct($model); $this->addClassPaths('Part'); } + public function getEntity(string|int|array $where, ?string $message = null): ?PartEntity + { + return parent::getEntity($where, $message); + } + + //์„œ๋ฒ„ํŒŒํŠธ๊ด€๋ จ ์ž‘์—… + public function attachToServerPart(ServerPartEntity $serverPartEntity): mixed + { + //๋ถ€ํ’ˆ์ •๋ณด๊ฐ€์ ธ์˜ค๊ธฐ + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity) { + throw new \Exception("{$serverPartEntity->getPartUID()}์— ํ•ด๋‹นํ•˜๋Š” ๋ถ€ํ’ˆ์ •๋ณด๋ฅผ ์ฐพ์„์ˆ˜์—†์Šต๋‹ˆ๋‹ค."); + } + //๋ถ€ํ’ˆ์ •๋ณด์— ์„œ๋ฒ„์ •๋ณด ์„ค์ • ๋ฐ ์„œ๋น„์Šค,๊ณ ๊ฐ์ •๋ณด ์ •์˜ + if ($entity->getAvailable() < $serverPartEntity->getCnt()) { + throw new \Exception("ํ˜„์žฌ ์‚ฌ์šฉ๊ฐ€๋Šฅ ๊ฐฏ์ˆ˜[{$entity->getAvailable()}]๋ณด๋‹ค ์ง€์ •ํ•˜์‹  ๊ฐฏ์ˆ˜({$serverPartEntity->getCnt()})๊ฐ€ ๋” ๋งŽ์Šต๋‹ˆ๋‹ค."); + } + return $this->model->modify($entity, ['used' => $entity->getUsed() + $serverPartEntity->getCnt()]); + } + public function detachFromServerPart(ServerPartEntity $serverPartEntity): mixed + { + //๋ถ€ํ’ˆ์ •๋ณด๊ฐ€์ ธ์˜ค๊ธฐ + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity) { + throw new \Exception("{$serverPartEntity->getPartUID()}์— ํ•ด๋‹นํ•˜๋Š” ๋ถ€ํ’ˆ์ •๋ณด๋ฅผ ์ฐพ์„์ˆ˜์—†์Šต๋‹ˆ๋‹ค."); + } + //๋ถ€ํ’ˆ์ •๋ณด์— ์„œ๋ฒ„์ •๋ณด ์„ค์ • ๋ฐ ์„œ๋น„์Šค,๊ณ ๊ฐ์ •๋ณด ์ •์˜ + if ($entity->getUsed() < $serverPartEntity->getCnt()) { + throw new \Exception("ํ˜„์žฌ ์‚ฌ์šฉ๋œ ๊ฐฏ์ˆ˜[{$entity->getUsed()}]๋ณด๋‹ค ์ง€์ •ํ•˜์‹  ๊ฐฏ์ˆ˜({$serverPartEntity->getCnt()})๊ฐ€ ๋” ๋งŽ์Šต๋‹ˆ๋‹ค."); + } + $entity = $this->model->modify($entity, ['used' => $entity->getUsed() - $serverPartEntity->getCnt()]); + // dd($entity); + return $entity; + } } diff --git a/app/Services/Part/RAMService.php b/app/Services/Part/RAMService.php index e5941a7..60f302c 100644 --- a/app/Services/Part/RAMService.php +++ b/app/Services/Part/RAMService.php @@ -26,6 +26,10 @@ class RAMService extends PartService { return new RAMDTO($formDatas); } + public function getEntityClass(): string + { + return RAMEntity::class; + } public function getFormService(): RAMForm { if ($this->_form === null) { @@ -95,7 +99,11 @@ class RAMService extends PartService } protected function create_process(array $formDatas): RAMEntity { - return new RAMEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof RAMEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ RAMEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): RAMEntity { @@ -108,4 +116,10 @@ class RAMService extends PartService //List ๊ฒ€์ƒ‰์šฉ //FormFilter ์กฐ๊ฑด์ ˆ ์ฒ˜๋ฆฌ //๊ฒ€์ƒ‰์–ด์กฐ๊ฑด์ ˆ์ฒ˜๋ฆฌ + //OrderBy ์ฒ˜๋ฆฌ + public function setOrderBy(mixed $field = null, mixed $value = null): void + { + $this->model->orderBy('title ASC'); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Part/SOFTWAREService.php b/app/Services/Part/SOFTWAREService.php index 0a34e0e..0ae832d 100644 --- a/app/Services/Part/SOFTWAREService.php +++ b/app/Services/Part/SOFTWAREService.php @@ -26,6 +26,10 @@ class SOFTWAREService extends PartService { return new SOFTWAREDTO($formDatas); } + public function getEntityClass(): string + { + return SOFTWAREEntity::class; + } public function getFormService(): SOFTWAREForm { if ($this->_form === null) { @@ -95,7 +99,11 @@ class SOFTWAREService extends PartService } protected function create_process(array $formDatas): SOFTWAREEntity { - return new SOFTWAREEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof SOFTWAREEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ SOFTWAREEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): SOFTWAREEntity { @@ -108,4 +116,10 @@ class SOFTWAREService extends PartService //List ๊ฒ€์ƒ‰์šฉ //FormFilter ์กฐ๊ฑด์ ˆ ์ฒ˜๋ฆฌ //๊ฒ€์ƒ‰์–ด์กฐ๊ฑด์ ˆ์ฒ˜๋ฆฌ + //OrderBy ์ฒ˜๋ฆฌ + public function setOrderBy(mixed $field = null, mixed $value = null): void + { + $this->model->orderBy('title ASC'); + parent::setOrderBy($field, $value); + } } diff --git a/app/Services/Part/SWITCHService.php b/app/Services/Part/SWITCHService.php index a679606..c3a1dd8 100644 --- a/app/Services/Part/SWITCHService.php +++ b/app/Services/Part/SWITCHService.php @@ -3,6 +3,8 @@ namespace App\Services\Part; use App\DTOs\Part\SWITCHDTO; +use App\Entities\Equipment\ServerEntity; +use App\Entities\Equipment\ServerPartEntity; use App\Entities\Part\SWITCHEntity; use App\Forms\Part\SWITCHForm; use App\Helpers\Part\SWITCHHelper; @@ -26,6 +28,10 @@ class SWITCHService extends PartService { return new SWITCHDTO($formDatas); } + public function getEntityClass(): string + { + return SWITCHEntity::class; + } public function getFormService(): SWITCHForm { if ($this->_form === null) { @@ -114,7 +120,11 @@ class SWITCHService extends PartService } protected function create_process(array $formDatas): SWITCHEntity { - return new SWITCHEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof SWITCHEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ SWITCHEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): SWITCHEntity { @@ -127,4 +137,91 @@ class SWITCHService extends PartService //List ๊ฒ€์ƒ‰์šฉ //FormFilter ์กฐ๊ฑด์ ˆ ์ฒ˜๋ฆฌ //๊ฒ€์ƒ‰์–ด์กฐ๊ฑด์ ˆ์ฒ˜๋ฆฌ + //OrderBy ์ฒ˜๋ฆฌ + public function setOrderBy(mixed $field = null, mixed $value = null): void + { + $this->model->orderBy('code ASC'); + parent::setOrderBy($field, $value); + } + + //์„œ๋ฒ„๊ด€๋ จ ์ž‘์—… + public function attachToServer(ServerEntity $serverEntity, array $formDatas = []): SWITCHEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = $serverEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverEntity->getServiceInfoUID(); + $formDatas['serverinfo_uid'] = $serverEntity->getPK(); + $formDatas['status'] = STATUS['OCCUPIED']; + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . ":์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: Switch์ƒํƒœ๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."); + } + //Switch์ •๋ณด์—์„œ ํ•ด๋‹นํ•˜๋Š” IP๊ฐ€ ์žˆ์œผ๋ฉด ๊ฐ€์ ธ์™€์„œ ์‚ฌ์šฉ์ค‘์ธ์ง€ ์ฒดํฌ ํ›„ ์ˆ˜์ • + $entity = $this->getEntity($serverEntity->getSwitchInfoUID()); + if (!$entity instanceof SWITCHEntity) { + throw new \Exception("{$serverEntity->getSwitchInfoUID()}์— ํ•ด๋‹นํ•˜๋Š” Switch์ •๋ณด๋ฅผ ์ฐพ์„์ˆ˜์—†์Šต๋‹ˆ๋‹ค."); + } + if ($entity->getStatus() !== STATUS['AVAILABLE']) { + throw new \Exception(__METHOD__ . ":์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: {$serverEntity->getTitle()}๋Š” ์‚ฌ์šฉ์ค‘์ž…๋‹ˆ๋‹ค."); + } + return $this->model->modify($entity, $formDatas); + } + public function detachFromServer(ServerEntity $serverEntity): SWITCHEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['serverinfo_uid'] = null; + $formDatas['old_clientinfo_uid'] = $serverEntity->getClientInfoUID() ?? null; + $formDatas['status'] = STATUS['AVAILABLE']; + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . ":์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: Switch์ƒํƒœ๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."); + } + //Switch์ •๋ณด๊ฐ€์ ธ์˜ค๊ธฐ + $entity = $this->getEntity($serverEntity->getSwitchInfoUID()); + if (!$entity instanceof SWITCHEntity) { + throw new \Exception("{$serverEntity->getSwitchInfoUID()}์— ํ•ด๋‹นํ•˜๋Š” Switch์ •๋ณด๋ฅผ ์ฐพ์„์ˆ˜์—†์Šต๋‹ˆ๋‹ค."); + } + //Switch์ •๋ณด ์ˆ˜์ • + return $this->model->modify($entity, $formDatas); + } + //์„œ๋ฒ„ํŒŒํŠธ๊ด€๋ จ ์ž‘์—… + public function attachToServerPart(ServerPartEntity $serverPartEntity): SWITCHEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = $serverPartEntity->getClientInfoUID(); + $formDatas['serviceinfo_uid'] = $serverPartEntity->getServiceInfoUID(); + $formDatas['serverinfo_uid'] = $serverPartEntity->getServerInfoUID(); + $formDatas['status'] = STATUS['OCCUPIED']; + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . ":์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: Switch์ƒํƒœ๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."); + } + //SWITCH์ •๋ณด์—์„œ ํ•ด๋‹นํ•˜๋Š” SWITCH๊ฐ€ ์žˆ์œผ๋ฉด ๊ฐ€์ ธ์™€์„œ ์‚ฌ์šฉ์ค‘์ธ์ง€ ์ฒดํฌ ํ›„ ์ˆ˜์ • + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if ($entity instanceof SWITCHEntity) { + if ($entity->getStatus() !== STATUS['AVAILABLE']) { + throw new \Exception(__METHOD__ . ":์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: {$entity->getTitle()}๋Š” ์‚ฌ์šฉ์ค‘์ž…๋‹ˆ๋‹ค."); + } + $entity = $this->model->modify($entity, $formDatas); + } + return $entity; + } + public function detachFromServerPart(ServerPartEntity $serverPartEntity): SWITCHEntity + { + $formDatas = []; + $formDatas['clientinfo_uid'] = null; + $formDatas['serviceinfo_uid'] = null; + $formDatas['serverinfo_uid'] = null; + $formDatas['old_clientinfo_uid'] = $serverPartEntity->getClientInfoUID() ?? null; + $formDatas['status'] = STATUS['AVAILABLE']; + if (!array_key_exists('status', $formDatas)) { + throw new \Exception(__METHOD__ . ":์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ: Switch์ƒํƒœ๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."); + } + //Switch์ •๋ณด๊ฐ€์ ธ์™€์„œ ์žˆ์œผ๋ฉด ์ˆ˜์ • + $entity = $this->getEntity($serverPartEntity->getPartUID()); + if (!$entity instanceof SWITCHEntity) { + throw new \Exception("{$serverPartEntity->getPartUID()}์— ํ•ด๋‹นํ•˜๋Š” Switch์ •๋ณด๋ฅผ ์ฐพ์„์ˆ˜์—†์Šต๋‹ˆ๋‹ค."); + } + //Switch์ •๋ณด ์ˆ˜์ • + return $this->model->modify($entity, $formDatas); + } } diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 28644f2..7558d35 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -25,6 +25,10 @@ class PaymentService extends CommonService { return PaymentDTO::class; } + public function getEntityClass(): string + { + return PaymentEntity::class; + } public function createDTO(array $formDatas): PaymentDTO { return new PaymentDTO($formDatas); @@ -130,11 +134,19 @@ class PaymentService extends CommonService } protected function create_process(array $formDatas): PaymentEntity { - return new PaymentEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof PaymentEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ PaymentEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): PaymentEntity { - return parent::modify_process($uid, $formDatas); + $entity = parent::modify_process($uid, $formDatas); + if (!$entity instanceof PaymentEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ PaymentEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } //List ๊ฒ€์ƒ‰์šฉ //FormFilter ์กฐ๊ฑด์ ˆ ์ฒ˜๋ฆฌ diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 81361c2..d4ba41e 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -26,6 +26,10 @@ class UserService extends CommonService { return new UserDTO($formDatas); } + public function getEntityClass(): string + { + return UserEntity::class; + } public function getFormService(): UserForm { if ($this->_form === null) { @@ -102,7 +106,11 @@ class UserService extends CommonService if (isset($formDatas['confirmpassword'])) { unset($formDatas['confirmpassword']); } - return new UserEntity($formDatas); + $entity = parent::create_process($formDatas); + if (!$entity instanceof UserEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ UserEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } protected function modify_process($uid, array $formDatas): UserEntity { @@ -110,7 +118,11 @@ class UserService extends CommonService if (isset($formDatas['confirmpassword'])) { unset($formDatas['confirmpassword']); } - return parent::modify_process($uid, $formDatas); + $entity = parent::modify_process($uid, $formDatas); + if (!$entity instanceof UserEntity) { + throw new RuntimeException(__METHOD__ . "์—์„œ ์˜ค๋ฅ˜๋ฐœ์ƒ:Return Type์€ UserEntity๋งŒ ๊ฐ€๋Šฅ"); + } + return $entity; } //List ๊ฒ€์ƒ‰์šฉ //FormFilter ์กฐ๊ฑด์ ˆ ์ฒ˜๋ฆฌ