feat: Items API에 group_id 파라미터 지원 추가

- common_codes에 item_group 추가 및 item_type parent_id 연결
- /api/v1/items?type=RM → 단일 품목 유형 조회
- /api/v1/items?group_id=103 → 그룹 전체 품목 조회 (FG,PT,SM,RM,CS)
- ItemService에 getItemTypesByGroupId(), newQueryForTypes() 메서드 추가
- 에러 메시지 추가 (item_type_or_group_required, invalid_group_id)
This commit is contained in:
2025-12-15 14:47:04 +09:00
parent aaf7979d5f
commit b1bcad3be6
4 changed files with 113 additions and 7 deletions

View File

@@ -0,0 +1,66 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
/**
* common_codes에 item_group 추가 및 item_type과 연결
*
* 구조:
* - item_group (부모): code_group='item_group', code='ITEM', name='품목'
* - item_type (자식): parent_id로 item_group 연결
*/
return new class extends Migration
{
public function up(): void
{
// 1. item_group 추가 (품목 그룹)
$itemGroupId = DB::table('common_codes')->insertGetId([
'tenant_id' => 1,
'code_group' => 'item_group',
'code' => 'ITEM',
'name' => '품목',
'description' => '품목 관리 그룹 (FG, PT, SM, RM, CS)',
'is_active' => true,
'sort_order' => 1,
'created_at' => now(),
'updated_at' => now(),
]);
// 2. 기존 item_type의 parent_id를 item_group으로 연결
DB::table('common_codes')
->where('code_group', 'item_type')
->whereIn('code', ['FG', 'PT', 'SM', 'RM', 'CS'])
->update(['parent_id' => $itemGroupId]);
// 3. item_type의 attributes에서 source_table을 items로 통일
$itemTypes = DB::table('common_codes')
->where('code_group', 'item_type')
->whereIn('code', ['FG', 'PT', 'SM', 'RM', 'CS'])
->get();
foreach ($itemTypes as $itemType) {
$attributes = json_decode($itemType->attributes, true) ?? [];
$attributes['source_table'] = 'items';
DB::table('common_codes')
->where('id', $itemType->id)
->update(['attributes' => json_encode($attributes)]);
}
}
public function down(): void
{
// 1. item_type의 parent_id 초기화
DB::table('common_codes')
->where('code_group', 'item_type')
->whereIn('code', ['FG', 'PT', 'SM', 'RM', 'CS'])
->update(['parent_id' => null]);
// 2. item_group 삭제
DB::table('common_codes')
->where('code_group', 'item_group')
->where('code', 'ITEM')
->delete();
}
};