refactor: group_id 네이밍 통일 (code_group='group', code='1')
- 마이그레이션: code_group='item_group' → 'group', code='ITEM' → '1' - ItemService: group_id로 code 조회 후 parent_id 매칭 - API: /api/v1/items?group_id=1 → 품목 그룹 전체 조회
This commit is contained in:
@@ -82,14 +82,26 @@ private function newQuery(string $itemType)
|
||||
/**
|
||||
* group_id로 해당 그룹의 item_type 목록 조회
|
||||
*
|
||||
* @param int $groupId common_codes의 item_group id
|
||||
* @param int $groupId 그룹 코드 (code_group='group', code='1' → group_id=1)
|
||||
* @return array item_type 코드 배열 ['FG', 'PT', 'SM', 'RM', 'CS']
|
||||
*/
|
||||
private function getItemTypesByGroupId(int $groupId): array
|
||||
{
|
||||
// 1. group_id로 그룹 레코드 찾기 (code_group='group', code=group_id)
|
||||
$group = \DB::table('common_codes')
|
||||
->where('code_group', 'group')
|
||||
->where('code', (string) $groupId)
|
||||
->where('is_active', true)
|
||||
->first();
|
||||
|
||||
if (! $group) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 2. 해당 그룹의 id를 parent_id로 가진 item_type 조회
|
||||
return \DB::table('common_codes')
|
||||
->where('code_group', 'item_type')
|
||||
->where('parent_id', $groupId)
|
||||
->where('parent_id', $group->id)
|
||||
->where('is_active', true)
|
||||
->pluck('code')
|
||||
->toArray();
|
||||
|
||||
@@ -4,21 +4,24 @@
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* common_codes에 item_group 추가 및 item_type과 연결
|
||||
* common_codes에 그룹 추가 및 item_type과 연결
|
||||
*
|
||||
* 구조:
|
||||
* - item_group (부모): code_group='item_group', code='ITEM', name='품목'
|
||||
* - item_type (자식): parent_id로 item_group 연결
|
||||
* - group (부모): code_group='group', code='1', name='품목'
|
||||
* - item_type (자식): parent_id로 group 연결
|
||||
*
|
||||
* API 사용:
|
||||
* - /api/v1/items?group_id=1 → 품목 그룹 전체 (FG, PT, SM, RM, CS)
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
// 1. item_group 추가 (품목 그룹)
|
||||
$itemGroupId = DB::table('common_codes')->insertGetId([
|
||||
// 1. 품목 그룹 추가 (code_group='group', code='1')
|
||||
$groupId = DB::table('common_codes')->insertGetId([
|
||||
'tenant_id' => 1,
|
||||
'code_group' => 'item_group',
|
||||
'code' => 'ITEM',
|
||||
'code_group' => 'group',
|
||||
'code' => '1',
|
||||
'name' => '품목',
|
||||
'description' => '품목 관리 그룹 (FG, PT, SM, RM, CS)',
|
||||
'is_active' => true,
|
||||
@@ -27,11 +30,11 @@ public function up(): void
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
// 2. 기존 item_type의 parent_id를 item_group으로 연결
|
||||
// 2. 기존 item_type의 parent_id를 group으로 연결
|
||||
DB::table('common_codes')
|
||||
->where('code_group', 'item_type')
|
||||
->whereIn('code', ['FG', 'PT', 'SM', 'RM', 'CS'])
|
||||
->update(['parent_id' => $itemGroupId]);
|
||||
->update(['parent_id' => $groupId]);
|
||||
|
||||
// 3. item_type의 attributes에서 source_table을 items로 통일
|
||||
$itemTypes = DB::table('common_codes')
|
||||
@@ -57,10 +60,10 @@ public function down(): void
|
||||
->whereIn('code', ['FG', 'PT', 'SM', 'RM', 'CS'])
|
||||
->update(['parent_id' => null]);
|
||||
|
||||
// 2. item_group 삭제
|
||||
// 2. group 삭제
|
||||
DB::table('common_codes')
|
||||
->where('code_group', 'item_group')
|
||||
->where('code', 'ITEM')
|
||||
->where('code_group', 'group')
|
||||
->where('code', '1')
|
||||
->delete();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user