From 5b061ba636b88c1211cd7a13b62fc2bdcb197b50 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 10 May 2019 16:03:04 -0500 Subject: [PATCH 01/12] Add greater than/less than search options #297 --- app/Database/factories/FlightFactory.php | 2 +- app/Http/Controllers/Api/FlightController.php | 21 +++++----- .../Controllers/Frontend/FlightController.php | 2 + app/Repositories/Criteria/WhereCriteria.php | 6 +++ app/Repositories/FlightRepository.php | 10 +++++ swagger.yml | 0 tests/FlightTest.php | 38 +++++++++++++++++++ 7 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 swagger.yml diff --git a/app/Database/factories/FlightFactory.php b/app/Database/factories/FlightFactory.php index 327ba2f4..248427cf 100644 --- a/app/Database/factories/FlightFactory.php +++ b/app/Database/factories/FlightFactory.php @@ -22,7 +22,7 @@ $factory->define(App\Models\Flight::class, function (Faker $faker) { 'alt_airport_id' => function () { return factory(App\Models\Airport::class)->create()->id; }, - 'distance' => $faker->numberBetween(0, 3000), + 'distance' => $faker->numberBetween(0, 1000), 'route' => null, 'level' => 0, 'dpt_time' => $faker->time(), diff --git a/app/Http/Controllers/Api/FlightController.php b/app/Http/Controllers/Api/FlightController.php index a27613cf..7d474f58 100644 --- a/app/Http/Controllers/Api/FlightController.php +++ b/app/Http/Controllers/Api/FlightController.php @@ -89,31 +89,34 @@ class FlightController extends Controller */ public function search(Request $request) { - $user = Auth::user(); - - try { - $where = [ - 'active' => true, - 'visible' => true, - ]; + $where = [ + 'active' => true, + 'visible' => true, + ]; + // Allow the option to bypass some of these restrictions for the searches + if (!$request->filled('ignore_restrictions') || $request->ignore_restrictions === '0') { if (setting('pilots.restrict_to_company')) { $where['airline_id'] = Auth::user()->airline_id; } + if (setting('pilots.only_flights_from_current')) { $where['dpt_airport_id'] = Auth::user()->curr_airport_id; } + } + try { $this->flightRepo->searchCriteria($request); - $this->flightRepo->pushCriteria(new RequestCriteria($request)); $this->flightRepo->pushCriteria(new WhereCriteria($request, $where)); + $this->flightRepo->pushCriteria(new RequestCriteria($request)); + $flights = $this->flightRepo->paginate(); } catch (RepositoryException $e) { return response($e, 503); } foreach ($flights as $flight) { - $this->flightSvc->filterSubfleets($user, $flight); + $this->flightSvc->filterSubfleets(Auth::user(), $flight); } return FlightResource::collection($flights); diff --git a/app/Http/Controllers/Frontend/FlightController.php b/app/Http/Controllers/Frontend/FlightController.php index ae5bb966..30ded3ac 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -13,6 +13,7 @@ use Flash; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Log; +use Prettus\Repository\Criteria\RequestCriteria; use Prettus\Repository\Exceptions\RepositoryException; /** @@ -68,6 +69,7 @@ class FlightController extends Controller try { $this->flightRepo->pushCriteria(new WhereCriteria($request, $where)); + $this->flightRepo->pushCriteria(new RequestCriteria($request)); } catch (RepositoryException $e) { Log::emergency($e); } diff --git a/app/Repositories/Criteria/WhereCriteria.php b/app/Repositories/Criteria/WhereCriteria.php index 97fb2caf..906b4f99 100644 --- a/app/Repositories/Criteria/WhereCriteria.php +++ b/app/Repositories/Criteria/WhereCriteria.php @@ -18,6 +18,12 @@ class WhereCriteria implements CriteriaInterface protected $request; protected $where; + /** + * Create a new Where search. + * + * @param $request + * @param $where + */ public function __construct($request, $where) { $this->request = $request; diff --git a/app/Repositories/FlightRepository.php b/app/Repositories/FlightRepository.php index ee789744..ab3481bb 100644 --- a/app/Repositories/FlightRepository.php +++ b/app/Repositories/FlightRepository.php @@ -103,6 +103,16 @@ class FlightRepository extends Repository implements CacheableInterface $where['arr_airport_id'] = $request->arr_icao; } + // Distance, greater than + if ($request->filled('dgt')) { + $where[] = ['distance', '>=', $request->dgt]; + } + + // Distance, less than + if ($request->filled('dlt')) { + $where[] = ['distance', '<', $request->dlt]; + } + $this->pushCriteria(new WhereCriteria($request, $where)); return $this; diff --git a/swagger.yml b/swagger.yml new file mode 100644 index 00000000..e69de29b diff --git a/tests/FlightTest.php b/tests/FlightTest.php index b438f661..f07bbb17 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -342,6 +342,44 @@ class FlightTest extends TestCase $this->assertEquals($flight->id, $body['data'][0]['id']); } + public function testFlightSearchApiDistance() + { + $total_flights = 10; + $this->user = factory(App\Models\User::class)->create(); + $flights = factory(App\Models\Flight::class, $total_flights)->create([ + 'airline_id' => $this->user->airline_id, + ]); + + // Max distance generated in factory is 1000, so set a random flight + // and try to find it again through the search + + $flight = $flights->random(); + $flight->distance = 1500; + $flight->save(); + + $distance_gt = 1000; + $distance_lt = 1600; + + // look for all of the flights now less than the "factory default" of 1000 + $query = 'dlt=1000&ignore_restrictions=1'; + $req = $this->get('/api/flights/search?'.$query); + $body = $req->json(); + $this->assertCount($total_flights - 1, $body['data']); + + // Try using greater than + $query = 'dgt='.$distance_gt.'&ignore_restrictions=1'; + $req = $this->get('/api/flights/search?'.$query); + $body = $req->json(); + $this->assertCount(1, $body['data']); + $this->assertEquals($flight->id, $body['data'][0]['id']); + + $query = 'dgt='.$distance_gt.'&dlt='.$distance_lt.'&ignore_restrictions=1'; + $req = $this->get('/api/flights/search?'.$query); + $body = $req->json(); + $this->assertCount(1, $body['data']); + $this->assertEquals($flight->id, $body['data'][0]['id']); + } + public function testAddSubfleet() { $subfleet = factory(App\Models\Subfleet::class)->create(); From 2b45b9fd7002194cd019e5c70c184a87ed74e0b1 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 10 May 2019 16:24:34 -0500 Subject: [PATCH 02/12] Fix the searchable fields --- app/Repositories/FlightRepository.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Repositories/FlightRepository.php b/app/Repositories/FlightRepository.php index ab3481bb..9d6b2322 100644 --- a/app/Repositories/FlightRepository.php +++ b/app/Repositories/FlightRepository.php @@ -18,15 +18,16 @@ class FlightRepository extends Repository implements CacheableInterface protected $fieldSearchable = [ 'arr_airport_id', + 'distance', 'dpt_airport_id', 'flight_number' => 'like', - 'flight_code' => 'like', - 'flight_leg' => 'like', + 'route_code' => 'like', + 'route_leg' => 'like', 'route' => 'like', 'notes' => 'like', ]; - public function model() + public function model(): string { return Flight::class; } @@ -70,7 +71,7 @@ class FlightRepository extends Repository implements CacheableInterface * * @return $this */ - public function searchCriteria(Request $request, bool $only_active = true) + public function searchCriteria(Request $request, bool $only_active = true): self { $where = []; From 5f0db96fc41122beca8c755858636c3ba2b4f7b8 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 10 May 2019 18:40:07 -0500 Subject: [PATCH 03/12] Working docker-compose files for development --- .travis/deploy_script.sh | 2 ++ Makefile | 2 +- Procfile | 4 ++-- docker-compose.yml | 39 +++++++++++++++++++++++++++++++++++++++ docker/nginx/default.conf | 27 +++++++++++++++++++++++++++ docker/php/Dockerfile | 3 +++ docker/php/www.conf | 12 ++++++++++++ index.php | 2 +- 8 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 docker-compose.yml create mode 100644 docker/nginx/default.conf create mode 100644 docker/php/Dockerfile create mode 100644 docker/php/www.conf diff --git a/.travis/deploy_script.sh b/.travis/deploy_script.sh index 8da3714f..d9441b09 100755 --- a/.travis/deploy_script.sh +++ b/.travis/deploy_script.sh @@ -55,6 +55,7 @@ if [ "$TRAVIS" = "true" ]; then .sass-cache .idea .travis + docker tests _ide_helper.php .dpl @@ -64,6 +65,7 @@ if [ "$TRAVIS" = "true" ]; then .styleci.yml env.php config.php + docker-compose.yml Makefile phpunit.xml phpvms.iml diff --git a/Makefile b/Makefile index 9f46b63d..f8fdd70e 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ update: build @echo "Done!" .PHONY: reset -reset: cleanapp/Models/Traits/JournalTrait.php +reset: clean @php $(COMPOSER) dump-autoload @make reload-db diff --git a/Procfile b/Procfile index e37f7486..340b8c19 100644 --- a/Procfile +++ b/Procfile @@ -1,5 +1,5 @@ -dnsmasq: /usr/local/sbin/dnsmasq --keep-in-foreground +#dnsmasq: /usr/local/sbin/dnsmasq --keep-in-foreground php-fpm: /usr/local/sbin/php-fpm --nodaemonize nginx: /usr/local/bin/nginx -g 'daemon off;' -#mysql: /usr/local/bin/mysqld +mysql: docker-compose --file ~/docker/mysql/docker-compose.yml up #mailhog: /usr/local/bin/mailhog diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..84f7b788 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +--- +version: '3' + +services: + app: + build: + context: ./docker/php + environment: + DB_HOST: mysql + volumes: + - ./:/var/www + - ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf + depends_on: + - mysql + + nginx: + image: nginx:1.13.8 + command: /bin/bash -c "exec nginx -g 'daemon off;'" + volumes: + - ./:/var/www + - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf + ports: + - 80:80 + depends_on: + - app + + mysql: + image: mysql:5.7.26 + environment: + - MYSQL_DATABASE=phpvms + - MYSQL_ROOT_PASSWORD= + - MYSQL_ALLOW_EMPTY_PASSWORD=yes + volumes: + - mysql-data:/var/lib/mysql + ports: + - 3306 + +volumes: + mysql-data: diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf new file mode 100644 index 00000000..ced8c907 --- /dev/null +++ b/docker/nginx/default.conf @@ -0,0 +1,27 @@ +server { + listen 80 default_server; + server_name phpvms.test; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + root /var/www/public; + index index.php index.html index.htm; + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass app:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include /etc/nginx/fastcgi_params; + } + + location ~ /\.ht { + deny all; + } +} diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile new file mode 100644 index 00000000..791d094a --- /dev/null +++ b/docker/php/Dockerfile @@ -0,0 +1,3 @@ +FROM php:7.3-fpm + +RUN docker-php-ext-install mysqli pdo openssl mbstring tokenizer curl json gmp diff --git a/docker/php/www.conf b/docker/php/www.conf new file mode 100644 index 00000000..57a5e5dd --- /dev/null +++ b/docker/php/www.conf @@ -0,0 +1,12 @@ +[www] + +user = www-data +group = www-data + +listen = :9000 + +pm = dynamic +pm.max_children = 5 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 diff --git a/index.php b/index.php index 3e89c0a5..8886dbb6 100755 --- a/index.php +++ b/index.php @@ -1,7 +1,7 @@ Date: Fri, 10 May 2019 18:54:10 -0500 Subject: [PATCH 04/12] Add swagger docs for search --- swagger.yml | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/swagger.yml b/swagger.yml index e69de29b..9c2d9e65 100644 --- a/swagger.yml +++ b/swagger.yml @@ -0,0 +1,64 @@ +--- +swagger: "2.0" +info: + version: "7.0" + title: phpVMS API + description: All of the responses are contained in the "data" variable +basePath: /api/v1 +schemes: + - https +paths: + "/flights/search": + get: + summary: Retrieve all the applications and flags + operationId: getFlightSearch + parameters: + - name: flight_id + in: query + type: string + required: false + description: ID of the flight + - name: airline_id + in: query + type: string + required: false + description: ID of the airline + - name: flight_number + in: query + type: string + required: false + description: Flight number to use + - name: route_code + in: query + type: string + required: false + description: The route code + - name: dep_icao + in: query + type: string + required: false + description: The departure ICAO + - name: arr_icao + in: query + type: string + required: false + description: The arrival ICAO + - name: dgt + in: query + type: integer + required: false + description: Flights with a distance greater than + - name: dgt + in: query + type: integer + required: false + description: Flights with a distance greater than + produces: + - application/json + responses: + 200: + description: Returns flights from a search + schema: + $ref: '#/definitions/AppsWrapper' + tags: + - flights From a90d9aac39a9f6f91a3186437d0325322bc7b121 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 10 May 2019 18:55:24 -0500 Subject: [PATCH 05/12] Save the data files locally --- docker-compose.yml | 15 +++++++-------- docker/data/.gitignore | 2 ++ 2 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 docker/data/.gitignore diff --git a/docker-compose.yml b/docker-compose.yml index 84f7b788..95962591 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,13 +27,12 @@ services: mysql: image: mysql:5.7.26 environment: - - MYSQL_DATABASE=phpvms - - MYSQL_ROOT_PASSWORD= - - MYSQL_ALLOW_EMPTY_PASSWORD=yes + MYSQL_DATABASE: phpvms + MYSQL_USER: phpvms + MYSQL_PASSWORD: phpvms + MYSQL_ROOT_PASSWORD: + MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' volumes: - - mysql-data:/var/lib/mysql + - ./docker/data/mysql:/var/lib/mysql ports: - - 3306 - -volumes: - mysql-data: + - 3306:3306 diff --git a/docker/data/.gitignore b/docker/data/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/docker/data/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore From 4dd3fc5244acaf247a6f362aa9135af048826a6d Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 10 May 2019 19:31:11 -0500 Subject: [PATCH 06/12] Show if there are database errors --- app/Http/Controllers/Frontend/HomeController.php | 7 +++++++ docker-compose.yml | 10 ++++++++++ docker/php/Dockerfile | 12 +++++++++++- docker/php/www.conf | 3 +++ .../views/system/errors/database_error.blade.php | 2 +- 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Frontend/HomeController.php b/app/Http/Controllers/Frontend/HomeController.php index aba33070..c6c7f64e 100644 --- a/app/Http/Controllers/Frontend/HomeController.php +++ b/app/Http/Controllers/Frontend/HomeController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Frontend; use App\Interfaces\Controller; use App\Models\User; use Illuminate\Database\QueryException; +use Log; /** * Class HomeController @@ -18,6 +19,12 @@ class HomeController extends Controller { try { $users = User::orderBy('created_at', 'desc')->take(4)->get(); + debug($users); + } catch (\PDOException $e) { + Log::emergency($e); + return view('system/errors/database_error', [ + 'error' => $e->getMessage(), + ]); } catch (QueryException $e) { return view('system/errors/not_installed'); } diff --git a/docker-compose.yml b/docker-compose.yml index 95962591..e6c720a1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,3 +36,13 @@ services: - ./docker/data/mysql:/var/lib/mysql ports: - 3306:3306 + + # Use this to tail the logs so it's just all in a single window + logs: + image: busybox + command: tail -f /var/www/storage/logs/laravel.log + restart: always + volumes: + - ./:/var/www + depends_on: + - app diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 791d094a..5c3d4984 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -1,3 +1,13 @@ FROM php:7.3-fpm -RUN docker-php-ext-install mysqli pdo openssl mbstring tokenizer curl json gmp +RUN docker-php-ext-install \ + mysqli \ + pdo \ + openssl \ + mbstring \ + tokenizer \ + curl \ + json \ + gmp + +RUN ln -sf /dev/stderr /var/log/fpm-error.log diff --git a/docker/php/www.conf b/docker/php/www.conf index 57a5e5dd..725d0d2c 100644 --- a/docker/php/www.conf +++ b/docker/php/www.conf @@ -10,3 +10,6 @@ pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 + +php_flag[display_errors] = on +php_admin_flag[log_errors] = on diff --git a/resources/views/system/errors/database_error.blade.php b/resources/views/system/errors/database_error.blade.php index cd36701e..fa8de3e7 100644 --- a/resources/views/system/errors/database_error.blade.php +++ b/resources/views/system/errors/database_error.blade.php @@ -62,7 +62,7 @@

Database Error

- @yield('content') + {{ $error }}
From 099600cf4c08568411ab6d1bfd204e134e5b1324 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 10 May 2019 19:46:50 -0500 Subject: [PATCH 07/12] Fix the PHP Docker image --- .../Controllers/Frontend/HomeController.php | 5 +++++ docker/php/Dockerfile | 17 ++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Frontend/HomeController.php b/app/Http/Controllers/Frontend/HomeController.php index c6c7f64e..93ae315d 100644 --- a/app/Http/Controllers/Frontend/HomeController.php +++ b/app/Http/Controllers/Frontend/HomeController.php @@ -29,6 +29,11 @@ class HomeController extends Controller return view('system/errors/not_installed'); } + // No users + if (!$users) { + return view('system/errors/not_installed'); + } + return view('home', [ 'users' => $users, ]); diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 5c3d4984..02e28188 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -1,13 +1,12 @@ FROM php:7.3-fpm -RUN docker-php-ext-install \ - mysqli \ - pdo \ - openssl \ - mbstring \ - tokenizer \ - curl \ - json \ - gmp +RUN apt-get update +RUN apt-get install -y libgmp-dev RUN ln -sf /dev/stderr /var/log/fpm-error.log + +RUN docker-php-ext-install \ + mysqli \ + pdo \ + pdo_mysql \ + gmp From 2ca4393c5ae3e60bd5ca5a23c2df54eb40557386 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sat, 11 May 2019 09:14:31 -0500 Subject: [PATCH 08/12] Adjust tail command --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index e6c720a1..439cbb4c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,7 +40,7 @@ services: # Use this to tail the logs so it's just all in a single window logs: image: busybox - command: tail -f /var/www/storage/logs/laravel.log + command: tail -f -F -n 0 /var/www/storage/logs/laravel.log restart: always volumes: - ./:/var/www From 65bd6888e82cdbee59abd7c7a885d96a2ec2c395 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sat, 11 May 2019 09:20:05 -0500 Subject: [PATCH 09/12] Only mount storage folder --- README.md | 25 ++++++++++++++++++++----- docker-compose.yml | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fbc9d536..f8a56265 100755 --- a/README.md +++ b/README.md @@ -2,16 +2,15 @@ [![Build Status](https://travis-ci.org/nabeelio/phpvms.svg)](https://travis-ci.org/nabeelio/phpvms) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d668bebb0a3c46bda381af16ce3d9450)](https://www.codacy.com/app/nabeelio/phpvms?utm_source=github.com&utm_medium=referral&utm_content=nabeelio/phpvms&utm_campaign=Badge_Grade) [![Latest Stable Version](https://poser.pugx.org/nabeel/phpvms/v/stable)](https://packagist.org/packages/nabeel/phpvms) ![StyleCI](https://github.styleci.io/repos/93688482/shield?branch=dev) [![License](https://poser.pugx.org/nabeel/phpvms/license)](https://packagist.org/packages/nabeel/phpvms) -The next phpvms version built on the laravel framework. work in progress. If you're looking for -the old, phpVMS classic, it's [available here](https://github.com/nabeelio/phpvms_v2). +The next phpvms version built on the laravel framework. work in progress. The latest documentation, with installation instructions is available + [on the phpVMS documentation](http://docs.phpvms.net/) page. # installation A full distribution, with all of the composer dependencies, is available at this [GitHub Releases](https://github.com/nabeelio/phpvms/releases) link. -The latest documentation, with installation instructions is available -[on the phpVMS documentation](http://docs.phpvms.net/) page. + ## Requirements @@ -30,6 +29,22 @@ The latest documentation, with installation instructions is available ## Installer 1. Upload to your server -2. Visit the site, and follow the link to the installer +1. Visit the site, and follow the link to the installer [View installation details](http://docs.phpvms.net/setup/installation) + +# development environment + +A full development environment can be brought up using Docker: + +```bash +composer install +npm install +docker-compose up +``` + +Then go to `http://localhost`. If you're using dnsmasq, the `app` container is listening on `phpvms.test`, or you can add to your `/etc/hosts` file: + +``` +127.0.0.1 phpvms.test +``` diff --git a/docker-compose.yml b/docker-compose.yml index 439cbb4c..b2ed1ea8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,6 +43,6 @@ services: command: tail -f -F -n 0 /var/www/storage/logs/laravel.log restart: always volumes: - - ./:/var/www + - ./storage:/var/www/storage depends_on: - app From 7fce5421b42f2e61be8b166c261181a96fe54c86 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sat, 11 May 2019 11:37:06 -0500 Subject: [PATCH 10/12] Reset the criterea before a new search --- app/Database/factories/FlightFactory.php | 2 +- app/Http/Controllers/Api/FlightController.php | 6 +++++- app/Http/Controllers/Frontend/FlightController.php | 2 ++ app/Repositories/FlightRepository.php | 2 +- app/helpers.php | 7 +++++-- tests/FlightTest.php | 3 ++- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/Database/factories/FlightFactory.php b/app/Database/factories/FlightFactory.php index 248427cf..412c30df 100644 --- a/app/Database/factories/FlightFactory.php +++ b/app/Database/factories/FlightFactory.php @@ -35,7 +35,7 @@ $factory->define(App\Models\Flight::class, function (Faker $faker) { 'start_date' => null, 'end_date' => null, 'created_at' => $faker->dateTimeBetween('-1 week', 'now'), - 'updated_at' => function (array $flight) { + 'updated_at' => static function (array $flight) { return $flight['created_at']; }, ]; diff --git a/app/Http/Controllers/Api/FlightController.php b/app/Http/Controllers/Api/FlightController.php index 7d474f58..2ddde8c4 100644 --- a/app/Http/Controllers/Api/FlightController.php +++ b/app/Http/Controllers/Api/FlightController.php @@ -9,6 +9,7 @@ use App\Repositories\Criteria\WhereCriteria; use App\Repositories\FlightRepository; use App\Services\FlightService; use Auth; +use DB; use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; use Prettus\Repository\Exceptions\RepositoryException; @@ -95,7 +96,9 @@ class FlightController extends Controller ]; // Allow the option to bypass some of these restrictions for the searches - if (!$request->filled('ignore_restrictions') || $request->ignore_restrictions === '0') { + if (!$request->filled('ignore_restrictions') + || $request->get('ignore_restrictions') === '0' + ) { if (setting('pilots.restrict_to_company')) { $where['airline_id'] = Auth::user()->airline_id; } @@ -106,6 +109,7 @@ class FlightController extends Controller } try { + $this->flightRepo->resetCriteria(); $this->flightRepo->searchCriteria($request); $this->flightRepo->pushCriteria(new WhereCriteria($request, $where)); $this->flightRepo->pushCriteria(new RequestCriteria($request)); diff --git a/app/Http/Controllers/Frontend/FlightController.php b/app/Http/Controllers/Frontend/FlightController.php index 30ded3ac..bb06e139 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -139,6 +139,8 @@ class FlightController extends Controller $where['dpt_airport_id'] = Auth::user()->curr_airport_id; } + $this->flightRepo->resetCriteria(); + try { $this->flightRepo->pushCriteria(new WhereCriteria($request, $where)); } catch (RepositoryException $e) { diff --git a/app/Repositories/FlightRepository.php b/app/Repositories/FlightRepository.php index 9d6b2322..4850f4aa 100644 --- a/app/Repositories/FlightRepository.php +++ b/app/Repositories/FlightRepository.php @@ -111,7 +111,7 @@ class FlightRepository extends Repository implements CacheableInterface // Distance, less than if ($request->filled('dlt')) { - $where[] = ['distance', '<', $request->dlt]; + $where[] = ['distance', '<=', $request->dlt]; } $this->pushCriteria(new WhereCriteria($request, $where)); diff --git a/app/helpers.php b/app/helpers.php index c1e5e11b..78d2788f 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -1,5 +1,8 @@ retrieve($key); - } catch (\App\Exceptions\SettingNotFound $e) { + } catch (SettingNotFound $e) { return $default; } diff --git a/tests/FlightTest.php b/tests/FlightTest.php index f07bbb17..d11a1d84 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -357,7 +357,7 @@ class FlightTest extends TestCase $flight->distance = 1500; $flight->save(); - $distance_gt = 1000; + $distance_gt = 1100; $distance_lt = 1600; // look for all of the flights now less than the "factory default" of 1000 @@ -370,6 +370,7 @@ class FlightTest extends TestCase $query = 'dgt='.$distance_gt.'&ignore_restrictions=1'; $req = $this->get('/api/flights/search?'.$query); $body = $req->json(); + $this->assertCount(1, $body['data']); $this->assertEquals($flight->id, $body['data'][0]['id']); From 1ec866d4dc31962dc4ab2b9a38e005766ca392e9 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sat, 11 May 2019 11:38:56 -0500 Subject: [PATCH 11/12] Style fixes --- app/Http/Controllers/Api/FlightController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Controllers/Api/FlightController.php b/app/Http/Controllers/Api/FlightController.php index 2ddde8c4..b67515b7 100644 --- a/app/Http/Controllers/Api/FlightController.php +++ b/app/Http/Controllers/Api/FlightController.php @@ -9,7 +9,6 @@ use App\Repositories\Criteria\WhereCriteria; use App\Repositories\FlightRepository; use App\Services\FlightService; use Auth; -use DB; use Illuminate\Http\Request; use Prettus\Repository\Criteria\RequestCriteria; use Prettus\Repository\Exceptions\RepositoryException; From df814edafe1941574de56a77971222455ca5a2c3 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sat, 11 May 2019 14:11:15 -0500 Subject: [PATCH 12/12] Add the symfony/polyfill-iconv package --- composer.json | 63 ++++++++++++++++++++++++++------------------------- composer.lock | 2 +- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/composer.json b/composer.json index 055c9a76..e91e65fe 100755 --- a/composer.json +++ b/composer.json @@ -14,40 +14,41 @@ "ext-pdo": "*", "composer/composer": "1.8.x", "composer/semver": "1.4.x", - "laravel/framework": "5.7.x", - "laravelcollective/html": "5.7.x", - "prettus/l5-repository": "2.6.x", - "nwidart/laravel-modules": "3.3.x", - "santigarcor/laratrust": "5.0.x", - "arrilot/laravel-widgets": "3.13.x", - "sebastiaanluca/laravel-helpers": "1.0.x", - "joshbrw/laravel-module-installer": "0.1.x", - "webpatser/laravel-uuid": "3.x", - "igaster/laravel-theme": "2.0.x", - "irazasyed/laravel-gamp": "1.3.x", - "toin0u/geotools-laravel": "1.0.x", - "spatie/laravel-pjax": "1.3.x", - "myclabs/deep-copy": "1.8.x", - "league/geotools": "0.8.x", - "fzaninotto/faker": "^1.8", - "hashids/hashids": "2.0.x", - "jackiedo/timezonelist": "5.x", - "tivie/php-os-detector": "1.1.x", - "pragmarx/version": "0.2.x", - "guzzlehttp/guzzle": "6.3.x", - "jmikola/geojson": "1.0.x", - "laracasts/flash": "3.0.x", - "nabeel/vacentral": "1.x", - "league/iso3166": "2.1.x", - "theiconic/php-ga-measurement-protocol": "2.7.x", - "vierbergenlars/php-semver": "3.0.x", - "php-units-of-measure/php-units-of-measure": "2.1.x", - "markrogoyski/math-php": "^0.38.0", "akaunting/money": "1.0.x", "anhskohbo/no-captcha": "3.0.x", - "league/csv": "9.2.x", + "arrilot/laravel-widgets": "3.13.x", + "fzaninotto/faker": "^1.8", + "guzzlehttp/guzzle": "6.3.x", + "hashids/hashids": "2.0.x", + "igaster/laravel-theme": "2.0.x", "intervention/image": "2.4.x", - "waavi/sanitizer": "1.0.x" + "irazasyed/laravel-gamp": "1.3.x", + "jackiedo/timezonelist": "5.x", + "jmikola/geojson": "1.0.x", + "joshbrw/laravel-module-installer": "0.1.x", + "laracasts/flash": "3.0.x", + "laravel/framework": "5.7.x", + "laravelcollective/html": "5.7.x", + "league/csv": "9.2.x", + "league/geotools": "0.8.x", + "league/iso3166": "2.1.x", + "markrogoyski/math-php": "^0.38.0", + "myclabs/deep-copy": "1.8.x", + "nabeel/vacentral": "1.x", + "nwidart/laravel-modules": "3.3.x", + "php-units-of-measure/php-units-of-measure": "2.1.x", + "pragmarx/version": "0.2.x", + "prettus/l5-repository": "2.6.x", + "santigarcor/laratrust": "5.0.x", + "sebastiaanluca/laravel-helpers": "1.0.x", + "spatie/laravel-pjax": "1.3.x", + "symfony/polyfill-iconv": "^1.11", + "theiconic/php-ga-measurement-protocol": "2.7.x", + "tivie/php-os-detector": "1.1.x", + "toin0u/geotools-laravel": "1.0.x", + "vierbergenlars/php-semver": "3.0.x", + "waavi/sanitizer": "1.0.x", + "webpatser/laravel-uuid": "3.x" }, "require-dev": { "phpunit/phpunit": "7.5.x", diff --git a/composer.lock b/composer.lock index 4a0321ab..c670bb52 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fb105f6d95ca2218f8e3e03c93371cd3", + "content-hash": "290bc8970d44a12e8546926949d73e20", "packages": [ { "name": "akaunting/money",