- Controller 3개, Service 3개, FormRequest 6개 생성 - Routes 등록 (BOM 항목, 섹션 템플릿, 마스터 필드) - Service-First, Multi-tenant, Soft Delete - 라우트 테스트 및 Pint 검사 통과 13 files changed, 600+ insertions(+)
102 lines
3.0 KiB
PHP
102 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services\ItemMaster;
|
|
|
|
use App\Models\ItemMaster\ItemMasterField;
|
|
use App\Services\Service;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
class ItemMasterFieldService extends Service
|
|
{
|
|
/**
|
|
* 마스터 필드 목록
|
|
*/
|
|
public function index(): Collection
|
|
{
|
|
$tenantId = $this->tenantId();
|
|
|
|
return ItemMasterField::where('tenant_id', $tenantId)
|
|
->orderBy('category')
|
|
->orderBy('field_name')
|
|
->get();
|
|
}
|
|
|
|
/**
|
|
* 마스터 필드 생성
|
|
*/
|
|
public function store(array $data): ItemMasterField
|
|
{
|
|
$tenantId = $this->tenantId();
|
|
$userId = $this->apiUserId();
|
|
|
|
$field = ItemMasterField::create([
|
|
'tenant_id' => $tenantId,
|
|
'field_name' => $data['field_name'],
|
|
'field_type' => $data['field_type'],
|
|
'category' => $data['category'] ?? null,
|
|
'description' => $data['description'] ?? null,
|
|
'is_common' => $data['is_common'] ?? false,
|
|
'default_value' => $data['default_value'] ?? null,
|
|
'options' => $data['options'] ?? null,
|
|
'validation_rules' => $data['validation_rules'] ?? null,
|
|
'properties' => $data['properties'] ?? null,
|
|
'created_by' => $userId,
|
|
]);
|
|
|
|
return $field;
|
|
}
|
|
|
|
/**
|
|
* 마스터 필드 수정
|
|
*/
|
|
public function update(int $id, array $data): ItemMasterField
|
|
{
|
|
$tenantId = $this->tenantId();
|
|
$userId = $this->apiUserId();
|
|
|
|
$field = ItemMasterField::where('tenant_id', $tenantId)
|
|
->where('id', $id)
|
|
->first();
|
|
|
|
if (! $field) {
|
|
throw new NotFoundHttpException(__('error.not_found'));
|
|
}
|
|
|
|
$field->update([
|
|
'field_name' => $data['field_name'] ?? $field->field_name,
|
|
'field_type' => $data['field_type'] ?? $field->field_type,
|
|
'category' => $data['category'] ?? $field->category,
|
|
'description' => $data['description'] ?? $field->description,
|
|
'is_common' => $data['is_common'] ?? $field->is_common,
|
|
'default_value' => $data['default_value'] ?? $field->default_value,
|
|
'options' => $data['options'] ?? $field->options,
|
|
'validation_rules' => $data['validation_rules'] ?? $field->validation_rules,
|
|
'properties' => $data['properties'] ?? $field->properties,
|
|
'updated_by' => $userId,
|
|
]);
|
|
|
|
return $field->fresh();
|
|
}
|
|
|
|
/**
|
|
* 마스터 필드 삭제
|
|
*/
|
|
public function destroy(int $id): void
|
|
{
|
|
$tenantId = $this->tenantId();
|
|
$userId = $this->apiUserId();
|
|
|
|
$field = ItemMasterField::where('tenant_id', $tenantId)
|
|
->where('id', $id)
|
|
->first();
|
|
|
|
if (! $field) {
|
|
throw new NotFoundHttpException(__('error.not_found'));
|
|
}
|
|
|
|
$field->update(['deleted_by' => $userId]);
|
|
$field->delete();
|
|
}
|
|
}
|