51 lines
2.0 KiB
PHP
51 lines
2.0 KiB
PHP
<?php namespace App\Http\Controllers\Dashboard;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller as BaseController;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ObrasController extends BaseController
|
|
{
|
|
public function Obras(Request $request)
|
|
{
|
|
$query = $request->only(['start', 'end', 'type', 'action']);
|
|
$query = array_merge($query, ['action' => 'index', 'type' => 'api'], $query);
|
|
|
|
try {
|
|
$response = Http::timeout(5)->get('https://obras-information.comalcalco.gob.mx/api/controller.php', $query);
|
|
|
|
if (! $response->successful()) {
|
|
return response()->json(['error' => 'External service error'], $response->status());
|
|
}
|
|
|
|
$mainData = $response->json();
|
|
|
|
$counterQuery = array_merge($query, ['action' => 'getCounters']);
|
|
$countersResponse = Http::timeout(5)->get('https://obras-information.comalcalco.gob.mx/api/controller.php', $counterQuery);
|
|
|
|
$countersData = [];
|
|
if ($countersResponse->successful()) {
|
|
$countersData = $countersResponse->json();
|
|
}
|
|
|
|
$usersQuery = array_merge($query, ['action' => 'actionsOfSupervisors']);
|
|
$userResponse = Http::timeout(5)->get('https://obras-information.comalcalco.gob.mx/api/controller.php', $usersQuery);
|
|
|
|
$usersData = [];
|
|
if($userResponse->successful()) {
|
|
$usersData = $userResponse->json();
|
|
}
|
|
|
|
// Combinar ambas respuestas
|
|
$combinedData = array_merge($mainData, ['counters' => $countersData, 'users' => $usersData]);
|
|
|
|
return response()->json($combinedData, $response->status())
|
|
->header('Content-Type', $response->header('Content-Type', 'application/json'));
|
|
} catch (\Throwable $e) {
|
|
Log::error('Proxy error: '.$e->getMessage());
|
|
return response()->json(['error' => 'Unable to contact external service'], 502);
|
|
}
|
|
}
|
|
}
|