2017-12-26 05:19:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
use App\Repositories\AcarsRepository;
|
|
|
|
use App\Repositories\PirepRepository;
|
2018-02-21 12:33:09 +08:00
|
|
|
use App\Services\GeoService;
|
|
|
|
use Illuminate\Http\Request;
|
2017-12-26 05:19:34 +08:00
|
|
|
|
|
|
|
|
2018-01-06 00:45:34 +08:00
|
|
|
class AcarsController extends RestController
|
2017-12-26 05:19:34 +08:00
|
|
|
{
|
2017-12-28 06:47:22 +08:00
|
|
|
protected $acarsRepo, $geoSvc, $pirepRepo;
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
/**
|
|
|
|
* AcarsController constructor.
|
|
|
|
* @param GeoService $geoSvc
|
|
|
|
* @param AcarsRepository $acarsRepo
|
|
|
|
* @param PirepRepository $pirepRepo
|
|
|
|
*/
|
2017-12-26 05:19:34 +08:00
|
|
|
public function __construct(
|
2017-12-28 06:47:22 +08:00
|
|
|
GeoService $geoSvc,
|
2017-12-26 05:19:34 +08:00
|
|
|
AcarsRepository $acarsRepo,
|
|
|
|
PirepRepository $pirepRepo
|
|
|
|
) {
|
2017-12-28 06:47:22 +08:00
|
|
|
$this->geoSvc = $geoSvc;
|
2017-12-26 05:19:34 +08:00
|
|
|
$this->acarsRepo = $acarsRepo;
|
|
|
|
$this->pirepRepo = $pirepRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-28 06:47:22 +08:00
|
|
|
* Return all of the flights (as points) in GeoJSON format
|
2018-02-21 12:33:09 +08:00
|
|
|
* @param Request $request
|
|
|
|
* @return mixed
|
2017-12-26 05:19:34 +08:00
|
|
|
*/
|
2017-12-28 06:47:22 +08:00
|
|
|
public function index(Request $request)
|
2017-12-26 05:19:34 +08:00
|
|
|
{
|
2017-12-28 06:47:22 +08:00
|
|
|
$pireps = $this->acarsRepo->getPositions();
|
|
|
|
$positions = $this->geoSvc->getFeatureForLiveFlights($pireps);
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2017-12-28 06:47:22 +08:00
|
|
|
return response(json_encode($positions), 200, [
|
|
|
|
'Content-type' => 'application/json'
|
|
|
|
]);
|
2017-12-26 05:19:34 +08:00
|
|
|
}
|
|
|
|
}
|