Skip to content

Commit

Permalink
Update SyncWebhookController.php
Browse files Browse the repository at this point in the history
  • Loading branch information
adrolli committed Sep 4, 2024
1 parent 6e3f651 commit 5a418c5
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions packages/sync/src/Http/Controllers/SyncWebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ public function __construct()

public function handle(Request $request)
{
$this->logDebug('SyncWebhookController handle method entered with data', ['data' => $request->all()]);
$this->logDebug('SyncWebhookController handle method entered', ['full_request_data' => $request->all()]);

try {
$validatedData = $this->validateRequest($request);

$this->logDebug('SyncWebhookController validated request', ['data' => $validatedData]);
$this->logDebug('SyncWebhookController validated request', ['validated_data' => $validatedData]);

// Log specific fields we're interested in
$this->logDebug('Important fields from validated data', [
'event_type' => $validatedData['event_type'],
'model_class' => $validatedData['model_class'],
'user_registered' => $validatedData['model']['user_registered'] ?? 'not set',
'capabilities' => $validatedData['model']['jku8u_capabilities'] ?? 'not set',
'description' => $validatedData['model']['description'] ?? 'not set',
// Add any other fields you want to check
]);

$sourcePlatform = Platform::where('domain', $validatedData['platform']['domain'])->first();

Expand All @@ -37,6 +47,14 @@ public function handle(Request $request)
throw new \Exception('Model ID not found in the request data');
}

// Log the exact data being passed to SyncJob
$this->logDebug('Data being passed to SyncJob', [
'model_class' => $validatedData['model_class'],
'model_data' => $validatedData['model'],
'event_type' => $validatedData['event_type'],
'source_platform_id' => $sourcePlatform->id,
]);

SyncJob::dispatch(
$validatedData['model_class'],
$validatedData['model'],
Expand All @@ -53,22 +71,29 @@ public function handle(Request $request)

return response()->json(['status' => 'success'], 200);
} catch (\Exception $e) {
$this->logDebug('SyncWebhookController encountered an error', ['error' => $e->getMessage()]);
$this->logDebug('SyncWebhookController encountered an error', [
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
]);

return response()->json(['status' => 'error', 'message' => $e->getMessage()], 500);
}
}

protected function validateRequest(Request $request)
{
$this->logDebug('SyncWebhookController validating request', ['data' => $request->all()]);
$this->logDebug('SyncWebhookController validating request', ['raw_request_data' => $request->all()]);

return $request->validate([
$validatedData = $request->validate([
'event_type' => 'required|string|in:created,updated,deleted',
'model' => 'required|array',
'model_class' => 'required|string',
'platform' => 'required|array',
'platform.domain' => 'required|string',
]);

$this->logDebug('Request validation result', ['validated_data' => $validatedData]);

return $validatedData;
}
}

0 comments on commit 5a418c5

Please sign in to comment.