Return the flight object with the bid
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Resources\Bid as BidResource;
|
||||||
use App\Http\Resources\Flight as FlightResource;
|
use App\Http\Resources\Flight as FlightResource;
|
||||||
use App\Http\Resources\Pirep as PirepResource;
|
use App\Http\Resources\Pirep as PirepResource;
|
||||||
use App\Http\Resources\Subfleet as SubfleetResource;
|
use App\Http\Resources\Subfleet as SubfleetResource;
|
||||||
@@ -103,20 +104,19 @@ class UserController extends RestController
|
|||||||
if ($request->isMethod('PUT')) {
|
if ($request->isMethod('PUT')) {
|
||||||
$flight_id = $request->input('flight_id');
|
$flight_id = $request->input('flight_id');
|
||||||
$flight = $this->flightRepo->find($flight_id);
|
$flight = $this->flightRepo->find($flight_id);
|
||||||
$this->flightSvc->addBid($flight, $user);
|
$bid = $this->flightSvc->addBid($flight, $user);
|
||||||
|
return new BidResource($bid);
|
||||||
}
|
}
|
||||||
|
|
||||||
elseif ($request->isMethod('DELETE')) {
|
if ($request->isMethod('DELETE')) {
|
||||||
$flight_id = $request->input('flight_id');
|
$flight_id = $request->input('flight_id');
|
||||||
$flight = $this->flightRepo->find($flight_id);
|
$flight = $this->flightRepo->find($flight_id);
|
||||||
$this->flightSvc->removeBid($flight, $user);
|
$this->flightSvc->removeBid($flight, $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return the flights they currently have bids on
|
# Return the flights they currently have bids on
|
||||||
$flights = UserBid::where(['user_id' => $user->id])
|
$bids = UserBid::where(['user_id' => $user->id])->get();
|
||||||
->get()->pluck('flight');
|
return BidResource::collection($bids);
|
||||||
|
|
||||||
return FlightResource::collection($flights);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
16
app/Http/Resources/Bid.php
Normal file
16
app/Http/Resources/Bid.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\Resource;
|
||||||
|
|
||||||
|
class Bid extends Resource
|
||||||
|
{
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
$bid = parent::toArray($request);
|
||||||
|
$bid['flight'] = new Flight($this->flight);
|
||||||
|
|
||||||
|
return $bid;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -235,10 +235,10 @@ class FlightTest extends TestCase
|
|||||||
$uri = '/api/user/bids';
|
$uri = '/api/user/bids';
|
||||||
$data = ['flight_id' => $flight->id];
|
$data = ['flight_id' => $flight->id];
|
||||||
|
|
||||||
$body = $this->put($uri, $data)->json('data');
|
$body = $this->put($uri, $data);
|
||||||
|
$body = $body->json('data');
|
||||||
|
|
||||||
$this->assertCount(1, $body);
|
$this->assertEquals($body['flight_id'], $flight->id);
|
||||||
$this->assertEquals($body[0]['id'], $flight->id);
|
|
||||||
|
|
||||||
# Now try to have the second user bid on it
|
# Now try to have the second user bid on it
|
||||||
# Should return a 409 error
|
# Should return a 409 error
|
||||||
|
|||||||
Reference in New Issue
Block a user