diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e49b37d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "php.version": "8.3" +} \ No newline at end of file diff --git a/app/Controllers/CommonController.php b/app/Controllers/CommonController.php index 21af014..f585269 100644 --- a/app/Controllers/CommonController.php +++ b/app/Controllers/CommonController.php @@ -36,19 +36,18 @@ abstract class CommonController extends AbstractCRUDController return array($uids, $selectedFields, $formDatas); } - protected function batchjob_process($uid, array $formDatas): CommonEntity + protected function batchjob_process(array $uids, array $formDatas): array { // Service 로직 호출 (오버라이드 포인트) - return $this->service->batchjob($uid, $formDatas); + return $this->service->batchjob($uids, $formDatas); } - protected function batchjob_result_process(array $uids, array $entities, array $errors): string|RedirectResponse + protected function batchjob_result_process(array $uids, array $entities): string|RedirectResponse { return $this->action_redirect_process('info', sprintf( - "%s에서 %s개 처리완료, %s개 오류, 총:%s개 수정이 완료되었습니다.", + "%s에서 %s개 처리완료 총:%s개 수정이 완료되었습니다.", $this->getTitle(), count($entities), - count($errors), count($uids) )); } @@ -62,17 +61,8 @@ abstract class CommonController extends AbstractCRUDController $this->service->getFormService()->setFormRules($action, $selectedFields); $this->service->getFormService()->setFormFilters($selectedFields); $this->service->getFormService()->setFormOptions($action, $selectedFields); - $entities = []; - $errors = []; - foreach ($uids as $uid) { - try { - $entities[] = $this->batchjob_process($uid, $formDatas); - } catch (\Throwable $e) { - log_message('error', "{$this->getTitle()}에서 {$uid} 수정 오류:" . $e->getMessage()); - $errors[] = $e->getMessage(); - } - } - return $this->batchjob_result_process($uids, $entities, $errors); + $entities = $this->batchjob_process($uids, $formDatas); + return $this->batchjob_result_process($uids, $entities); } catch (\Throwable $e) { return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄수정 오류:" . $e->getMessage()); } @@ -89,13 +79,12 @@ abstract class CommonController extends AbstractCRUDController return $uids; } - protected function batchjob_delete_result_process(array $uids, array $entities, array $errors): string|RedirectResponse + protected function batchjob_delete_result_process(array $uids, array $entities): string|RedirectResponse { return $this->action_redirect_process('info', sprintf( - "%s에서 %s개 처리완료, %s개 오류, 총:%s개 일괄삭제가 완료되었습니다.", + "%s에서 %s개 처리완료, 총:%s개 일괄삭제가 완료되었습니다.", $this->getTitle(), count($entities), - count($errors), count($uids) )); } @@ -103,25 +92,16 @@ abstract class CommonController extends AbstractCRUDController /** * 단일 삭제 로직을 재사용 (Override 가능) */ - protected function batchjob_delete_process($uid): CommonEntity + protected function batchjob_delete_process(array $uids): array { - return $this->service->delete($uid); + return $this->service->batchjob_delete($uids); } final public function batchjob_delete(): string|RedirectResponse { try { $uids = $this->batchjob_delete_pre_process(); - $entities = []; - $errors = []; - foreach ($uids as $uid) { - try { - $entities[] = $this->batchjob_delete_process($uid); - } catch (\Throwable $e) { - log_message('error', "{$this->getTitle()}에서 {$uid} 삭제 오류:" . $e->getMessage()); - $errors[] = $e->getMessage(); - } - } - return $this->batchjob_delete_result_process($uids, $entities, $errors); + $entities = $this->batchjob_delete_process($uids); + return $this->batchjob_delete_result_process($uids, $entities); } catch (\Throwable $e) { return $this->action_redirect_process('error', "{$this->getTitle()}에서 일괄삭제 오류:" . $e->getMessage()); } diff --git a/app/Forms/CommonForm.php b/app/Forms/CommonForm.php index e1134bc..3f781a2 100644 --- a/app/Forms/CommonForm.php +++ b/app/Forms/CommonForm.php @@ -188,8 +188,12 @@ abstract class CommonForm $entities = []; switch ($field) { default: - if (array_key_exists($field, $formDatas)) { - $where = sprintf("status = '%s' OR %s='%s'", STATUS['AVAILABLE'], $this->getAttribute('pk_field'), $formDatas[$field]); + if (in_array($action, ['create_form', 'modify_form'])) { + if (array_key_exists($field, $formDatas)) { + $where = sprintf("status = '%s' OR %s='%s'", STATUS['AVAILABLE'], $this->getAttribute('pk_field'), $formDatas[$field]); + } else { + $where = sprintf("status = '%s'", STATUS['AVAILABLE']); + } $entities = $service->getEntities([$where => null]); } else { $entities = $service->getEntities(); diff --git a/app/Forms/Equipment/ServerForm.php b/app/Forms/Equipment/ServerForm.php index 01a2b3c..0489469 100644 --- a/app/Forms/Equipment/ServerForm.php +++ b/app/Forms/Equipment/ServerForm.php @@ -51,9 +51,13 @@ class ServerForm extends EquipmentForm $entities = []; switch ($field) { case 'ip': - if (array_key_exists($field, $formDatas)) { - $where = sprintf("status = '%s' OR %s='%s'", STATUS['AVAILABLE'], $field, $formDatas[$field]); - $entities = $service->getEntities([$where => null]); + if (in_array($action, ['create_form', 'modify_form'])) { + if (array_key_exists($field, $formDatas)) { + $where = sprintf("status = '%s' OR %s='%s'", STATUS['AVAILABLE'], $field, $formDatas[$field]); + $entities = $service->getEntities([$where => null]); + } else { + $entities = parent::getFormOption_process($service, $action, $field, $formDatas); + } } else { $entities = parent::getFormOption_process($service, $action, $field, $formDatas); } diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index cb146b6..16a1cfb 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -156,7 +156,7 @@ abstract class CommonService // 최종적으로 DB에 반영된 PK를 반환받습니다. (UPDATE이면 기존 PK, INSERT이면 새 PK) $finalPK = $this->handle_save_result($result, $initialPK); // handle_save_result에서 확인된 최종 PK를 사용하여 DB에서 최신 엔티티를 가져옴 - return $this->getEntity($finalPK); + return $entity; } //생성용 @@ -172,18 +172,37 @@ abstract class CommonService } final public function create(object $dto): CommonEntity { - //DTO 타입 체크 로직을 일반화 - $dtoClass = $this->getDTOClass(); - if (!$dto instanceof $dtoClass) { - throw new RuntimeException(__METHOD__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)"); + $db = \Config\Database::connect(); + try { + //트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정 + $db->transException(true)->transStart(); + //DTO 타입 체크 로직을 일반화 + $dtoClass = $this->getDTOClass(); + 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); + // 트랜잭션 완료 및 커밋 + $db->transComplete(); + return $entity; + } catch (DatabaseException $e) { + // DatabaseException을 포착하면 자동으로 롤백 처리됨 + throw new RuntimeException(sprintf( + "\n----[%s]에서 트랜잭션 실패: DB 오류----\n%s\n%s\n------------------------------\n", + __METHOD__, + $this->model->getLastQuery(), + $e->getMessage() + ), $e->getCode(), $e); + } catch (\Throwable $e) { + $db->transRollback(); // 예외 발생 시 수동으로 롤백 + throw new RuntimeException($e->getMessage(), 0, $e); } - $formDatas = $dto->toArray(); - if (!$this->getFormService()->validate($formDatas)) { - throw new ValidationException(implode("\n", service('validation')->getErrors())); - } - // NOTE: create_process에서 엔티티를 생성할 때, 자동 증가(AUTO_INCREMENT) 필드는 - // DB가 처리하도록 NULL이나 빈 값(0)으로 두는 것이 일반적입니다. - return $this->create_process($formDatas); } //수정용 @@ -213,16 +232,35 @@ abstract class CommonService } final public function modify(string|int $uid, object $dto): CommonEntity { - //DTO 타입 체크 로직을 일반화 - $dtoClass = $this->getDTOClass(); - if (!$dto instanceof $dtoClass) { - throw new RuntimeException(__METHOD__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)"); + $db = \Config\Database::connect(); + try { + //트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정 + $db->transException(true)->transStart(); + //DTO 타입 체크 로직을 일반화 + $dtoClass = $this->getDTOClass(); + 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); + // 트랜잭션 완료 및 커밋 + $db->transComplete(); + return $entity; + } catch (DatabaseException $e) { + // DatabaseException을 포착하면 자동으로 롤백 처리됨 + throw new RuntimeException(sprintf( + "\n----[%s]에서 트랜잭션 실패: DB 오류----\n%s\n%s\n------------------------------\n", + __METHOD__, + $this->model->getLastQuery(), + $e->getMessage() + ), $e->getCode(), $e); + } catch (\Throwable $e) { + $db->transRollback(); // 예외 발생 시 수동으로 롤백 + throw new RuntimeException($e->getMessage(), 0, $e); } - $formDatas = $dto->toArray(); - if (!$this->getFormService()->validate($formDatas)) { - throw new ValidationException(implode("\n", service('validation')->getErrors())); - } - return $this->modify_process($uid, $formDatas); } //배치 작업용 수정 @@ -232,19 +270,41 @@ abstract class CommonService $entity = $this->modify_process($uid, $formDatas); return $entity; } - final public function batchjob(string|int $uid, object $dto): CommonEntity + final public function batchjob(array $uids, object $dto): array { - //DTO 타입 체크 로직을 일반화 - $dtoClass = $this->getDTOClass(); - if (!$dto instanceof $dtoClass) { - throw new RuntimeException(__METHOD__ . "에서 오류발생: " . get_class($dto) . "는 사용할 수 없습니다. ({$dtoClass} 필요)"); + $db = \Config\Database::connect(); + try { + //트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정 + $db->transException(true)->transStart(); + //DTO 타입 체크 로직을 일반화 + $dtoClass = $this->getDTOClass(); + 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())); + } + //일괄작업처리 + $entities = []; + foreach ($uids as $uid) { + $entities[] = $this->batchjob_process($uid, $formDatas); + } + // 트랜잭션 완료 및 커밋 + $db->transComplete(); + return $entities; + } catch (DatabaseException $e) { + // DatabaseException을 포착하면 자동으로 롤백 처리됨 + throw new RuntimeException(sprintf( + "\n----[%s]에서 트랜잭션 실패: DB 오류----\n%s\n%s\n------------------------------\n", + __METHOD__, + $this->model->getLastQuery(), + $e->getMessage() + ), $e->getCode(), $e); + } catch (\Throwable $e) { + $db->transRollback(); // 예외 발생 시 수동으로 롤백 + throw new RuntimeException($e->getMessage(), 0, $e); } - - $formDatas = $dto->toArray(); - if (!$this->getFormService()->validate($formDatas)) { - throw new ValidationException(implode("\n", service('validation')->getErrors())); - } - return $this->batchjob_process($uid, $formDatas); } //삭제용 (일반) @@ -257,11 +317,6 @@ abstract class CommonService if (!$entity) { throw new \Exception(__METHOD__ . "에서 오류발생: {$uid}에 해당하는 정보을 찾을수 없습니다."); } - return $entity; - } - final public function delete(string|int $uid): CommonEntity - { - $entity = $this->delete_process($uid); $result = $this->model->delete($entity->getPK()); log_message('debug', $this->model->getLastQuery()); if ($result === false) { @@ -271,6 +326,29 @@ abstract class CommonService } return $entity; } + final public function delete(string|int $uid): CommonEntity + { + $db = \Config\Database::connect(); + try { + //트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정 + $db->transException(true)->transStart(); + $entity = $this->delete_process($uid); + // 트랜잭션 완료 및 커밋 + $db->transComplete(); + return $entity; + } catch (DatabaseException $e) { + // DatabaseException을 포착하면 자동으로 롤백 처리됨 + throw new RuntimeException(sprintf( + "\n----[%s]에서 트랜잭션 실패: DB 오류----\n%s\n%s\n------------------------------\n", + __METHOD__, + $this->model->getLastQuery(), + $e->getMessage() + ), $e->getCode(), $e); + } catch (\Throwable $e) { + $db->transRollback(); // 예외 발생 시 수동으로 롤백 + throw new RuntimeException($e->getMessage(), 0, $e); + } + } //삭제용 (배치 작업) protected function batchjob_delete_process(string|int $uid): CommonEntity @@ -280,17 +358,32 @@ abstract class CommonService return $entity; } - final public function batchjob_delete(string|int $uid): CommonEntity + final public function batchjob_delete(array $uids): array { - $entity = $this->batchjob_delete_process($uid); - $result = $this->model->delete($entity->getPK()); - log_message('debug', $this->model->getLastQuery()); - if ($result === false) { - $errors = $this->model->errors(); - $errorMsg = is_array($errors) ? implode(", ", $errors) : "삭제 작업이 실패했습니다."; - throw new RuntimeException(__METHOD__ . "에서 오류발생: " . $errorMsg); + $db = \Config\Database::connect(); + try { + //트랜잭션 도중 DB 오류가 발생하면 DatabaseException을 던지도록 설정 + $db->transException(true)->transStart(); + //일괄작업처리 + $entities = []; + foreach ($uids as $uid) { + $entities[] = $this->batchjob_delete_process($uid); + } + // 트랜잭션 완료 및 커밋 + $db->transComplete(); + return $entities; + } catch (DatabaseException $e) { + // DatabaseException을 포착하면 자동으로 롤백 처리됨 + throw new RuntimeException(sprintf( + "\n----[%s]에서 트랜잭션 실패: DB 오류----\n%s\n%s\n------------------------------\n", + __METHOD__, + $this->model->getLastQuery(), + $e->getMessage() + ), $e->getCode(), $e); + } catch (\Throwable $e) { + $db->transRollback(); // 예외 발생 시 수동으로 롤백 + throw new RuntimeException($e->getMessage(), 0, $e); } - return $entity; } //Index용 diff --git a/app/Services/Equipment/ServerPartService.php b/app/Services/Equipment/ServerPartService.php index c0fc70b..9b32ec3 100644 --- a/app/Services/Equipment/ServerPartService.php +++ b/app/Services/Equipment/ServerPartService.php @@ -172,7 +172,12 @@ class ServerPartService extends EquipmentService $formDatas['amount'] = $partEntity->getPrice(); //파트 금액 $formDatas['cnt'] = $part["CNT"]; $formDatas['extra'] = $part["EXTRA"]; - $entity = $this->model->create($formDatas); + //action 초기화 + $this->action_init_process('create'); + $entity = $this->create($this->createDTO($formDatas)); + if (!$entity instanceof ServerPartEntity) { + throw new \Exception(__METHOD__ . "에서 오류발생: Return Type은 ServerPartEntity만 가능합니다."); + } $this->getPartService($entity->getType())->attachToServerPart($entity); } } diff --git a/app/Services/Equipment/ServerService.php b/app/Services/Equipment/ServerService.php index 49002fd..b89c782 100644 --- a/app/Services/Equipment/ServerService.php +++ b/app/Services/Equipment/ServerService.php @@ -129,7 +129,9 @@ class ServerService extends EquipmentService throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 ServerEntity만 가능"); } //서버추가시 서버파트 자동추가용 - service('equipment_serverpartservice')->attachToServer($entity); + service('part_ipservice')->attachToServer($entity); + service('part_switchservice')->attachToServer($entity); + // service('equipment_serverpartservice')->attachToServer($entity); return $entity; } protected function modify_process($uid, array $formDatas): ServerEntity diff --git a/app/Services/Part/CSService.php b/app/Services/Part/CSService.php index ad89125..0df9965 100644 --- a/app/Services/Part/CSService.php +++ b/app/Services/Part/CSService.php @@ -173,7 +173,13 @@ class CSService extends PartService if ($entity->getStatus() !== STATUS['AVAILABLE']) { throw new \Exception(__METHOD__ . ":에서 오류발생: {$serverPartEntity->getTitle()}는 사용중입니다."); } - $entity = $this->model->modify($entity, $formDatas); + //CS 정보 수정 + //초기화 + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + /** @var CSEntity $entity IDE에 entity type알려주기*/ + $entity = $this->modify($entity->getPK(), $this->createDTO($formDatas)); } return $entity; } @@ -192,7 +198,13 @@ class CSService extends PartService if (!$entity instanceof CSEntity) { throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 CS정보를 찾을수없습니다."); } - //CS정보 수정 - return $this->model->modify($entity, $formDatas); + //CS 정보 수정 + //초기화 + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + /** @var CSEntity $entity IDE에 entity type알려주기*/ + $entity = $this->modify($entity->getPK(), $this->createDTO($formDatas)); + return $entity; } } diff --git a/app/Services/Part/DISKService.php b/app/Services/Part/DISKService.php index 07c4161..f21c6f7 100644 --- a/app/Services/Part/DISKService.php +++ b/app/Services/Part/DISKService.php @@ -3,6 +3,7 @@ namespace App\Services\Part; use App\DTOs\Part\DISKDTO; +use App\Entities\Equipment\ServerPartEntity; use App\Entities\Part\DISKEntity; use App\Forms\Part\DISKForm; use App\Helpers\Part\DISKHelper; @@ -124,4 +125,21 @@ class DISKService extends PartService $this->model->orderBy('title ASC'); parent::setOrderBy($field, $value); } + + //서버파트관련 작업 + public function detachFromServerPart(ServerPartEntity $serverPartEntity): DiskEntity + { + /** @var DiskEntity $entity IDE에 entity type알려주기*/ + $entity = parent::detachFromServerPart($serverPartEntity); + + $formDatas = ['format' => $entity->getFormat() + $serverPartEntity->getCnt()]; + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + $entity = $this->modify($entity->getPK(), $this->createDTO($formDatas)); + if (!$entity instanceof DISKEntity) { + throw new RuntimeException(__METHOD__ . "에서 오류발생:Return Type은 DISKEntity만 가능"); + } + return $entity; + } } diff --git a/app/Services/Part/IPService.php b/app/Services/Part/IPService.php index efecc64..7d5c04b 100644 --- a/app/Services/Part/IPService.php +++ b/app/Services/Part/IPService.php @@ -159,7 +159,14 @@ class IPService extends PartService if ($entity->getStatus() !== STATUS['AVAILABLE']) { throw new \Exception(__METHOD__ . ":에서 오류발생: {$serverEntity->getTitle()}는 사용중입니다."); } - return $this->model->modify($entity, $formDatas); + //IP 정보 수정 + //초기화 + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + /** @var IPEntity $entity IDE에 entity type알려주기*/ + $entity = $this->modify($entity->getPK(), $this->createDTO($formDatas)); + return $entity; } public function detachFromServer(ServerEntity $serverEntity): IPEntity { @@ -175,7 +182,13 @@ class IPService extends PartService throw new \Exception("{$serverEntity->getIP()}에 해당하는 IP정보를 찾을수없습니다."); } //IP정보 수정 - return $this->model->modify($entity, $formDatas); + //초기화 + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + /** @var IPEntity $entity IDE에 entity type알려주기*/ + $entity = $this->modify($entity->getPK(), $this->createDTO($formDatas)); + return $entity; } //서버파트관련 작업 @@ -192,7 +205,13 @@ class IPService extends PartService if ($entity->getStatus() !== STATUS['AVAILABLE']) { throw new \Exception(__METHOD__ . ":에서 오류발생: {$entity->getTitle()}는 사용중입니다."); } - $entity = $this->model->modify($entity, $formDatas); + //IP 정보 수정 + //초기화 + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + /** @var IPEntity $entity IDE에 entity type알려주기*/ + $entity = $this->modify($entity->getPK(), $this->createDTO($formDatas)); } return $entity; } @@ -209,7 +228,13 @@ class IPService extends PartService if (!$entity instanceof IPEntity) { throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 IP정보를 찾을수없습니다."); } - //IP정보 수정 - return $this->model->modify($entity, $formDatas); + //IP 정보 수정 + //초기화 + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + /** @var IPEntity $entity IDE에 entity type알려주기*/ + $entity = $this->modify($entity->getPK(), $this->createDTO($formDatas)); + return $entity; } } diff --git a/app/Services/Part/PartService.php b/app/Services/Part/PartService.php index a2c3f35..24e8653 100644 --- a/app/Services/Part/PartService.php +++ b/app/Services/Part/PartService.php @@ -20,7 +20,7 @@ abstract class PartService extends CommonService } //서버파트관련 작업 - public function attachToServerPart(ServerPartEntity $serverPartEntity): mixed + public function attachToServerPart(ServerPartEntity $serverPartEntity): PartEntity { //부품정보가져오기 $entity = $this->getEntity($serverPartEntity->getPartUID()); @@ -31,9 +31,13 @@ abstract class PartService extends CommonService if ($entity->getAvailable() < $serverPartEntity->getCnt()) { throw new \Exception("현재 사용가능 갯수[{$entity->getAvailable()}]보다 지정하신 갯수({$serverPartEntity->getCnt()})가 더 많습니다."); } - return $this->model->modify($entity, ['used' => $entity->getUsed() + $serverPartEntity->getCnt()]); + $formDatas = ['used' => $entity->getUsed() + $serverPartEntity->getCnt()]; + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + return $this->modify($entity->getPK(), $this->createDTO($formDatas)); } - public function detachFromServerPart(ServerPartEntity $serverPartEntity): mixed + public function detachFromServerPart(ServerPartEntity $serverPartEntity): PartEntity { //부품정보가져오기 $entity = $this->getEntity($serverPartEntity->getPartUID()); @@ -44,8 +48,10 @@ abstract class PartService extends CommonService 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; + $formDatas = ['used' => $entity->getUsed() - $serverPartEntity->getCnt()]; + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + return $this->modify($entity->getPK(), $this->createDTO($formDatas)); } } diff --git a/app/Services/Part/SWITCHService.php b/app/Services/Part/SWITCHService.php index c3a1dd8..ada62ba 100644 --- a/app/Services/Part/SWITCHService.php +++ b/app/Services/Part/SWITCHService.php @@ -163,7 +163,14 @@ class SWITCHService extends PartService if ($entity->getStatus() !== STATUS['AVAILABLE']) { throw new \Exception(__METHOD__ . ":에서 오류발생: {$serverEntity->getTitle()}는 사용중입니다."); } - return $this->model->modify($entity, $formDatas); + //SWITCH 정보 수정 + //초기화 + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + /** @var SWITCHEntity $entity IDE에 entity type알려주기*/ + $entity = $this->modify($entity->getPK(), $this->createDTO($formDatas)); + return $entity; } public function detachFromServer(ServerEntity $serverEntity): SWITCHEntity { @@ -181,8 +188,14 @@ class SWITCHService extends PartService if (!$entity instanceof SWITCHEntity) { throw new \Exception("{$serverEntity->getSwitchInfoUID()}에 해당하는 Switch정보를 찾을수없습니다."); } - //Switch정보 수정 - return $this->model->modify($entity, $formDatas); + //SWITCH 정보 수정 + //초기화 + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + /** @var SWITCHEntity $entity IDE에 entity type알려주기*/ + $entity = $this->modify($entity->getPK(), $this->createDTO($formDatas)); + return $entity; } //서버파트관련 작업 public function attachToServerPart(ServerPartEntity $serverPartEntity): SWITCHEntity @@ -201,7 +214,13 @@ class SWITCHService extends PartService if ($entity->getStatus() !== STATUS['AVAILABLE']) { throw new \Exception(__METHOD__ . ":에서 오류발생: {$entity->getTitle()}는 사용중입니다."); } - $entity = $this->model->modify($entity, $formDatas); + //SWITCH 정보 수정 + //초기화 + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + /** @var SWITCHEntity $entity IDE에 entity type알려주기*/ + $entity = $this->modify($entity->getPK(), $this->createDTO($formDatas)); } return $entity; } @@ -221,7 +240,13 @@ class SWITCHService extends PartService if (!$entity instanceof SWITCHEntity) { throw new \Exception("{$serverPartEntity->getPartUID()}에 해당하는 Switch정보를 찾을수없습니다."); } - //Switch정보 수정 - return $this->model->modify($entity, $formDatas); + //SWITCH 정보 수정 + //초기화 + $fields = array_keys($formDatas); + $this->getFormService()->setFormFields($fields); + $this->getFormService()->setFormRules('modify', $fields); + /** @var SWITCHEntity $entity IDE에 entity type알려주기*/ + $entity = $this->modify($entity->getPK(), $this->createDTO($formDatas)); + return $entity; } }