feat: Item Master 하이브리드 구조 전환 및 독립 API 추가
- CASCADE FK → 독립 엔티티 + entity_relationships 링크 테이블 - 독립 API 10개 추가 (섹션/필드/BOM CRUD, clone, usage) - SectionTemplate 모델 제거 → ItemSection.is_template 통합 - 페이지-섹션, 섹션-필드, 섹션-BOM 링크/언링크 API 14개 추가 - Swagger 문서 업데이트
This commit is contained in:
@@ -2,11 +2,17 @@
|
||||
|
||||
namespace App\Services\ItemMaster;
|
||||
|
||||
use App\Models\ItemMaster\SectionTemplate;
|
||||
use App\Models\ItemMaster\ItemSection;
|
||||
use App\Services\Service;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* SectionTemplateService
|
||||
*
|
||||
* 섹션 템플릿 관리 서비스
|
||||
* 내부적으로 ItemSection (is_template=true) 사용
|
||||
*/
|
||||
class SectionTemplateService extends Service
|
||||
{
|
||||
/**
|
||||
@@ -16,7 +22,9 @@ public function index(): Collection
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
return SectionTemplate::where('tenant_id', $tenantId)
|
||||
return ItemSection::templates()
|
||||
->where('tenant_id', $tenantId)
|
||||
->with(['fields', 'bomItems'])
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
}
|
||||
@@ -24,37 +32,42 @@ public function index(): Collection
|
||||
/**
|
||||
* 섹션 템플릿 생성
|
||||
*/
|
||||
public function store(array $data): SectionTemplate
|
||||
public function store(array $data): ItemSection
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$template = SectionTemplate::create([
|
||||
$template = ItemSection::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'group_id' => 1,
|
||||
'page_id' => null,
|
||||
'title' => $data['title'],
|
||||
'type' => $data['type'],
|
||||
'description' => $data['description'] ?? null,
|
||||
'order_no' => 0,
|
||||
'is_template' => true,
|
||||
'is_default' => $data['is_default'] ?? false,
|
||||
'description' => $data['description'] ?? null,
|
||||
'created_by' => $userId,
|
||||
]);
|
||||
|
||||
return $template;
|
||||
return $template->load(['fields', 'bomItems']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 섹션 템플릿 수정
|
||||
*/
|
||||
public function update(int $id, array $data): SectionTemplate
|
||||
public function update(int $id, array $data): ItemSection
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$template = SectionTemplate::where('tenant_id', $tenantId)
|
||||
$template = ItemSection::templates()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('id', $id)
|
||||
->first();
|
||||
|
||||
if (! $template) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
throw new NotFoundHttpException(__('error.section_not_found'));
|
||||
}
|
||||
|
||||
$template->update([
|
||||
@@ -65,7 +78,7 @@ public function update(int $id, array $data): SectionTemplate
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
return $template->fresh();
|
||||
return $template->fresh()->load(['fields', 'bomItems']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,15 +89,27 @@ public function destroy(int $id): void
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
$template = SectionTemplate::where('tenant_id', $tenantId)
|
||||
$template = ItemSection::templates()
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('id', $id)
|
||||
->first();
|
||||
|
||||
if (! $template) {
|
||||
throw new NotFoundHttpException(__('error.not_found'));
|
||||
throw new NotFoundHttpException(__('error.section_not_found'));
|
||||
}
|
||||
|
||||
$template->update(['deleted_by' => $userId]);
|
||||
$template->delete();
|
||||
|
||||
// 하위 필드/BOM도 Soft Delete
|
||||
foreach ($template->fields as $field) {
|
||||
$field->update(['deleted_by' => $userId]);
|
||||
$field->delete();
|
||||
}
|
||||
|
||||
foreach ($template->bomItems as $bomItem) {
|
||||
$bomItem->update(['deleted_by' => $userId]);
|
||||
$bomItem->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user