Updated Google Scholar Integration,Updated Admin and HOD Dashboard, Added Google Auth: Login Controller and Routes

This commit is contained in:
tanmaychinchore
2025-11-18 22:24:53 +05:30
parent 9ee3d3eda4
commit 34394e6abf
9 changed files with 1347 additions and 49 deletions

View File

@@ -10,20 +10,22 @@ class ScholarService
{
try {
// Extract Google Scholar profile ID (e.g., ssU-uBEAAAAJ)
preg_match('/user=([^&]+)/', $url, $match);
preg_match('/[?&]user=([^&]+)/', $url, $match);
$profileId = $match[1] ?? null;
if (!$profileId) {
\Log::warning('No Google Scholar ID found in URL: ' . $url);
return [];
$msg = 'No Google Scholar ID found in URL: ' . $url;
\Log::warning($msg);
return ['error' => $msg];
}
// Load API key from .env
$apiKey = env('SERPAPI_KEY');
if (!$apiKey) {
\Log::error('SERPAPI_KEY not found in environment variables');
return [];
$msg = 'SERPAPI_KEY not found in environment variables';
\Log::error($msg);
return ['error' => $msg];
}
$endpoint = 'https://serpapi.com/search.json';
@@ -34,8 +36,10 @@ class ScholarService
]);
if (!$response->successful()) {
\Log::error('Scholar API request failed: ' . $response->status());
return [];
$status = $response->status();
$body = $response->body();
\Log::error('Scholar API request failed', ['status' => $status, 'body' => $body]);
return ['error' => 'Scholar API request failed: ' . $status, 'body' => $body];
}
$json = $response->json();
@@ -46,8 +50,13 @@ class ScholarService
?? $json['results']
?? [];
if (empty($articles)) {
\Log::warning('Scholar API returned no articles', ['profileId' => $profileId, 'response' => $json]);
return ['error' => 'No publications returned by Scholar API', 'raw' => $json];
}
// ✅ Format and return
return collect($articles)
$formatted = collect($articles)
->map(function ($a) {
return [
'title' => $a['title'] ?? $a['name'] ?? null,
@@ -59,6 +68,8 @@ class ScholarService
})
->toArray();
return ['data' => $formatted];
} catch (\Throwable $e) {
\Log::error('ScholarService API error: ' . $e->getMessage());
return [];