Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

389 API Changes #393

Merged
merged 9 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
_ide_helper.php
.php_cs.cache
.phpstorm.meta.php
.phpunit.result.cache
/vendor
node_modules/
npm-debug.log
Expand Down
1 change: 1 addition & 0 deletions .travis/deploy_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ if [ "$TRAVIS" = "true" ]; then
.php_cs.cache
.phpstorm.meta.php
.styleci.yml
.phpunit.result.cache
env.php
intellij_style.xml
config.php
Expand Down
28 changes: 28 additions & 0 deletions app/Contracts/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,32 @@ public function whereNotInOrder($col, $values, $sort_by, $order_by = 'asc')
return $q;
});
}

/**
* Retrieve all data of repository, paginated. Added in extra parameter to read from the
* request which page it should be on
*
* @param null $limit
* @param array $columns
* @param string $method
*
* @throws \Prettus\Repository\Exceptions\RepositoryException
*
* @return mixed
*/
public function paginate($limit = null, $columns = ['*'], $method = 'paginate')
{
$this->applyCriteria();
$this->applyScope();

$max = config('repository.pagination.limit', 50);
$limit = (int) ($limit ?? request()->query('limit') ?? $max);
$page = request()->query('page', 1);

$results = $this->model->{$method}($limit, $columns, 'page', $page);
$results->appends(app('request')->query());
$this->resetModel();

return $this->parserResult($results);
}
}
20 changes: 16 additions & 4 deletions app/Http/Controllers/Api/AcarsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Http\Requests\Acars\LogRequest;
use App\Http\Requests\Acars\PositionRequest;
use App\Http\Resources\AcarsRoute as AcarsRouteResource;
use App\Http\Resources\Pirep as PirepResource;
use App\Models\Acars;
use App\Models\Enums\AcarsType;
use App\Models\Enums\PirepStatus;
Expand All @@ -21,9 +22,6 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

/**
* Class AcarsController
*/
class AcarsController extends Controller
{
private $acarsRepo;
Expand Down Expand Up @@ -61,14 +59,28 @@ protected function checkCancelled(Pirep $pirep)
}
}

/**
* Get all the active PIREPs
*
* @return mixed
*/
public function live_flights()
{
$pireps = $this->acarsRepo->getPositions(setting('acars.live_time'))->filter(function ($pirep) {
return $pirep->position !== null;
});

return PirepResource::collection($pireps);
}

/**
* Return all of the flights (as points) in GeoJSON format
*
* @param Request $request
*
* @return mixed
*/
public function index(Request $request)
public function pireps_geojson(Request $request)
{
$pireps = $this->acarsRepo->getPositions(setting('acars.live_time'));
$positions = $this->geoSvc->getFeatureForLiveFlights($pireps);
Expand Down
4 changes: 0 additions & 4 deletions app/Http/Controllers/Api/AirlineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
use App\Repositories\AirlineRepository;
use Illuminate\Http\Request;

/**
* Class AirlineController
*/
class AirlineController extends Controller
{
private $airlineRepo;
Expand All @@ -34,7 +31,6 @@ public function __construct(
*/
public function index(Request $request)
{
//$this->airlineRepo->pushCriteria(new RequestCriteria($request));
$airports = $this->airlineRepo
->whereOrder(['active' => true], 'name', 'asc')
->paginate();
Expand Down
22 changes: 2 additions & 20 deletions app/Http/Controllers/Api/PirepController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
use App\Services\Finance\PirepFinanceService;
use App\Services\PirepService;
use App\Services\UserService;
use Auth;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Log;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;

/**
* Class PirepController
Expand All @@ -52,8 +52,6 @@ class PirepController extends Controller
private $userSvc;

/**
* PirepController constructor.
*
* @param AcarsRepository $acarsRepo
* @param FareService $fareSvc
* @param PirepFinanceService $financeSvc
Expand Down Expand Up @@ -159,22 +157,6 @@ protected function updateFares($pirep, Request $request)
$this->fareSvc->saveForPirep($pirep, $fares);
}

/**
* Get all the active PIREPs
*
* @return mixed
*/
public function index()
{
$pireps = $this->acarsRepo
->getPositions(setting('acars.live_time'))
->filter(function ($pirep) {
return $pirep->position !== null;
});

return PirepResource::collection($pireps);
}

/**
* @param $pirep_id
*
Expand Down
8 changes: 5 additions & 3 deletions app/Http/Routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* Public routes
*/
Route::group([], function () {
Route::get('acars', 'AcarsController@index');
Route::get('pireps', 'PirepController@index');
Route::get('acars', 'AcarsController@live_flights');
Route::get('acars/geojson', 'AcarsController@pireps_geojson');

Route::get('pireps/{pirep_id}', 'PirepController@get');
Route::get('pireps/{pirep_id}/acars/geojson', 'AcarsController@acars_geojson');

Expand All @@ -15,7 +16,7 @@
});

/*
* these need to be authenticated with a user's API key
* These need to be authenticated with a user's API key
*/
Route::group(['middleware' => ['api.auth']], function () {
Route::get('airlines', 'AirlineController@index');
Expand All @@ -35,6 +36,7 @@
Route::get('flights/{id}', 'FlightController@get');
Route::get('flights/{id}/route', 'FlightController@route');

Route::get('pireps', 'UserController@pireps');
Route::put('pireps/{pirep_id}', 'PirepController@update');

/*
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"league/geotools": "0.8.*",
"league/iso3166": "2.1.*",
"markrogoyski/math-php": "^0.38.0",
"myclabs/deep-copy": "1.8.*",
"myclabs/deep-copy": "~1.9.0",
"nabeel/vacentral": "~2.0",
"nwidart/laravel-modules": "~5.1",
"php-units-of-measure/php-units-of-measure": "~2.1.0",
Expand All @@ -60,8 +60,8 @@
"fzaninotto/faker": "~1.8.0",
"friendsofphp/php-cs-fixer": "^2.15",
"mockery/mockery": "0.9.*",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "7.5.*",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "~8.3",
"squizlabs/php_codesniffer": "3.*"
},
"autoload": {
Expand Down
Loading