Rename user_bids table to bids
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ flight_fields:
|
||||
name: cost index
|
||||
value: 100
|
||||
|
||||
user_bids:
|
||||
bids:
|
||||
- id: 100
|
||||
user_id: 1
|
||||
flight_id: flightid_1
|
||||
|
||||
@@ -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),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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', [
|
||||
|
||||
@@ -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',
|
||||
@@ -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()
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<div class="row">
|
||||
|
||||
<div class="form-group col-sm-3">
|
||||
{!! Form::label('level', 'Flight Type:') !!}
|
||||
{!! Form::label('level', 'Flight Type:') !!} <span class="required">*</span>
|
||||
{!! Form::select('flight_type', $flight_types, null, ['class' => 'form-control select2']) !!}
|
||||
<p class="text-danger">{{ $errors->first('flight_type') }}</p>
|
||||
</div>
|
||||
@@ -52,7 +52,7 @@
|
||||
<!-- Alt Airport Id Field -->
|
||||
<div class="form-group col-sm-3">
|
||||
{!! 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']) !!}
|
||||
<p class="text-danger">{{ $errors->first('alt_airport_id') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -75,13 +75,22 @@
|
||||
<div class="form-group col-sm-4">
|
||||
{!! Form::label('flight_time', 'Flight Time (hours & minutes):') !!}
|
||||
<div style="float: left">
|
||||
{!! Form::number('hours', null, ['class' => 'form-control', 'placeholder' => 'hours']) !!}
|
||||
{!! Form::number('hours', null, [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'hours'
|
||||
]) !!}
|
||||
</div>
|
||||
<div style="float: left">
|
||||
{!! Form::number('minutes', null, ['class' => 'form-control', 'placeholder' => 'minutes']) !!}
|
||||
<p class="text-danger">{{ $errors->first('hours') }}</p>
|
||||
<p class="text-danger">{{ $errors->first('minutes') }}</p>
|
||||
{!! Form::number('minutes', null, [
|
||||
'class' => 'form-control',
|
||||
'placeholder' => 'minutes'
|
||||
]) !!}
|
||||
</div>
|
||||
{!! $flight->flight_time !!}
|
||||
{!! $flight->hours !!}
|
||||
{!! $flight->minutes !!}
|
||||
<p class="text-danger">{{ $errors->first('hours') }}</p>
|
||||
<p class="text-danger">{{ $errors->first('minutes') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-sm-2">
|
||||
|
||||
@@ -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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user