46 lines
1.9 KiB
PHP
46 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\IntegrationHub\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Modules\IntegrationHub\Models\IhExportJob;
|
|
use Modules\IntegrationHub\Models\IhOdataToken;
|
|
use Modules\IntegrationHub\Models\IhWebhookDelivery;
|
|
use Modules\IntegrationHub\Models\IhWebhookEndpoint;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
if (! auth()->user()->can('integrationhub.access')) {
|
|
abort(403);
|
|
}
|
|
|
|
$business_id = (int) $request->session()->get('user.business_id');
|
|
|
|
$stats = [
|
|
'webhook_endpoints' => IhWebhookEndpoint::forBusiness($business_id)->count(),
|
|
'active_webhooks' => IhWebhookEndpoint::forBusiness($business_id)->active()->count(),
|
|
'odata_tokens' => IhOdataToken::forBusiness($business_id)->valid()->count(),
|
|
'recent_exports' => IhExportJob::forBusiness($business_id)->latest('id')->limit(5)->count(),
|
|
'failed_deliveries' => IhWebhookDelivery::whereHas('endpoint', fn ($q) => $q->where('business_id', $business_id))
|
|
->where('status', 'failed')
|
|
->where('created_at', '>=', now()->subDays(7))
|
|
->count(),
|
|
];
|
|
|
|
$recentExports = IhExportJob::forBusiness($business_id)->latest('id')->limit(5)->get();
|
|
$recentDeliveries = IhWebhookDelivery::whereHas('endpoint', fn ($q) => $q->where('business_id', $business_id))
|
|
->latest('id')
|
|
->limit(10)
|
|
->with('endpoint')
|
|
->get();
|
|
|
|
$datasets = config('integrationhub.datasets', []);
|
|
$odataDatasets = app(\Modules\IntegrationHub\Services\ODataExportService::class)->availableDatasets();
|
|
|
|
return view('integrationhub::dashboard.index', compact('stats', 'recentExports', 'recentDeliveries', 'datasets', 'odataDatasets'));
|
|
}
|
|
}
|