diff --git a/app/Http/Controllers/Api/V1/CommonController.php b/app/Http/Controllers/Api/V1/CommonController.php index 9eea861..84ec27a 100644 --- a/app/Http/Controllers/Api/V1/CommonController.php +++ b/app/Http/Controllers/Api/V1/CommonController.php @@ -26,11 +26,26 @@ public function list(Request $request) }, __('message.fetched')); } + /** + * 특정 그룹의 공통 코드 목록 조회 + * + * GET /api/v1/settings/common/{group} + */ public function index(Request $request, string $group) { - return ApiResponse::handle(function () { - // Service implementation needed - return []; + return ApiResponse::handle(function () use ($group) { + $tenantId = app('tenant_id'); + + return DB::table('common_codes') + ->select(['id', 'code', 'name', 'description', 'sort_order', 'attributes']) + ->where('code_group', $group) + ->where('is_active', true) + ->where(function ($query) use ($tenantId) { + $query->where('tenant_id', $tenantId) + ->orWhereNull('tenant_id'); + }) + ->orderBy('sort_order') + ->get(); }, __('message.fetched')); } diff --git a/database/migrations/2026_01_09_171700_add_order_codes_to_common_codes.php b/database/migrations/2026_01_09_171700_add_order_codes_to_common_codes.php new file mode 100644 index 0000000..625ff7f --- /dev/null +++ b/database/migrations/2026_01_09_171700_add_order_codes_to_common_codes.php @@ -0,0 +1,69 @@ + 'DRAFT', 'name' => '임시저장', 'sort_order' => 1], + ['code' => 'CONFIRMED', 'name' => '확정', 'sort_order' => 2], + ['code' => 'IN_PROGRESS', 'name' => '진행중', 'sort_order' => 3], + ['code' => 'COMPLETED', 'name' => '완료', 'sort_order' => 4], + ['code' => 'CANCELLED', 'name' => '취소', 'sort_order' => 5], + ]; + + foreach ($orderStatuses as $item) { + DB::table('common_codes')->updateOrInsert( + ['code_group' => 'order_status', 'code' => $item['code']], + [ + 'code_group' => 'order_status', + 'code' => $item['code'], + 'name' => $item['name'], + 'sort_order' => $item['sort_order'], + 'is_active' => true, + 'created_at' => $now, + 'updated_at' => $now, + ] + ); + } + + // order_type 코드 그룹 (수주 유형) + $orderTypes = [ + ['code' => 'ORDER', 'name' => '수주', 'sort_order' => 1], + ['code' => 'PURCHASE', 'name' => '발주', 'sort_order' => 2], + ]; + + foreach ($orderTypes as $item) { + DB::table('common_codes')->updateOrInsert( + ['code_group' => 'order_type', 'code' => $item['code']], + [ + 'code_group' => 'order_type', + 'code' => $item['code'], + 'name' => $item['name'], + 'sort_order' => $item['sort_order'], + 'is_active' => true, + 'created_at' => $now, + 'updated_at' => $now, + ] + ); + } + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + DB::table('common_codes')->where('code_group', 'order_status')->delete(); + DB::table('common_codes')->where('code_group', 'order_type')->delete(); + } +}; \ No newline at end of file