fix:메뉴 싱크 원격 API 호출 시 테넌트 ID 전달
- fetchRemoteMenus()에서 tenant_id 쿼리 파라미터 추가 - export() API에서 요청의 tenant_id 파라미터 우선 사용 - getMenuTreeForTenant() 메서드 추가로 특정 테넌트 메뉴 조회 지원 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -127,8 +127,11 @@ public function export(Request $request): JsonResponse
|
||||
return response()->json(['error' => 'Unauthorized'], 401);
|
||||
}
|
||||
|
||||
$menus = $this->getMenuTree();
|
||||
$tenant = Tenant::find($this->getTenantId());
|
||||
// 요청에서 tenant_id를 받으면 사용, 없으면 세션 기반
|
||||
$tenantId = $request->query('tenant_id') ? (int) $request->query('tenant_id') : $this->getTenantId();
|
||||
|
||||
$menus = $this->getMenuTreeForTenant($tenantId);
|
||||
$tenant = Tenant::find($tenantId);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
@@ -332,14 +335,22 @@ public function testConnection(Request $request): JsonResponse
|
||||
* 메뉴 트리 조회
|
||||
*/
|
||||
private function getMenuTree(?int $parentId = null): array
|
||||
{
|
||||
return $this->getMenuTreeForTenant($this->getTenantId(), $parentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 테넌트의 메뉴 트리 조회
|
||||
*/
|
||||
private function getMenuTreeForTenant(int $tenantId, ?int $parentId = null): array
|
||||
{
|
||||
$menus = Menu::withoutGlobalScopes()
|
||||
->where('tenant_id', $this->getTenantId())
|
||||
->where('tenant_id', $tenantId)
|
||||
->where('parent_id', $parentId)
|
||||
->orderBy('sort_order')
|
||||
->get();
|
||||
|
||||
return $menus->map(function ($menu) {
|
||||
return $menus->map(function ($menu) use ($tenantId) {
|
||||
return [
|
||||
'id' => $menu->id,
|
||||
'name' => $menu->name,
|
||||
@@ -347,7 +358,7 @@ private function getMenuTree(?int $parentId = null): array
|
||||
'icon' => $menu->icon,
|
||||
'sort_order' => $menu->sort_order,
|
||||
'options' => $menu->options,
|
||||
'children' => $this->getMenuTree($menu->id),
|
||||
'children' => $this->getMenuTreeForTenant($tenantId, $menu->id),
|
||||
];
|
||||
})->toArray();
|
||||
}
|
||||
@@ -383,7 +394,9 @@ private function fetchRemoteMenus(array $env): array
|
||||
$response = Http::withHeaders([
|
||||
'X-Menu-Sync-Key' => $env['api_key'],
|
||||
'Accept' => 'application/json',
|
||||
])->timeout(10)->get(rtrim($env['url'], '/') . '/menu-sync/export');
|
||||
])->timeout(10)->get(rtrim($env['url'], '/') . '/menu-sync/export', [
|
||||
'tenant_id' => $this->getTenantId(), // 현재 선택된 테넌트 전달
|
||||
]);
|
||||
|
||||
if (! $response->successful()) {
|
||||
throw new \Exception('API 오류: HTTP ' . $response->status());
|
||||
|
||||
Reference in New Issue
Block a user