From 2589787f3a20ef4e09d5176197d96c87a3015841 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Mon, 25 Aug 2025 13:55:21 +0330 Subject: [PATCH] create new thing for mission acsses and event and listener --- ...equestEvent.php => SendDataToFMSEvent.php} | 2 +- .../Mission/ControlUnitController.php | 3 ++ .../ConfirmGuaranteeLetterNeedListener.php | 17 +++++++-- .../Harim/ConfirmNoRoadAccessNeedListener.php | 14 +++++++- .../ConfirmRoadAccessEditNeedListener.php | 14 +++++++- .../Harim/ConfirmRoadAccessNeedListener.php | 12 ++++++- .../Dashboard/Harim/RejectRequestListener.php | 10 +++++- .../Mission/FinishRequestListener.php | 35 ------------------- .../Mission/SendDataToFMSListener.php | 28 +++++++++++++++ app/Providers/EventServiceProvider.php | 5 +++ routes/v3.php | 1 + 11 files changed, 99 insertions(+), 42 deletions(-) rename app/Events/V3/Dashboard/Mission/{FinishRequestEvent.php => SendDataToFMSEvent.php} (94%) delete mode 100644 app/Listeners/V3/Dashboard/Mission/FinishRequestListener.php create mode 100644 app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php diff --git a/app/Events/V3/Dashboard/Mission/FinishRequestEvent.php b/app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php similarity index 94% rename from app/Events/V3/Dashboard/Mission/FinishRequestEvent.php rename to app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php index 3569c2b3..f25abfb1 100644 --- a/app/Events/V3/Dashboard/Mission/FinishRequestEvent.php +++ b/app/Events/V3/Dashboard/Mission/SendDataToFMSEvent.php @@ -8,7 +8,7 @@ use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; -class FinishRequestEvent +class SendDataToFMSEvent { use Dispatchable, InteractsWithSockets, SerializesModels; diff --git a/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php b/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php index e919baff..c13d77f0 100644 --- a/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php +++ b/app/Http/Controllers/V3/Dashboard/Mission/ControlUnitController.php @@ -6,6 +6,7 @@ use App\Enums\MissionCategory; use App\Enums\MissionStates; use App\Enums\MissionTypes; use App\Enums\MissionZones; +use App\Events\V3\Dashboard\Mission\SendDataToFMSEvent; use App\Http\Controllers\Controller; use App\Http\Requests\V3\Mission\ControlUnit\FinishRequest; use App\Http\Requests\V3\Mission\ControlUnit\NoProcessRequest; @@ -63,6 +64,8 @@ class ControlUnitController extends Controller ]); }); + SendDataToFMSEvent::dispatch($mission); + return $this->successResponse(); } diff --git a/app/Listeners/V3/Dashboard/Harim/ConfirmGuaranteeLetterNeedListener.php b/app/Listeners/V3/Dashboard/Harim/ConfirmGuaranteeLetterNeedListener.php index 6f9839b8..8dd0eeca 100644 --- a/app/Listeners/V3/Dashboard/Harim/ConfirmGuaranteeLetterNeedListener.php +++ b/app/Listeners/V3/Dashboard/Harim/ConfirmGuaranteeLetterNeedListener.php @@ -3,10 +3,19 @@ namespace App\Listeners\V3\Dashboard\Harim; use App\Events\V3\Dashboard\Harim\ConfirmGuaranteeLetterNeedEvent; +use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; -class ConfirmGuaranteeLetterNeedListener +class ConfirmGuaranteeLetterNeedListener implements ShouldQueue { + /** + * The name of the queue the job should be sent to. + * + * @var string|null + */ + public ?string $queue = 'harim'; + protected string $url; protected string $password; protected string $username; @@ -17,6 +26,10 @@ class ConfirmGuaranteeLetterNeedListener $this->username = config('harim_web_services.reject.username'); $this->password = config('harim_web_services.reject.password'); } + + /** + * @throws RequestException + */ public function handle(ConfirmGuaranteeLetterNeedEvent $event): void { Http::post($this->url, @@ -27,7 +40,7 @@ class ConfirmGuaranteeLetterNeedListener '' => $event->harim->id, '' => $event->harim->id, '' => $event->harim->id, - ' ' => $event->harim->id, + '' => $event->harim->id, ))->throw(); } } diff --git a/app/Listeners/V3/Dashboard/Harim/ConfirmNoRoadAccessNeedListener.php b/app/Listeners/V3/Dashboard/Harim/ConfirmNoRoadAccessNeedListener.php index ce5bc75e..e4a2600c 100644 --- a/app/Listeners/V3/Dashboard/Harim/ConfirmNoRoadAccessNeedListener.php +++ b/app/Listeners/V3/Dashboard/Harim/ConfirmNoRoadAccessNeedListener.php @@ -3,10 +3,19 @@ namespace App\Listeners\V3\Dashboard\Harim; use App\Events\V3\Dashboard\Harim\ConfirmNoRoadAccessNeedEvent; +use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; -class ConfirmNoRoadAccessNeedListener +class ConfirmNoRoadAccessNeedListener implements ShouldQueue { + /** + * The name of the queue the job should be sent to. + * + * @var string|null + */ + public ?string $queue = 'harim'; + protected string $url; protected string $password; protected string $username; @@ -18,6 +27,9 @@ class ConfirmNoRoadAccessNeedListener $this->password = config('harim_web_services.reject.password'); } + /** + * @throws RequestException + */ public function handle(ConfirmNoRoadAccessNeedEvent $event): void { Http::post($this->url, diff --git a/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessEditNeedListener.php b/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessEditNeedListener.php index b0a84311..7ad2e903 100644 --- a/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessEditNeedListener.php +++ b/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessEditNeedListener.php @@ -3,10 +3,19 @@ namespace App\Listeners\V3\Dashboard\Harim; use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessEditNeedEvent; +use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; -class ConfirmRoadAccessEditNeedListener +class ConfirmRoadAccessEditNeedListener implements ShouldQueue { + /** + * The name of the queue the job should be sent to. + * + * @var string|null + */ + public ?string $queue = 'harim'; + protected string $url; protected string $password; protected string $username; @@ -18,6 +27,9 @@ class ConfirmRoadAccessEditNeedListener $this->password = config('harim_web_services.reject.password'); } + /** + * @throws RequestException + */ public function handle(ConfirmRoadAccessEditNeedEvent $event): void { Http::post($this->url, diff --git a/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessNeedListener.php b/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessNeedListener.php index eb07807e..c94bc368 100644 --- a/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessNeedListener.php +++ b/app/Listeners/V3/Dashboard/Harim/ConfirmRoadAccessNeedListener.php @@ -3,10 +3,19 @@ namespace App\Listeners\V3\Dashboard\Harim; use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessNeedEvent; +use Illuminate\Contracts\Queue\ShouldQueue; +use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; -class ConfirmRoadAccessNeedListener +class ConfirmRoadAccessNeedListener implements ShouldQueue { + /** + * The name of the queue the job should be sent to. + * + * @var string|null + */ + public ?string $queue = 'harim'; + protected string $url; protected string $password; protected string $username; @@ -20,6 +29,7 @@ class ConfirmRoadAccessNeedListener /** * Handle the event. + * @throws RequestException */ public function handle(ConfirmRoadAccessNeedEvent $event): void { diff --git a/app/Listeners/V3/Dashboard/Harim/RejectRequestListener.php b/app/Listeners/V3/Dashboard/Harim/RejectRequestListener.php index ce50d817..6ccc698c 100644 --- a/app/Listeners/V3/Dashboard/Harim/RejectRequestListener.php +++ b/app/Listeners/V3/Dashboard/Harim/RejectRequestListener.php @@ -3,11 +3,19 @@ namespace App\Listeners\V3\Dashboard\Harim; use App\Events\V3\Dashboard\Harim\RejectRequestEvent; +use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Http\Client\RequestException; use Illuminate\Support\Facades\Http; -class RejectRequestListener +class RejectRequestListener implements ShouldQueue { + /** + * The name of the queue the job should be sent to. + * + * @var string|null + */ + public ?string $queue = 'harim'; + protected string $url; protected string $password; protected string $username; diff --git a/app/Listeners/V3/Dashboard/Mission/FinishRequestListener.php b/app/Listeners/V3/Dashboard/Mission/FinishRequestListener.php deleted file mode 100644 index be6e1d49..00000000 --- a/app/Listeners/V3/Dashboard/Mission/FinishRequestListener.php +++ /dev/null @@ -1,35 +0,0 @@ -url = config('App\Services\FMSService.url'); - $this->username = config('App\Services\FMSService.username'); - $this->password = config('App\Services\FMSService.password'); - } - - /** - * @throws RequestException - */ - public function handle(FinishRequestEvent $event): void - { - Http::post($this->url, - array( - 'area' => $event->mission->area, - 'machine_code' => $event->mission->machines()->pluck('machines.machine_code'), - 'start_date' => $event->mission->start_date, - 'end_date' => $event->mission->end_date, - ))->throw(); - } -} diff --git a/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php b/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php new file mode 100644 index 00000000..26c98a2c --- /dev/null +++ b/app/Listeners/V3/Dashboard/Mission/SendDataToFMSListener.php @@ -0,0 +1,28 @@ +run($event->mission); + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 3686d436..16c73d00 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -7,11 +7,13 @@ use App\Events\V3\Dashboard\Harim\ConfirmNoRoadAccessNeedEvent; use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessEditNeedEvent; use App\Events\V3\Dashboard\Harim\ConfirmRoadAccessNeedEvent; use App\Events\V3\Dashboard\Harim\RejectRequestEvent; +use App\Events\V3\Dashboard\Mission\SendDataToFMSEvent; use App\Listeners\V3\Dashboard\Harim\ConfirmGuaranteeLetterNeedListener; use App\Listeners\V3\Dashboard\Harim\ConfirmNoRoadAccessNeedListener; use App\Listeners\V3\Dashboard\Harim\ConfirmRoadAccessEditNeedListener; use App\Listeners\V3\Dashboard\Harim\ConfirmRoadAccessNeedListener; use App\Listeners\V3\Dashboard\Harim\RejectRequestListener; +use App\Listeners\V3\Dashboard\Mission\SendDataToFMSListener; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; @@ -50,6 +52,9 @@ class EventServiceProvider extends ServiceProvider ], ConfirmGuaranteeLetterNeedEvent::class => [ ConfirmGuaranteeLetterNeedListener::class + ], + SendDataToFMSEvent::class => [ + SendDataToFMSListener::class ] ]; diff --git a/routes/v3.php b/routes/v3.php index 717202a6..f211be1a 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -500,6 +500,7 @@ Route::prefix('missions') ->controller(ControlUnitController::class) ->group(function () { Route::get('/', 'index')->name('index'); + Route::post('/no_process','noProcess')->name('noProcess'); Route::post('/start/{mission}', 'start')->name('start'); Route::post('/finish/{mission}', 'finish')->name('finish'); });