@@ -13,6 +13,19 @@ use Illuminate\Support\Facades\Log;
|
|||||||
|
|
||||||
class BidService extends Service
|
class BidService extends Service
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Get a specific bid for a user
|
||||||
|
*
|
||||||
|
* @param $bid_id
|
||||||
|
*
|
||||||
|
* @return \App\Models\Bid|\Illuminate\Database\Eloquent\Model|object|null
|
||||||
|
*/
|
||||||
|
public function getBid($bid_id)
|
||||||
|
{
|
||||||
|
return Bid::with(['flight', 'flight.simbrief'])
|
||||||
|
->where(['id' => $bid_id])->first();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find all of the bids for a given user
|
* Find all of the bids for a given user
|
||||||
*
|
*
|
||||||
@@ -22,8 +35,8 @@ class BidService extends Service
|
|||||||
*/
|
*/
|
||||||
public function findBidsForUser(User $user)
|
public function findBidsForUser(User $user)
|
||||||
{
|
{
|
||||||
$bids = Bid::where(['user_id' => $user->id])->get();
|
return Bid::with(['flight', 'flight.simbrief'])
|
||||||
return $bids;
|
->where(['user_id' => $user->id])->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,7 +99,7 @@ class BidService extends Service
|
|||||||
$flight->has_bid = true;
|
$flight->has_bid = true;
|
||||||
$flight->save();
|
$flight->save();
|
||||||
|
|
||||||
return $bid;
|
return $this->getBid($bid->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Exceptions\BidExistsForFlight;
|
||||||
use App\Models\Bid;
|
use App\Models\Bid;
|
||||||
use App\Models\Flight;
|
use App\Models\Flight;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -136,7 +137,7 @@ class BidTest extends TestCase
|
|||||||
$this->bidSvc->addBid($flight, $user1);
|
$this->bidSvc->addBid($flight, $user1);
|
||||||
|
|
||||||
// Try adding again, should throw an exception
|
// Try adding again, should throw an exception
|
||||||
$this->expectException(\App\Exceptions\BidExistsForFlight::class);
|
$this->expectException(BidExistsForFlight::class);
|
||||||
$this->bidSvc->addBid($flight, $user2);
|
$this->bidSvc->addBid($flight, $user2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ use Carbon\Carbon;
|
|||||||
|
|
||||||
class SimBriefTest extends TestCase
|
class SimBriefTest extends TestCase
|
||||||
{
|
{
|
||||||
|
private static $simbrief_flight_id = 'simbriefflightid';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load SimBrief
|
* Load SimBrief
|
||||||
*
|
*
|
||||||
@@ -19,6 +21,7 @@ class SimBriefTest extends TestCase
|
|||||||
protected function loadSimBrief($user): SimBrief
|
protected function loadSimBrief($user): SimBrief
|
||||||
{
|
{
|
||||||
$flight = factory(App\Models\Flight::class)->create([
|
$flight = factory(App\Models\Flight::class)->create([
|
||||||
|
'id' => self::$simbrief_flight_id,
|
||||||
'dpt_airport_id' => 'OMAA',
|
'dpt_airport_id' => 'OMAA',
|
||||||
'arr_airport_id' => 'OMDB',
|
'arr_airport_id' => 'OMDB',
|
||||||
]);
|
]);
|
||||||
@@ -107,6 +110,25 @@ class SimBriefTest extends TestCase
|
|||||||
$this->assertEquals('FlightPlan', $xml->attributes()->Type);
|
$this->assertEquals('FlightPlan', $xml->attributes()->Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure the user's bids have the Simbrief data show up
|
||||||
|
*/
|
||||||
|
public function testUserBidSimbrief()
|
||||||
|
{
|
||||||
|
$this->user = factory(App\Models\User::class)->create();
|
||||||
|
$this->loadSimBrief($this->user);
|
||||||
|
|
||||||
|
// Find the flight
|
||||||
|
$uri = '/api/user/bids';
|
||||||
|
$data = ['flight_id' => self::$simbrief_flight_id];
|
||||||
|
|
||||||
|
$body = $this->put($uri, $data);
|
||||||
|
$body = $body->json('data');
|
||||||
|
|
||||||
|
// Make sure Simbrief is there
|
||||||
|
$this->assertNotNull($body['flight']['simbrief']['id']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testAttachToPirep()
|
public function testAttachToPirep()
|
||||||
{
|
{
|
||||||
$user = factory(App\Models\User::class)->create();
|
$user = factory(App\Models\User::class)->create();
|
||||||
|
|||||||
Reference in New Issue
Block a user