style: Pint 포맷팅 적용
This commit is contained in:
@@ -21,6 +21,7 @@ class CommonCodeSyncController extends Controller
|
||||
protected function getTenantId(): int
|
||||
{
|
||||
$tenantId = session('selected_tenant_id');
|
||||
|
||||
return ($tenantId && $tenantId !== 'all') ? (int) $tenantId : 1;
|
||||
}
|
||||
|
||||
@@ -153,6 +154,7 @@ public function import(Request $request): JsonResponse
|
||||
|
||||
if ($exists) {
|
||||
$skipped++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -170,7 +172,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,
|
||||
]);
|
||||
@@ -199,6 +201,7 @@ public function push(Request $request): JsonResponse
|
||||
$localCodes = $this->getCodeList($validated['type']);
|
||||
$selectedCodes = array_filter($localCodes, function ($code) use ($validated) {
|
||||
$key = $this->makeCodeKey($code);
|
||||
|
||||
return in_array($key, $validated['code_keys']);
|
||||
});
|
||||
|
||||
@@ -211,7 +214,7 @@ public function push(Request $request): JsonResponse
|
||||
$response = Http::withHeaders([
|
||||
'X-Menu-Sync-Key' => $env['api_key'],
|
||||
'Accept' => 'application/json',
|
||||
])->post(rtrim($env['url'], '/') . '/common-code-sync/import', [
|
||||
])->post(rtrim($env['url'], '/').'/common-code-sync/import', [
|
||||
'codes' => array_values($selectedCodes),
|
||||
]);
|
||||
|
||||
@@ -228,7 +231,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,6 +264,7 @@ public function pull(Request $request): JsonResponse
|
||||
// 선택된 코드만 필터링
|
||||
$selectedCodes = array_filter($remoteCodes, function ($code) use ($validated) {
|
||||
$key = $this->makeCodeKey($code);
|
||||
|
||||
return in_array($key, $validated['code_keys']);
|
||||
});
|
||||
|
||||
@@ -282,6 +286,7 @@ public function pull(Request $request): JsonResponse
|
||||
|
||||
if ($exists) {
|
||||
$skipped++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -299,7 +304,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,
|
||||
]);
|
||||
@@ -307,7 +312,8 @@ public function pull(Request $request): JsonResponse
|
||||
|
||||
/**
|
||||
* 코드 목록 조회
|
||||
* @param string $type 'global', 'tenant', or 'all'
|
||||
*
|
||||
* @param string $type 'global', 'tenant', or 'all'
|
||||
*/
|
||||
private function getCodeList(string $type = 'all'): array
|
||||
{
|
||||
@@ -369,12 +375,12 @@ private function fetchRemoteCodes(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'], '/') . '/common-code-sync/export', [
|
||||
])->timeout(10)->get(rtrim($env['url'], '/').'/common-code-sync/export', [
|
||||
'type' => $type,
|
||||
]);
|
||||
|
||||
if (! $response->successful()) {
|
||||
throw new \Exception('API 오류: HTTP ' . $response->status());
|
||||
throw new \Exception('API 오류: HTTP '.$response->status());
|
||||
}
|
||||
|
||||
$data = $response->json();
|
||||
@@ -393,6 +399,7 @@ private function fetchRemoteCodes(array $env, string $type = 'all'): array
|
||||
private function makeCodeKey(array $code): string
|
||||
{
|
||||
$tenantPart = $code['tenant_id'] ?? 'global';
|
||||
|
||||
return "{$tenantPart}:{$code['code_group']}:{$code['code']}";
|
||||
}
|
||||
|
||||
@@ -401,8 +408,8 @@ private function makeCodeKey(array $code): string
|
||||
*/
|
||||
private function calculateDiff(array $localCodes, array $remoteCodes): array
|
||||
{
|
||||
$localKeys = array_map(fn($c) => $this->makeCodeKey($c), $localCodes);
|
||||
$remoteKeys = array_map(fn($c) => $this->makeCodeKey($c), $remoteCodes);
|
||||
$localKeys = array_map(fn ($c) => $this->makeCodeKey($c), $localCodes);
|
||||
$remoteKeys = array_map(fn ($c) => $this->makeCodeKey($c), $remoteCodes);
|
||||
|
||||
return [
|
||||
'local_only' => array_values(array_diff($localKeys, $remoteKeys)),
|
||||
|
||||
Reference in New Issue
Block a user