From 24c97cf75afefe931d04804960b5f55093f3713e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=84=B1?= Date: Fri, 30 Jan 2026 20:13:39 +0900 Subject: [PATCH] =?UTF-8?q?fix(API):=20=EA=B3=B5=ED=86=B5=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20=ED=85=8C=EB=84=8C=ED=8A=B8=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20-=20=EA=B8=80=EB=A1=9C=EB=B2=8C=20?= =?UTF-8?q?=ED=8F=B4=EB=B0=B1=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 테넌트 데이터 존재 시 테넌트만 조회, 없으면 글로벌 폴백 - 기존: tenant OR NULL → 글로벌+테넌트 중복 반환 문제 해결 Co-Authored-By: Claude Opus 4.5 --- app/Http/Controllers/Api/V1/CommonController.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/V1/CommonController.php b/app/Http/Controllers/Api/V1/CommonController.php index 84ec27a..c71873c 100644 --- a/app/Http/Controllers/Api/V1/CommonController.php +++ b/app/Http/Controllers/Api/V1/CommonController.php @@ -36,13 +36,23 @@ public function index(Request $request, string $group) return ApiResponse::handle(function () use ($group) { $tenantId = app('tenant_id'); + // 테넌트 전용 데이터가 있으면 테넌트만, 없으면 글로벌 폴백 + $tenantCount = DB::table('common_codes') + ->where('code_group', $group) + ->where('is_active', true) + ->where('tenant_id', $tenantId) + ->count(); + 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'); + ->where(function ($query) use ($tenantId, $tenantCount) { + if ($tenantCount > 0) { + $query->where('tenant_id', $tenantId); + } else { + $query->whereNull('tenant_id'); + } }) ->orderBy('sort_order') ->get();