From 06b8cf0424dc9ad20937802279641c9a742c2b5b Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Wed, 3 Sep 2025 11:16:06 +0900 Subject: [PATCH] dbmsv2_init...1 --- app/Controllers/CommonController.php | 4 +++- app/Services/CommonService.php | 14 +++++++---- app/Services/Equipment/ServerPartService.php | 13 ++-------- app/Services/Equipment/ServerService.php | 25 +++++++++----------- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 6d00425..9376e9d 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -393,7 +393,7 @@ abstract class CommonController extends BaseController //단일필드작업기능 protected function toggle_process(mixed $entity, array $formDatas): mixed { - return $this->getService()->modify($entity, $formDatas); + return $this->getService()->toggle($entity, $formDatas); } public function toggle(mixed $uid, string $field): RedirectResponse|string { @@ -407,6 +407,7 @@ abstract class CommonController extends BaseController $this->setFormRules(); //기본값정의 $this->setFormDatas($this->request->getGet()); + $this->doValidations(); //기존 Entity 가져오기 $entity = $this->getService()->getEntity($uid); if (!$entity) { @@ -460,6 +461,7 @@ abstract class CommonController extends BaseController $this->setFormRules(); //기본값정의 $this->setFormDatas($this->request->getGet()); + $this->doValidations(); $entities = []; foreach ($uids as $uid) { //기존 Entity 가져오기 diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index 26529ab..9f7e153 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -154,15 +154,21 @@ abstract class CommonService public function create(array $formDatas): mixed { $entity = $this->getModel()->create($formDatas); - LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["CREATED"] . ":"); + // LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["CREATED"] . ":"); return $entity; } //수정 public function modify(mixed $entity, array $formDatas): mixed { $entity = $this->getModel()->modify($entity, $formDatas); - // dd($entity); - LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["UPDATED"] . ":"); + // LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["UPDATED"] . ":"); + return $entity; + } + //단일작업 + public function toggle(mixed $entity, array $formDatas): mixed + { + $entity = $this->getModel()->modify($entity, $formDatas); + // LogCollector::info("[{$entity->getTitle()}]" . MESSAGES["UPDATED"] . ":"); return $entity; } //삭제 @@ -174,7 +180,7 @@ abstract class CommonService if (!$result) { throw new \Exception($message); } - LogCollector::info($message); + // LogCollector::info($message); return $entity; } catch (\Exception $e) { $message = sprintf( diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index 45e0d9f..15bf6a9 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -113,21 +113,12 @@ class ServerPartService extends EquipmentService } return $entity; } - //수정 - public function modifyByServer(ServerEntity $serverEntity, array $formDatas): ServerPartEntity - { - //삭제후생성 - $this->deleteByServer($serverEntity); - return $this->createByServer($serverEntity, $formDatas); - } //삭제 - public function deleteByServer(ServerEntity $serverEntity): array + public function deleteByServer(ServerEntity $serverEntity): void { //기존 서벼별 부품연결정보 삭제 후 - $entities = $this->getEntities(['serverinfo_uid' => $serverEntity->getPK()]); - foreach ($entities as $entity) { + foreach ($this->getEntities(['serverinfo_uid' => $serverEntity->getPK()]) as $entity) { $this->delete($entity); } - return $entities; } } diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 44fdf14..04c3392 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -180,11 +180,9 @@ class ServerService extends EquipmentService public function create(array $formDatas): ServerEntity { $entity = parent::create($formDatas); - //ServerPart정보 생성 - foreach (SERVER['PARTTYPES'] as $partType) { - foreach ($this->getServerPartService()->createByServer($entity, $formDatas) as $serverPartEntity) { - $entity->addServerPartEntity($serverPartEntity->getType(), $serverPartEntity); - }; + //신규 ServerPart정보 생성 + foreach ($this->getServerPartService()->createByServer($entity, $formDatas) as $serverPartEntity) { + $entity->addServerPartEntity($serverPartEntity->getType(), $serverPartEntity); } return $entity; } @@ -192,21 +190,20 @@ class ServerService extends EquipmentService public function modify(mixed $entity, array $formDatas): ServerEntity { $entity = parent::modify($entity, $formDatas); - // ServerPart정보 수정 - foreach ($this->getServerPartService()->modifyByServer($entity, $formDatas) as $serverPartEntity) { + //기존 ServerPart정보 삭제 + $this->getServerPartService()->deleteByServer($entity); + //신규 ServerPart정보 생성 + foreach ($this->getServerPartService()->createByServer($entity, $formDatas) as $serverPartEntity) { $entity->addServerPartEntity($serverPartEntity->getType(), $serverPartEntity); - }; + } return $entity; } //삭제 public function delete(mixed $entity): ServerEntity { - $entity = parent::delete($entity); - // ServerPart정보 수정 - foreach ($this->getServerPartService()->deleteByServer($entity) as $serverPartEntity) { - $entity->addServerPartEntity($serverPartEntity->getType(), $serverPartEntity); - }; - return $entity; + //기존 ServerPart정보 삭제 + $this->getServerPartService()->deleteByServer($entity); + return parent::delete($entity); } //List 검색용 //OrderBy 처리