fix: [menu-sync] 대분류 메뉴 push 시 null URL validation 오류 수정
- import validation에서 url 필드를 required → nullable로 변경 - push/getChildrenData에서 null URL을 빈 문자열로 대체 - importMenu에서 빈 URL을 null로 저장 - push 에러 응답에 원격 서버 에러 메시지 포함
This commit is contained in:
@@ -160,7 +160,7 @@ public function import(Request $request): JsonResponse
|
||||
$validated = $request->validate([
|
||||
'menus' => 'required|array',
|
||||
'menus.*.name' => 'required|string|max:100',
|
||||
'menus.*.url' => 'required|string|max:255',
|
||||
'menus.*.url' => 'nullable|string|max:255',
|
||||
'menus.*.icon' => 'nullable|string|max:50',
|
||||
'menus.*.sort_order' => 'nullable|integer',
|
||||
'menus.*.options' => 'nullable|array',
|
||||
@@ -217,7 +217,7 @@ public function push(Request $request): JsonResponse
|
||||
|
||||
return [
|
||||
'name' => $menu->name,
|
||||
'url' => $menu->url,
|
||||
'url' => $menu->url ?? '',
|
||||
'icon' => $menu->icon,
|
||||
'sort_order' => $menu->sort_order,
|
||||
'options' => $menu->options,
|
||||
@@ -231,7 +231,7 @@ public function push(Request $request): JsonResponse
|
||||
$response = Http::withHeaders([
|
||||
'X-Menu-Sync-Key' => $env['api_key'],
|
||||
'Accept' => 'application/json',
|
||||
])->post(rtrim($env['url'], '/').'/menu-sync/import', [
|
||||
])->timeout(15)->post(rtrim($env['url'], '/').'/menu-sync/import', [
|
||||
'menus' => $menuData,
|
||||
]);
|
||||
|
||||
@@ -242,9 +242,11 @@ public function push(Request $request): JsonResponse
|
||||
]);
|
||||
}
|
||||
|
||||
$errorMsg = $response->json('message') ?? $response->json('error') ?? '원격 서버 오류 (HTTP '.$response->status().')';
|
||||
|
||||
return response()->json([
|
||||
'error' => $response->json('error', '원격 서버 오류'),
|
||||
], $response->status());
|
||||
'error' => $errorMsg,
|
||||
], 422);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => '연결 실패: '.$e->getMessage()], 500);
|
||||
}
|
||||
@@ -380,7 +382,7 @@ private function getChildrenData(int $parentId): array
|
||||
return $children->map(function ($menu) {
|
||||
return [
|
||||
'name' => $menu->name,
|
||||
'url' => $menu->url,
|
||||
'url' => $menu->url ?? '',
|
||||
'icon' => $menu->icon,
|
||||
'sort_order' => $menu->sort_order,
|
||||
'options' => $menu->options,
|
||||
@@ -700,7 +702,7 @@ private function importMenu(array $data, ?int $parentId = null): void
|
||||
'parent_id' => $parentId,
|
||||
],
|
||||
[
|
||||
'url' => $data['url'],
|
||||
'url' => ! empty($data['url']) ? $data['url'] : null,
|
||||
'icon' => $data['icon'] ?? null,
|
||||
'sort_order' => $data['sort_order'] ?? 0,
|
||||
'options' => $data['options'] ?? null,
|
||||
|
||||
Reference in New Issue
Block a user