Skip to content

Commit

Permalink
Merge pull request #395 from ECFMP/plugin-api-deleted
Browse files Browse the repository at this point in the history
feat: allow deleted measures to be retrieved from the plugin api
  • Loading branch information
AndyTWF authored Aug 18, 2023
2 parents 6ed4b09 + 1a001d8 commit bd28d4e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/Http/Controllers/PluginApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Models\FlightInformationRegion;
use App\Repository\FlowMeasureRepository;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class PluginApiController
{
Expand All @@ -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(
[
Expand All @@ -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')
),
]
);
Expand Down
49 changes: 49 additions & 0 deletions tests/Api/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])->withTrashed()->get()
)->toArray(new Request()),
]
);
}
}

0 comments on commit bd28d4e

Please sign in to comment.