diff --git a/app/Http/Requests/ItemMaster/ItemPageStoreRequest.php b/app/Http/Requests/ItemMaster/ItemPageStoreRequest.php index 38f8c564..3c580eff 100644 --- a/app/Http/Requests/ItemMaster/ItemPageStoreRequest.php +++ b/app/Http/Requests/ItemMaster/ItemPageStoreRequest.php @@ -2,7 +2,9 @@ namespace App\Http\Requests\ItemMaster; +use App\Models\ItemMaster\ItemPage; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Validation\Rule; class ItemPageStoreRequest extends FormRequest { @@ -13,10 +15,26 @@ public function authorize(): bool public function rules(): array { + $tenantId = app('tenant_id'); + return [ 'page_name' => 'required|string|max:255', - 'item_type' => 'required|in:FG,PT,SM,RM,CS', + 'item_type' => [ + 'required', + 'in:FG,PT,SM,RM,CS', + Rule::unique((new ItemPage)->getTable(), 'item_type') + ->where('tenant_id', $tenantId) + ->where('is_active', true) + ->whereNull('deleted_at'), + ], 'absolute_path' => 'nullable|string|max:500', ]; } + + public function messages(): array + { + return [ + 'item_type.unique' => __('error.item_page_duplicate_item_type'), + ]; + } } diff --git a/app/Services/ItemMaster/ItemPageService.php b/app/Services/ItemMaster/ItemPageService.php index db9ed7ff..6d6a26b4 100644 --- a/app/Services/ItemMaster/ItemPageService.php +++ b/app/Services/ItemMaster/ItemPageService.php @@ -45,6 +45,16 @@ public function store(array $data): ItemPage $userId = $this->apiUserId(); $itemType = strtoupper($data['item_type']); + // 동일 tenant_id + item_type 조합의 활성 페이지 중복 검증 + $exists = ItemPage::where('tenant_id', $tenantId) + ->where('item_type', $itemType) + ->where('is_active', true) + ->exists(); + + if ($exists) { + throw new BusinessException(__('error.item_page_duplicate_item_type')); + } + // item_type으로 common_codes에서 source_table 조회 $sourceTable = $this->getSourceTableFromCommonCode($itemType); diff --git a/lang/en/error.php b/lang/en/error.php index 01aa5b42..2bf0693f 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -83,6 +83,7 @@ 'code_exists_in_deleted' => 'The same code exists in deleted data. Please permanently delete that code first or use a different code.', // Item type validation + 'item_page_duplicate_item_type' => 'A page with the same item type already exists.', 'item_type_required' => 'Item type (item_type) is required.', 'item_type_or_group_required' => 'Item type (item_type) or group ID (group_id) is required.', 'invalid_item_type' => 'Invalid item type.', diff --git a/lang/ko/error.php b/lang/ko/error.php index e5ef71c2..c3d14699 100644 --- a/lang/ko/error.php +++ b/lang/ko/error.php @@ -148,6 +148,7 @@ 'field_key_system_readonly' => '시스템 필드의 field_key는 변경할 수 없습니다.', 'field_key_system_cannot_delete' => '시스템 필드는 삭제할 수 없습니다.', 'bom_not_found' => 'BOM 항목을 찾을 수 없습니다.', + 'item_page_duplicate_item_type' => '이미 동일한 품목 유형의 페이지가 존재합니다.', 'item_type_required' => '품목 유형(item_type)은 필수입니다.', 'item_type_or_group_required' => '품목 유형(item_type) 또는 그룹 ID(group_id)는 필수입니다.', 'invalid_item_type' => '유효하지 않은 품목 유형입니다.',