fix response

This commit is contained in:
Jethro Lin 2024-12-04 13:53:58 +08:00
parent e1119a9426
commit 27cad57159

View file

@ -45,7 +45,14 @@ public function index(): JsonResponse
'created_at', 'created_at',
])->get(); ])->get();
return $this->success($clients); return $this->success([
'items' => $clients->map(fn($client) => [
'id' => $client->id,
'name' => $client->name,
'llm_provider_id' => $client->llm_provider_id,
'created_at' => $client->created_at->toIso8601String(),
])
]);
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('Error fetching clients', [ Log::error('Error fetching clients', [
@ -81,14 +88,11 @@ public function store(Request $request): JsonResponse
]); ]);
$validated['status'] = Client::STATUS_ACTIVE; $validated['status'] = Client::STATUS_ACTIVE;
$validated['rate_limit'] = config('llm.default_rate_limit', 60); // 默認每分鐘 60 次 $validated['rate_limit'] = config('llm.default_rate_limit', 60);
$validated['timeout'] = config('llm.default_timeout', 30); // 默認 30 秒 $validated['timeout'] = config('llm.default_timeout', 30);
$client = Client::create($validated); $client = Client::create($validated);
// 加載 LLM 提供商信息
$client->load('llmProvider:id,name,service_name');
$this->logService->logOperation( $this->logService->logOperation(
'admin', 'admin',
$this->admin->id, $this->admin->id,
@ -153,9 +157,6 @@ public function update(Request $request, int $id): JsonResponse
$client->update($validated); $client->update($validated);
// 加載 LLM 提供商信息
$client->load('llmProvider:id,name,service_name');
$this->logService->logOperation( $this->logService->logOperation(
'admin', 'admin',
$this->admin->id, $this->admin->id,
@ -257,7 +258,7 @@ public function generateAuthToken(int $id): JsonResponse
if (!$this->admin->canManageClient($client->id)) { if (!$this->admin->canManageClient($client->id)) {
return $this->error( return $this->error(
ErrorCode::FORBIDDEN, ErrorCode::FORBIDDEN,
'您無<EFBFBD><EFBFBD>管理該客戶。' '您無管理該客戶。'
); );
} }
@ -277,8 +278,9 @@ public function generateAuthToken(int $id): JsonResponse
); );
return $this->success([ return $this->success([
'client_id' => $client->id,
'auth_token' => $result['token'], 'auth_token' => $result['token'],
'expires_at' => $result['expires_at'], 'created_at' => now()->toIso8601String(),
]); ]);
} catch (ModelNotFoundException $e) { } catch (ModelNotFoundException $e) {