style: Pint 포맷팅 적용
This commit is contained in:
@@ -22,6 +22,7 @@ class CategorySyncController extends Controller
|
||||
protected function getTenantId(): int
|
||||
{
|
||||
$tenantId = session('selected_tenant_id');
|
||||
|
||||
return ($tenantId && $tenantId !== 'all') ? (int) $tenantId : 1;
|
||||
}
|
||||
|
||||
@@ -155,6 +156,7 @@ public function import(Request $request): JsonResponse
|
||||
|
||||
if ($exists) {
|
||||
$skipped++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -188,6 +190,7 @@ public function import(Request $request): JsonResponse
|
||||
|
||||
if ($exists) {
|
||||
$skipped++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -218,7 +221,7 @@ public function import(Request $request): JsonResponse
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "{$imported}개 카테고리가 동기화되었습니다." . ($skipped > 0 ? " ({$skipped}개 스킵)" : ''),
|
||||
'message' => "{$imported}개 카테고리가 동기화되었습니다.".($skipped > 0 ? " ({$skipped}개 스킵)" : ''),
|
||||
'imported' => $imported,
|
||||
'skipped' => $skipped,
|
||||
]);
|
||||
@@ -247,6 +250,7 @@ public function push(Request $request): JsonResponse
|
||||
$localCategories = $this->getCategoryList($validated['type']);
|
||||
$selectedCategories = array_filter($localCategories, function ($cat) use ($validated) {
|
||||
$key = $this->makeCategoryKey($cat);
|
||||
|
||||
return in_array($key, $validated['category_keys']);
|
||||
});
|
||||
|
||||
@@ -259,7 +263,7 @@ public function push(Request $request): JsonResponse
|
||||
$response = Http::withHeaders([
|
||||
'X-Menu-Sync-Key' => $env['api_key'],
|
||||
'Accept' => 'application/json',
|
||||
])->post(rtrim($env['url'], '/') . '/category-sync/import', [
|
||||
])->post(rtrim($env['url'], '/').'/category-sync/import', [
|
||||
'categories' => array_values($selectedCategories),
|
||||
]);
|
||||
|
||||
@@ -276,7 +280,7 @@ public function push(Request $request): JsonResponse
|
||||
'error' => $response->json('error', '원격 서버 오류'),
|
||||
], $response->status());
|
||||
} catch (\Exception $e) {
|
||||
return response()->json(['error' => '연결 실패: ' . $e->getMessage()], 500);
|
||||
return response()->json(['error' => '연결 실패: '.$e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -309,6 +313,7 @@ public function pull(Request $request): JsonResponse
|
||||
// 선택된 카테고리만 필터링
|
||||
$selectedCategories = array_filter($remoteCategories, function ($cat) use ($validated) {
|
||||
$key = $this->makeCategoryKey($cat);
|
||||
|
||||
return in_array($key, $validated['category_keys']);
|
||||
});
|
||||
|
||||
@@ -328,6 +333,7 @@ public function pull(Request $request): JsonResponse
|
||||
|
||||
if ($exists) {
|
||||
$skipped++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -359,6 +365,7 @@ public function pull(Request $request): JsonResponse
|
||||
|
||||
if ($exists) {
|
||||
$skipped++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -388,7 +395,7 @@ public function pull(Request $request): JsonResponse
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "{$imported}개 카테고리가 동기화되었습니다." . ($skipped > 0 ? " ({$skipped}개 스킵)" : ''),
|
||||
'message' => "{$imported}개 카테고리가 동기화되었습니다.".($skipped > 0 ? " ({$skipped}개 스킵)" : ''),
|
||||
'imported' => $imported,
|
||||
'skipped' => $skipped,
|
||||
]);
|
||||
@@ -396,7 +403,8 @@ public function pull(Request $request): JsonResponse
|
||||
|
||||
/**
|
||||
* 카테고리 목록 조회
|
||||
* @param string $type 'global', 'tenant', or 'all'
|
||||
*
|
||||
* @param string $type 'global', 'tenant', or 'all'
|
||||
*/
|
||||
private function getCategoryList(string $type = 'all'): array
|
||||
{
|
||||
@@ -472,12 +480,12 @@ private function fetchRemoteCategories(array $env, string $type = 'all'): array
|
||||
$response = Http::withHeaders([
|
||||
'X-Menu-Sync-Key' => $env['api_key'],
|
||||
'Accept' => 'application/json',
|
||||
])->timeout(10)->get(rtrim($env['url'], '/') . '/category-sync/export', [
|
||||
])->timeout(10)->get(rtrim($env['url'], '/').'/category-sync/export', [
|
||||
'type' => $type,
|
||||
]);
|
||||
|
||||
if (! $response->successful()) {
|
||||
throw new \Exception('API 오류: HTTP ' . $response->status());
|
||||
throw new \Exception('API 오류: HTTP '.$response->status());
|
||||
}
|
||||
|
||||
$data = $response->json();
|
||||
@@ -496,6 +504,7 @@ private function fetchRemoteCategories(array $env, string $type = 'all'): array
|
||||
private function makeCategoryKey(array $cat): string
|
||||
{
|
||||
$typePart = $cat['is_global'] ? 'global' : "tenant:{$cat['tenant_id']}";
|
||||
|
||||
return "{$typePart}:{$cat['code_group']}:{$cat['code']}";
|
||||
}
|
||||
|
||||
@@ -504,8 +513,8 @@ private function makeCategoryKey(array $cat): string
|
||||
*/
|
||||
private function calculateDiff(array $localCategories, array $remoteCategories): array
|
||||
{
|
||||
$localKeys = array_map(fn($c) => $this->makeCategoryKey($c), $localCategories);
|
||||
$remoteKeys = array_map(fn($c) => $this->makeCategoryKey($c), $remoteCategories);
|
||||
$localKeys = array_map(fn ($c) => $this->makeCategoryKey($c), $localCategories);
|
||||
$remoteKeys = array_map(fn ($c) => $this->makeCategoryKey($c), $remoteCategories);
|
||||
|
||||
return [
|
||||
'local_only' => array_values(array_diff($localKeys, $remoteKeys)),
|
||||
|
||||
Reference in New Issue
Block a user