diff --git a/app/Http/Controllers/Api/FlightController.php b/app/Http/Controllers/Api/FlightController.php index 5b73ad6a..9a2e057f 100644 --- a/app/Http/Controllers/Api/FlightController.php +++ b/app/Http/Controllers/Api/FlightController.php @@ -5,7 +5,6 @@ namespace App\Http\Controllers\Api; use Illuminate\Http\Request; use App\Http\Controllers\AppBaseController; -use App\Models\Transformers\FlightTransformer; use App\Repositories\FlightRepository; use App\Http\Resources\Flight as FlightResource; use Prettus\Repository\Exceptions\RepositoryException; @@ -33,7 +32,7 @@ class FlightController extends AppBaseController } catch (RepositoryException $e) { return response($e, 503); } + return FlightResource::collection($flights); - //return fractal($flights, new FlightTransformer())->respond(); } } diff --git a/app/Http/Controllers/Api/PirepController.php b/app/Http/Controllers/Api/PirepController.php index bff8882f..568ed171 100644 --- a/app/Http/Controllers/Api/PirepController.php +++ b/app/Http/Controllers/Api/PirepController.php @@ -2,16 +2,23 @@ namespace App\Http\Controllers\Api; -use App\Models\Pirep; -use App\Models\Transformers\PirepTransformer; +use App\Http\Resources\Pirep as PirepResource; use App\Http\Controllers\AppBaseController; +use App\Repositories\PirepRepository; class PirepController extends AppBaseController { + protected $pirepRepo; + + public function __construct(PirepRepository $pirepRepo) + { + $this->pirepRepo = $pirepRepo; + } + public function get($id) { - $pirep = Pirep::find($id); - return fractal($pirep, new PirepTransformer())->respond(); + PirepResource::withoutWrapping(); + return new PirepResource($this->pirepRepo->find($id)); } } diff --git a/app/Http/Controllers/Frontend/FlightController.php b/app/Http/Controllers/Frontend/FlightController.php index c7e25f67..278e5992 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -10,7 +10,7 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use App\Http\Controllers\AppBaseController; -use App\Models\UserFlight; +use App\Models\UserBid; use App\Repositories\FlightRepository; use App\Repositories\Criteria\WhereCriteria; @@ -48,7 +48,7 @@ class FlightController extends AppBaseController $flights = $this->flightRepo->paginate(); - $saved_flights = UserFlight::where('user_id', Auth::id()) + $saved_flights = UserBid::where('user_id', Auth::id()) ->pluck('flight_id')->toArray(); return $this->view('flights.index', [ @@ -69,7 +69,7 @@ class FlightController extends AppBaseController { $flights = $this->flightRepo->searchCriteria($request)->paginate(); - $saved_flights = UserFlight::where('user_id', Auth::id()) + $saved_flights = UserBid::where('user_id', Auth::id()) ->pluck('flight_id')->toArray(); return $this->view('flights.index', [ @@ -89,7 +89,7 @@ class FlightController extends AppBaseController $cols = ['user_id' => $user_id, 'flight_id' => $flight_id]; if($action === 'save') { - $uf = UserFlight::create($cols); + $uf = UserBid::create($cols); $uf->save(); return response()->json([ @@ -100,7 +100,7 @@ class FlightController extends AppBaseController elseif ($action === 'remove') { try { - $uf = UserFlight::where($cols)->first(); + $uf = UserBid::where($cols)->first(); $uf->delete(); } catch (Exception $e) { } diff --git a/app/Http/Resources/Pirep.php b/app/Http/Resources/Pirep.php new file mode 100644 index 00000000..67cab45f --- /dev/null +++ b/app/Http/Resources/Pirep.php @@ -0,0 +1,19 @@ + $pirep->id, - 'route_code' => $pirep->route_code, - 'route_leg' => $pirep->route_leg, - 'level' => $pirep->level, - 'route' => $pirep->route, - 'source' => $pirep->source, - 'status' => $pirep->status, - 'raw_data' => $pirep->raw_data, - 'flight_time' => $pirep->flight_time, - 'aircraft' => [], - 'dpt' => PirepTransformer::$aptXform->transform($pirep->dpt_airport), - 'arr' => PirepTransformer::$aptXform->transform($pirep->arr_airport), - 'user' => [ - 'id' => $pirep->user->id, - 'pilot_id' => $pirep->user->pilot_id(), - ], - ]; - - if ($pirep->flight_id) { - $p['flight'] = PirepTransformer::$flightXform->transform($pirep->flight); - } - - return $p; - } -} diff --git a/app/Models/User.php b/app/Models/User.php index 4a4444c0..f3968635 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -140,7 +140,7 @@ class User extends Authenticatable public function flights() { - return $this->hasMany('App\Models\UserFlight', 'user_id'); + return $this->hasMany('App\Models\UserBid', 'user_id'); } public function pireps() diff --git a/app/Models/UserFlight.php b/app/Models/UserBid.php similarity index 63% rename from app/Models/UserFlight.php rename to app/Models/UserBid.php index c9744657..275a824b 100644 --- a/app/Models/UserFlight.php +++ b/app/Models/UserBid.php @@ -7,16 +7,14 @@ use Eloquent as Model; /** * @package App\Models */ -class UserFlight extends Model +class UserBid extends Model { - public $table = 'user_flights'; - public $timestamps = false; + public $table = 'user_bids'; - public $fillable - = [ - 'user_id', - 'flight_id', - ]; + public $fillable = [ + 'user_id', + 'flight_id', + ]; /** * Relationships diff --git a/database/migrations/2017_06_08_0000_create_users_table.php b/database/migrations/2017_06_08_0000_create_users_table.php index 61212fbc..8da41008 100755 --- a/database/migrations/2017_06_08_0000_create_users_table.php +++ b/database/migrations/2017_06_08_0000_create_users_table.php @@ -107,10 +107,10 @@ class CreateUsersTable extends Migration */ public function down() { - Schema::drop('users'); - Schema::drop('permission_role'); - Schema::drop('permissions'); - Schema::drop('role_user'); - Schema::drop('roles'); + Schema::dropIfExists('users'); + Schema::dropIfExists('permission_role'); + Schema::dropIfExists('permissions'); + Schema::dropIfExists('role_user'); + Schema::dropIfExists('roles'); } } diff --git a/database/migrations/2017_06_08_0001_create_password_resets_table.php b/database/migrations/2017_06_08_0001_create_password_resets_table.php index bda733da..1eefa405 100755 --- a/database/migrations/2017_06_08_0001_create_password_resets_table.php +++ b/database/migrations/2017_06_08_0001_create_password_resets_table.php @@ -27,6 +27,6 @@ class CreatePasswordResetsTable extends Migration */ public function down() { - Schema::drop('password_resets'); + Schema::dropIfExists('password_resets'); } } diff --git a/database/migrations/2017_06_08_191703_create_airlines_table.php b/database/migrations/2017_06_08_191703_create_airlines_table.php index f3b92ac8..a5fce623 100644 --- a/database/migrations/2017_06_08_191703_create_airlines_table.php +++ b/database/migrations/2017_06_08_191703_create_airlines_table.php @@ -38,6 +38,6 @@ class CreateAirlinesTable extends Migration */ public function down() { - Schema::drop('airlines'); + Schema::dropIfExists('airlines'); } } diff --git a/database/migrations/2017_06_09_010621_create_aircrafts_table.php b/database/migrations/2017_06_09_010621_create_aircrafts_table.php index 661be527..d4804bee 100644 --- a/database/migrations/2017_06_09_010621_create_aircrafts_table.php +++ b/database/migrations/2017_06_09_010621_create_aircrafts_table.php @@ -25,6 +25,6 @@ class CreateAircraftsTable extends Migration public function down() { - Schema::drop('aircraft'); + Schema::dropIfExists('aircraft'); } } diff --git a/database/migrations/2017_06_10_040335_create_fares_table.php b/database/migrations/2017_06_10_040335_create_fares_table.php index f56b17e9..2a31a0be 100644 --- a/database/migrations/2017_06_10_040335_create_fares_table.php +++ b/database/migrations/2017_06_10_040335_create_fares_table.php @@ -33,6 +33,6 @@ class CreateFaresTable extends Migration */ public function down() { - Schema::drop('fares'); + Schema::dropIfExists('fares'); } } diff --git a/database/migrations/2017_06_11_135707_create_airports_table.php b/database/migrations/2017_06_11_135707_create_airports_table.php index b602b81f..6b8e0cae 100644 --- a/database/migrations/2017_06_11_135707_create_airports_table.php +++ b/database/migrations/2017_06_11_135707_create_airports_table.php @@ -5,16 +5,9 @@ use Illuminate\Database\Schema\Blueprint; class CreateAirportsTable extends Migration { - - /** - * Run the migrations. - * - * @return void - */ public function up() { Schema::create('airports', function (Blueprint $table) { -// $table->bigIncrements('id'); $table->string('id', 5)->primary(); $table->string('iata', 5)->nullable(); $table->string('icao', 5); @@ -30,13 +23,8 @@ class CreateAirportsTable extends Migration }); } - /** - * Reverse the migrations. - * - * @return void - */ public function down() { - Schema::drop('airports'); + Schema::dropIfExists('airports'); } } diff --git a/database/migrations/2017_06_17_214650_create_flights_table.php b/database/migrations/2017_06_17_214650_create_flight_tables.php similarity index 83% rename from database/migrations/2017_06_17_214650_create_flights_table.php rename to database/migrations/2017_06_17_214650_create_flight_tables.php index 80866634..05f68932 100644 --- a/database/migrations/2017_06_17_214650_create_flights_table.php +++ b/database/migrations/2017_06_17_214650_create_flight_tables.php @@ -47,14 +47,6 @@ class CreateFlightsTable extends Migration $table->timestamps(); }); - Schema::create('user_flights', function(Blueprint $table) { - $table->increments('id'); - $table->integer('user_id', false, true); - $table->uuid('flight_id'); - - $table->index('user_id'); - $table->index(['user_id', 'flight_id']); - }); } /** @@ -66,6 +58,5 @@ class CreateFlightsTable extends Migration { Schema::drop('flights'); Schema::drop('flight_fields'); - Schema::drop('user_flights'); } } diff --git a/database/migrations/2017_06_21_165410_create_ranks_table.php b/database/migrations/2017_06_21_165410_create_ranks_table.php index 734362f5..4e89b8fb 100644 --- a/database/migrations/2017_06_21_165410_create_ranks_table.php +++ b/database/migrations/2017_06_21_165410_create_ranks_table.php @@ -33,6 +33,6 @@ class CreateRanksTable extends Migration */ public function down() { - Schema::drop('ranks'); + Schema::dropIfExists('ranks'); } } diff --git a/database/migrations/2017_06_23_011011_create_subfleets_table.php b/database/migrations/2017_06_23_011011_create_subfleet_tables.php similarity index 91% rename from database/migrations/2017_06_23_011011_create_subfleets_table.php rename to database/migrations/2017_06_23_011011_create_subfleet_tables.php index 46342655..d924c47b 100644 --- a/database/migrations/2017_06_23_011011_create_subfleets_table.php +++ b/database/migrations/2017_06_23_011011_create_subfleet_tables.php @@ -71,10 +71,10 @@ class CreateSubfleetsTable extends Migration */ public function down() { - Schema::drop('subfleets'); - Schema::drop('subfleet_expenses'); - Schema::drop('subfleet_fare'); - Schema::drop('subfleet_flight'); - Schema::drop('subfleet_rank'); + Schema::dropIfExists('subfleets'); + Schema::dropIfExists('subfleet_expenses'); + Schema::dropIfExists('subfleet_fare'); + Schema::dropIfExists('subfleet_flight'); + Schema::dropIfExists('subfleet_rank'); } } diff --git a/database/migrations/2017_06_28_195426_create_pireps_table.php b/database/migrations/2017_06_28_195426_create_pirep_tables.php similarity index 92% rename from database/migrations/2017_06_28_195426_create_pireps_table.php rename to database/migrations/2017_06_28_195426_create_pirep_tables.php index 5864d453..a2fff669 100644 --- a/database/migrations/2017_06_28_195426_create_pireps_table.php +++ b/database/migrations/2017_06_28_195426_create_pirep_tables.php @@ -107,11 +107,11 @@ class CreatePirepsTable extends Migration */ public function down() { - Schema::drop('pireps'); - Schema::drop('pirep_comments'); - Schema::drop('pirep_expenses'); - Schema::drop('pirep_fares'); - Schema::drop('pirep_fields'); - Schema::drop('pirep_field_values'); + Schema::dropIfExists('pireps'); + Schema::dropIfExists('pirep_comments'); + Schema::dropIfExists('pirep_expenses'); + Schema::dropIfExists('pirep_fares'); + Schema::dropIfExists('pirep_fields'); + Schema::dropIfExists('pirep_field_values'); } } diff --git a/database/migrations/2017_12_10_014930_create_settings_table.php b/database/migrations/2017_12_10_014930_create_settings_table.php index ea26f4f5..338c6db0 100644 --- a/database/migrations/2017_12_10_014930_create_settings_table.php +++ b/database/migrations/2017_12_10_014930_create_settings_table.php @@ -79,6 +79,6 @@ class CreateSettingsTable extends Migration */ public function down() { - Schema::drop('settings'); + Schema::dropIfExists('settings'); } } diff --git a/database/seeds/dev.yml b/database/seeds/dev.yml index b0e325d0..086f3ce4 100644 --- a/database/seeds/dev.yml +++ b/database/seeds/dev.yml @@ -312,7 +312,7 @@ flight_fields: name: cost index value: 100 -user_flights: +user_bids: - id: 100 user_id: 1 flight_id: flightid_1