2017-12-26 05:19:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Controller;
|
2017-12-26 05:19:34 +08:00
|
|
|
use App\Repositories\AcarsRepository;
|
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-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* Class AcarsController
|
|
|
|
* @package App\Http\Controllers\Api
|
|
|
|
*/
|
|
|
|
class AcarsController extends Controller
|
2017-12-26 05:19:34 +08:00
|
|
|
{
|
2018-03-20 09:50:40 +08:00
|
|
|
private $acarsRepo,
|
|
|
|
$geoSvc;
|
2017-12-26 05:19:34 +08:00
|
|
|
|
2018-02-21 12:33:09 +08:00
|
|
|
/**
|
|
|
|
* AcarsController constructor.
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param GeoService $geoSvc
|
2018-02-21 12:33:09 +08:00
|
|
|
* @param AcarsRepository $acarsRepo
|
|
|
|
*/
|
2017-12-26 05:19:34 +08:00
|
|
|
public function __construct(
|
2017-12-28 06:47:22 +08:00
|
|
|
GeoService $geoSvc,
|
2018-03-20 09:50:40 +08:00
|
|
|
AcarsRepository $acarsRepo
|
2017-12-26 05:19:34 +08:00
|
|
|
) {
|
2017-12-28 06:47:22 +08:00
|
|
|
$this->geoSvc = $geoSvc;
|
2017-12-26 05:19:34 +08:00
|
|
|
$this->acarsRepo = $acarsRepo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
}
|
|
|
|
}
|