32 lines
1.2 KiB
PHP
32 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Part;
|
|
|
|
use App\Entities\Equipment\ServerPartEntity;
|
|
use App\Entities\Part\PartEntity;
|
|
use App\Models\CommonModel;
|
|
use App\Services\CommonService;
|
|
|
|
abstract class PartService extends CommonService
|
|
{
|
|
protected function __construct(CommonModel $model)
|
|
{
|
|
parent::__construct($model);
|
|
$this->addClassPaths('Part');
|
|
}
|
|
abstract public function attachToServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): PartEntity;
|
|
abstract public function detachFromServerPart(ServerPartEntity $serverPartEntity, array $formDatas = []): PartEntity;
|
|
final protected function updatePart($entity, array $formDatas): PartEntity
|
|
{
|
|
$updateResult = $this->model->update($entity->getPK(), $formDatas);
|
|
if ($updateResult === false || $updateResult === 0) {
|
|
// 업데이트 실패 시 예외 처리
|
|
$errors = $this->model->errors();
|
|
$errorMsg = is_array($errors) ? implode(", ", $errors) : "DB 업데이트 실패 또는 변경된 행 없음.";
|
|
throw new \Exception(__METHOD__ . ": " . $errorMsg);
|
|
}
|
|
$entity->merge($formDatas);
|
|
return $entity;
|
|
}
|
|
}
|