From 20c30efaf37ae21d2ec29d5b6567212cf8c69106 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Fri, 18 Aug 2023 18:11:27 +0100 Subject: [PATCH 1/2] feat: allow deleted measures to be retrieved from the plugin api --- app/Http/Controllers/PluginApiController.php | 5 +- tests/Api/PluginTest.php | 49 ++++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/PluginApiController.php b/app/Http/Controllers/PluginApiController.php index 0b75e4cc..390cb8b5 100644 --- a/app/Http/Controllers/PluginApiController.php +++ b/app/Http/Controllers/PluginApiController.php @@ -9,6 +9,7 @@ use App\Models\FlightInformationRegion; use App\Repository\FlowMeasureRepository; use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; class PluginApiController { @@ -19,7 +20,7 @@ public function __construct(FlowMeasureRepository $flowMeasureRepository) $this->flowMeasureRepository = $flowMeasureRepository; } - public function __invoke(): JsonResponse + public function __invoke(Request $request): JsonResponse { return response()->json( [ @@ -28,7 +29,7 @@ public function __invoke(): JsonResponse FlightInformationRegion::all() ), 'flow_measures' => FlowMeasureResource::collection( - $this->flowMeasureRepository->getApiRelevantFlowMeasures(false) + $this->flowMeasureRepository->getApiRelevantFlowMeasures($request->query('deleted', '0') === '1') ), ] ); diff --git a/tests/Api/PluginTest.php b/tests/Api/PluginTest.php index 70a540d3..b4d0ba7e 100644 --- a/tests/Api/PluginTest.php +++ b/tests/Api/PluginTest.php @@ -75,4 +75,53 @@ public function testItReturnsPluginApiData() ] ); } + + public function testItReturnsPluginApiDataWithDeleted() + { + FlightInformationRegion::factory()->count(5)->create(); + Event::factory()->count(3)->create(); + + // Should show + $active = FlowMeasure::factory() + ->create(); + + $notStarted = FlowMeasure::factory() + ->notStarted() + ->create(); + + $finished = FlowMeasure::factory() + ->finished() + ->create(); + + // Should show, deleted + $deleted = FlowMeasure::factory() + ->create(); + $deleted->delete(); + + // Shouldn't show, too far in the future + FlowMeasure::factory() + ->withTimes(Carbon::now()->addDay()->addHour(), Carbon::now()->addDay()->addHours(2)) + ->withEvent() + ->create(); + + // Shouldn't show, too far in the past + FlowMeasure::factory() + ->withTimes(Carbon::now()->subDay()->subHours(3), Carbon::now()->subDay()->subHours(2)) + ->withEvent() + ->create(); + + $this->get('api/v1/plugin?deleted=1') + ->assertStatus(200) + ->assertExactJson( + [ + 'events' => EventResource::collection(Event::all())->toArray(new Request()), + 'flight_information_regions' => FlightInformationRegionResource::collection( + FlightInformationRegion::all() + )->toArray(new Request()), + 'flow_measures' => FlowMeasureResource::collection( + FlowMeasure::whereIn('id', [$active->id, $notStarted->id, $finished->id, $deleted->id])->get() + )->toArray(new Request()), + ] + ); + } } From 1a001d805927809e2b75b9f795b93e21dbc171d4 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Fri, 18 Aug 2023 21:08:41 +0100 Subject: [PATCH 2/2] fix: add missing trashed --- tests/Api/PluginTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Api/PluginTest.php b/tests/Api/PluginTest.php index b4d0ba7e..d1c82224 100644 --- a/tests/Api/PluginTest.php +++ b/tests/Api/PluginTest.php @@ -119,7 +119,7 @@ public function testItReturnsPluginApiDataWithDeleted() FlightInformationRegion::all() )->toArray(new Request()), 'flow_measures' => FlowMeasureResource::collection( - FlowMeasure::whereIn('id', [$active->id, $notStarted->id, $finished->id, $deleted->id])->get() + FlowMeasure::whereIn('id', [$active->id, $notStarted->id, $finished->id, $deleted->id])->withTrashed()->get() )->toArray(new Request()), ] );