feat: field_key 시스템 필드 예약어 검증 추가
- SystemFields 상수 클래스 생성 (app/Constants/) - source_table 기반 테이블별 예약어 관리 - products/materials 테이블 고정 컬럼 정의 - 공통 시스템 컬럼 포함 - ItemFieldService 수정 - validateFieldKeyUnique에 시스템 필드 검증 추가 - source_table 미지정시 그룹 전체 예약어 체크 (안전 모드) - 에러 메시지 추가 (error.field_key_reserved) - 작업 문서 추가 (docs/specs/item-master-field-key-validation.md)
This commit is contained in:
144
app/Constants/SystemFields.php
Normal file
144
app/Constants/SystemFields.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace App\Constants;
|
||||
|
||||
/**
|
||||
* 테이블별 시스템 필드(고정 컬럼) 예약어 관리
|
||||
*
|
||||
* field_key 중복 검증 시 해당 테이블의 고정 컬럼과 충돌을 방지합니다.
|
||||
* source_table (products, materials) 기반으로 대상 테이블을 결정합니다.
|
||||
*/
|
||||
class SystemFields
|
||||
{
|
||||
/**
|
||||
* 소스 테이블 상수
|
||||
*/
|
||||
public const SOURCE_TABLE_PRODUCTS = 'products';
|
||||
|
||||
public const SOURCE_TABLE_MATERIALS = 'materials';
|
||||
|
||||
/**
|
||||
* 그룹 ID 상수
|
||||
*/
|
||||
public const GROUP_ITEM_MASTER = 1; // 품목관리
|
||||
|
||||
/**
|
||||
* products 테이블 고정 컬럼
|
||||
*/
|
||||
public const PRODUCTS = [
|
||||
// 기본 정보
|
||||
'code',
|
||||
'name',
|
||||
'unit',
|
||||
'category_id',
|
||||
'product_type',
|
||||
'description',
|
||||
// 플래그
|
||||
'is_sellable',
|
||||
'is_purchasable',
|
||||
'is_producible',
|
||||
'is_variable_size',
|
||||
'is_active',
|
||||
// 하이브리드 고정 필드
|
||||
'safety_stock',
|
||||
'lead_time',
|
||||
'product_category',
|
||||
'part_type',
|
||||
// 파일 관련
|
||||
'bending_diagram',
|
||||
'bending_details',
|
||||
'specification_file',
|
||||
'specification_file_name',
|
||||
'certification_file',
|
||||
'certification_file_name',
|
||||
'certification_number',
|
||||
'certification_start_date',
|
||||
'certification_end_date',
|
||||
// JSON 필드
|
||||
'attributes',
|
||||
'attributes_archive',
|
||||
];
|
||||
|
||||
/**
|
||||
* materials 테이블 고정 컬럼
|
||||
*/
|
||||
public const MATERIALS = [
|
||||
// 기본 정보
|
||||
'name',
|
||||
'item_name',
|
||||
'specification',
|
||||
'material_code',
|
||||
'material_type',
|
||||
'unit',
|
||||
'category_id',
|
||||
// 플래그
|
||||
'is_inspection',
|
||||
'is_active',
|
||||
// 기타
|
||||
'search_tag',
|
||||
'remarks',
|
||||
// JSON 필드
|
||||
'attributes',
|
||||
'options',
|
||||
];
|
||||
|
||||
/**
|
||||
* 공통 시스템 컬럼 (모든 테이블에 적용)
|
||||
*/
|
||||
public const COMMON = [
|
||||
'id',
|
||||
'tenant_id',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* source_table 기반 예약어 목록 조회
|
||||
*/
|
||||
public static function getReservedKeys(string $sourceTable): array
|
||||
{
|
||||
$tableFields = match ($sourceTable) {
|
||||
self::SOURCE_TABLE_PRODUCTS => self::PRODUCTS,
|
||||
self::SOURCE_TABLE_MATERIALS => self::MATERIALS,
|
||||
default => []
|
||||
};
|
||||
|
||||
// 공통 시스템 컬럼 병합
|
||||
return array_unique(array_merge(self::COMMON, $tableFields));
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 field_key가 시스템 필드인지 확인
|
||||
*/
|
||||
public static function isReserved(string $fieldKey, string $sourceTable): bool
|
||||
{
|
||||
return in_array($fieldKey, self::getReservedKeys($sourceTable), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* group_id에 속한 모든 테이블의 예약어 목록 조회
|
||||
* (item_type을 모를 때 안전하게 모든 예약어 체크)
|
||||
*/
|
||||
public static function getAllReservedKeysForGroup(int $groupId): array
|
||||
{
|
||||
$allFields = self::COMMON;
|
||||
|
||||
if ($groupId === self::GROUP_ITEM_MASTER) {
|
||||
$allFields = array_merge($allFields, self::PRODUCTS, self::MATERIALS);
|
||||
}
|
||||
|
||||
return array_unique($allFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 field_key가 그룹 내 어떤 테이블에서든 시스템 필드인지 확인
|
||||
*/
|
||||
public static function isReservedInGroup(string $fieldKey, int $groupId): bool
|
||||
{
|
||||
return in_array($fieldKey, self::getAllReservedKeysForGroup($groupId), true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user