Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CalumTowers committed Jan 20, 2025
1 parent 3d2e426 commit 5e6837d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace App\Http\Controllers\External\VatsimNet;

use App\Http\Controllers\BaseController;
use App\Jobs\ExternalServices\VatsimNet\Webhooks\MemberChangedAction;
use App\Jobs\ExternalServices\VatsimNet\Webhooks\MemberCreatedAction;
use Illuminate\Support\Facades\Log;

class ProcessVatsimNetWebhook extends BaseController
{
Expand All @@ -15,10 +18,19 @@ public function __invoke()
}

foreach (request()->json('actions') as $action) {
$class = config("services.vatsim-net.webhook.jobs.{$action['action']}");
if ($class && class_exists($class)) {
dispatch(new $class(request()->json('resource'), $action))->afterResponse();
$class = match ($action['action']) {
'member_created_action' => MemberCreatedAction::class,
'member_changed_action' => MemberChangedAction::class,
default => null,
};

if (! $class) {
Log::error("Unhandled webhook from VATSIM.net: {$action['action']}");

continue;
}

dispatch(new $class(request()->json('resource'), $action))->afterResponse();
}

return response()->json([
Expand Down
7 changes: 0 additions & 7 deletions config/services.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php

use App\Jobs\ExternalServices\VatsimNet\Webhooks\MemberChangedAction;
use App\Jobs\ExternalServices\VatsimNet\Webhooks\MemberCreatedAction;

return [

/*
Expand Down Expand Up @@ -81,10 +78,6 @@
'vatsim-net' => [
'webhook' => [
'key' => env('VATSIM_NET_WEBHOOK_KEY'),
'jobs' => [
'member_created_action' => MemberCreatedAction::class,
'member_changed_action' => MemberChangedAction::class,
],
],
'api' => [
'base' => env('VATSIM_API_BASE', 'https://api.vatsim.net/api/'),
Expand Down

0 comments on commit 5e6837d

Please sign in to comment.