From 97764866f2ae51e8d38cbaf1455d6ae446e7e11e Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Tue, 27 Feb 2018 13:25:32 -0600 Subject: [PATCH] Rename user_bids table to bids --- .../2017_12_12_174519_create_bids_table.php | 4 ++-- app/Database/seeds/sample.yml | 2 +- .../Controllers/Admin/FlightController.php | 5 +++-- app/Http/Controllers/Api/UserController.php | 6 +++--- .../Controllers/Frontend/FlightController.php | 6 +++--- app/Models/{UserBid.php => Bid.php} | 4 ++-- app/Models/User.php | 2 +- app/Services/FlightService.php | 16 +++++++------- .../views/admin/flights/fields.blade.php | 21 +++++++++++++------ tests/FlightTest.php | 4 ++-- 10 files changed, 40 insertions(+), 30 deletions(-) rename app/Models/{UserBid.php => Bid.php} (85%) diff --git a/app/Database/migrations/2017_12_12_174519_create_bids_table.php b/app/Database/migrations/2017_12_12_174519_create_bids_table.php index 045cc69a..78c622d5 100644 --- a/app/Database/migrations/2017_12_12_174519_create_bids_table.php +++ b/app/Database/migrations/2017_12_12_174519_create_bids_table.php @@ -13,7 +13,7 @@ class CreateBidsTable extends Migration */ public function up() { - Schema::create('user_bids', function (Blueprint $table) { + Schema::create('bids', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('user_id'); $table->string('flight_id', \App\Models\Flight::ID_MAX_LENGTH); @@ -31,6 +31,6 @@ class CreateBidsTable extends Migration */ public function down() { - Schema::dropIfExists('user_bids'); + Schema::dropIfExists('bids'); } } diff --git a/app/Database/seeds/sample.yml b/app/Database/seeds/sample.yml index c3fbf42a..cac7823b 100644 --- a/app/Database/seeds/sample.yml +++ b/app/Database/seeds/sample.yml @@ -313,7 +313,7 @@ flight_fields: name: cost index value: 100 -user_bids: +bids: - id: 100 user_id: 1 flight_id: flightid_1 diff --git a/app/Http/Controllers/Admin/FlightController.php b/app/Http/Controllers/Admin/FlightController.php index f0cb8662..84daa3a9 100644 --- a/app/Http/Controllers/Admin/FlightController.php +++ b/app/Http/Controllers/Admin/FlightController.php @@ -177,16 +177,17 @@ class FlightController extends BaseController } $time = new Time($flight->flight_time); + $flight->hours = $time->hours; $flight->minutes = $time->minutes; - $avail_subfleets = $this->getAvailSubfleets($flight); return view('admin.flights.edit', [ 'flight' => $flight, 'airlines' => $this->airlineRepo->selectBoxList(), 'airports' => $this->airportRepo->selectBoxList(), + 'alt_airports' => $this->airportRepo->selectBoxList(true), 'avail_fares' => $this->getAvailFares($flight), - 'avail_subfleets' => $avail_subfleets, + 'avail_subfleets' => $this->getAvailSubfleets($flight), 'flight_types' => FlightType::select(true), ]); } diff --git a/app/Http/Controllers/Api/UserController.php b/app/Http/Controllers/Api/UserController.php index 6fcf703a..5577ef62 100644 --- a/app/Http/Controllers/Api/UserController.php +++ b/app/Http/Controllers/Api/UserController.php @@ -8,7 +8,7 @@ use App\Http\Resources\Pirep as PirepResource; use App\Http\Resources\Subfleet as SubfleetResource; use App\Http\Resources\User as UserResource; use App\Models\Enums\PirepState; -use App\Models\UserBid; +use App\Models\Bid; use App\Repositories\Criteria\WhereCriteria; use App\Repositories\FlightRepository; use App\Repositories\PirepRepository; @@ -111,7 +111,7 @@ class UserController extends RestController if ($request->isMethod('DELETE')) { if($request->filled('bid_id')) { - $bid = UserBid::findOrFail($request->input('bid_id')); + $bid = Bid::findOrFail($request->input('bid_id')); $flight_id = $bid->flight_id; } else { $flight_id = $request->input('flight_id'); @@ -122,7 +122,7 @@ class UserController extends RestController } # Return the flights they currently have bids on - $bids = UserBid::where(['user_id' => $user->id])->get(); + $bids = Bid::where(['user_id' => $user->id])->get(); return BidResource::collection($bids); } diff --git a/app/Http/Controllers/Frontend/FlightController.php b/app/Http/Controllers/Frontend/FlightController.php index 2eef8b28..9a16f8f1 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers\Frontend; use App\Http\Controllers\Controller; -use App\Models\UserBid; +use App\Models\Bid; use App\Repositories\AirlineRepository; use App\Repositories\AirportRepository; use App\Repositories\Criteria\WhereCriteria; @@ -65,7 +65,7 @@ class FlightController extends Controller $flights = $this->flightRepo->paginate(); - $saved_flights = UserBid::where('user_id', Auth::id()) + $saved_flights = Bid::where('user_id', Auth::id()) ->pluck('flight_id')->toArray(); return $this->view('flights.index', [ @@ -86,7 +86,7 @@ class FlightController extends Controller { $flights = $this->flightRepo->searchCriteria($request)->paginate(); - $saved_flights = UserBid::where('user_id', Auth::id()) + $saved_flights = Bid::where('user_id', Auth::id()) ->pluck('flight_id')->toArray(); return $this->view('flights.index', [ diff --git a/app/Models/UserBid.php b/app/Models/Bid.php similarity index 85% rename from app/Models/UserBid.php rename to app/Models/Bid.php index aab75add..db4d3774 100644 --- a/app/Models/UserBid.php +++ b/app/Models/Bid.php @@ -5,9 +5,9 @@ namespace App\Models; /** * @package App\Models */ -class UserBid extends BaseModel +class Bid extends BaseModel { - public $table = 'user_bids'; + public $table = 'bids'; public $fillable = [ 'user_id', diff --git a/app/Models/User.php b/app/Models/User.php index 548dff48..3e769d93 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -153,7 +153,7 @@ class User extends Authenticatable public function bids() { - return $this->hasMany(UserBid::class, 'user_id'); + return $this->hasMany(Bid::class, 'user_id'); } public function pireps() diff --git a/app/Services/FlightService.php b/app/Services/FlightService.php index 0763465c..52d54efc 100644 --- a/app/Services/FlightService.php +++ b/app/Services/FlightService.php @@ -6,7 +6,7 @@ use App\Exceptions\BidExists; use App\Models\Flight; use App\Models\Subfleet; use App\Models\User; -use App\Models\UserBid; +use App\Models\Bid; use App\Repositories\FlightRepository; use App\Repositories\NavdataRepository; use Log; @@ -102,7 +102,7 @@ class FlightService extends BaseService public function deleteFlight(Flight $flight) { $where = ['flight_id' => $flight->id]; - UserBid::where($where)->delete(); + Bid::where($where)->delete(); $flight->delete(); } @@ -136,7 +136,7 @@ class FlightService extends BaseService * Allow a user to bid on a flight. Check settings and all that good stuff * @param Flight $flight * @param User $user - * @return UserBid|null + * @return Bid|null * @throws \App\Exceptions\BidExists */ public function addBid(Flight $flight, User $user) @@ -149,7 +149,7 @@ class FlightService extends BaseService # See if we're allowed to have multiple bids or not if (!setting('bids.allow_multiple_bids')) { - $user_bids = UserBid::where(['user_id' => $user->id])->first(); + $user_bids = Bid::where(['user_id' => $user->id])->first(); if ($user_bids) { Log::info('User "' . $user->id . '" already has bids, skipping'); throw new BidExists(); @@ -162,12 +162,12 @@ class FlightService extends BaseService 'flight_id' => $flight->id ]; - $user_bid = UserBid::where($bid_data)->first(); + $user_bid = Bid::where($bid_data)->first(); if ($user_bid) { return $user_bid; } - $user_bid = UserBid::create($bid_data); + $user_bid = Bid::create($bid_data); $flight->has_bid = true; $flight->save(); @@ -182,7 +182,7 @@ class FlightService extends BaseService */ public function removeBid(Flight $flight, User $user) { - $user_bid = UserBid::where([ + $user_bid = Bid::where([ 'flight_id' => $flight->id, 'user_id' => $user->id ])->first(); @@ -191,7 +191,7 @@ class FlightService extends BaseService } # Only flip the flag if there are no bids left for this flight - if (!UserBid::where('flight_id', $flight->id)->exists()) { + if (!Bid::where('flight_id', $flight->id)->exists()) { $flight->has_bid = false; $flight->save(); } diff --git a/resources/views/admin/flights/fields.blade.php b/resources/views/admin/flights/fields.blade.php index ab467f0a..eacba2f4 100644 --- a/resources/views/admin/flights/fields.blade.php +++ b/resources/views/admin/flights/fields.blade.php @@ -31,7 +31,7 @@
- {!! Form::label('level', 'Flight Type:') !!} + {!! Form::label('level', 'Flight Type:') !!} * {!! Form::select('flight_type', $flight_types, null, ['class' => 'form-control select2']) !!}

{{ $errors->first('flight_type') }}

@@ -52,7 +52,7 @@
{!! Form::label('alt_airport_id', 'Alt Airport:') !!} - {!! Form::select('alt_airport_id', $airports, null , ['class' => 'form-control select2']) !!} + {!! Form::select('alt_airport_id', $alt_airports, null , ['class' => 'form-control select2']) !!}

{{ $errors->first('alt_airport_id') }}

@@ -75,13 +75,22 @@
{!! Form::label('flight_time', 'Flight Time (hours & minutes):') !!}
- {!! Form::number('hours', null, ['class' => 'form-control', 'placeholder' => 'hours']) !!} + {!! Form::number('hours', null, [ + 'class' => 'form-control', + 'placeholder' => 'hours' + ]) !!}
- {!! Form::number('minutes', null, ['class' => 'form-control', 'placeholder' => 'minutes']) !!} -

{{ $errors->first('hours') }}

-

{{ $errors->first('minutes') }}

+ {!! Form::number('minutes', null, [ + 'class' => 'form-control', + 'placeholder' => 'minutes' + ]) !!}
+ {!! $flight->flight_time !!} + {!! $flight->hours !!} + {!! $flight->minutes !!} +

{{ $errors->first('hours') }}

+

{{ $errors->first('minutes') }}

diff --git a/tests/FlightTest.php b/tests/FlightTest.php index 90b82a33..d1cee7db 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -2,7 +2,7 @@ use App\Models\Flight; use App\Models\User; -use App\Models\UserBid; +use App\Models\Bid; use App\Repositories\SettingRepository; use App\Services\FlightService; @@ -272,7 +272,7 @@ class FlightTest extends TestCase $this->assertNull($empty_flight); # Make sure no bids exist - $user_bids = UserBid::where('flight_id', $flight->id)->get(); + $user_bids = Bid::where('flight_id', $flight->id)->get(); #$this->assertEquals(0, $user_bid->count());