Check for bid existing or not
This commit is contained in:
parent
88ffee16be
commit
670cb5d811
43
app/Exceptions/BidNotFound.php
Normal file
43
app/Exceptions/BidNotFound.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
class BidNotFound extends AbstractHttpException
|
||||||
|
{
|
||||||
|
private $bid_id;
|
||||||
|
|
||||||
|
public function __construct($bid_id)
|
||||||
|
{
|
||||||
|
$this->bid_id = $bid_id;
|
||||||
|
parent::__construct(
|
||||||
|
404,
|
||||||
|
'The bid '.$bid_id.' was not found'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the RFC 7807 error type (without the URL root)
|
||||||
|
*/
|
||||||
|
public function getErrorType(): string
|
||||||
|
{
|
||||||
|
return 'bid-not-found';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the detailed error string
|
||||||
|
*/
|
||||||
|
public function getErrorDetails(): string
|
||||||
|
{
|
||||||
|
return $this->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an array with the error details, merged with the RFC7807 response
|
||||||
|
*/
|
||||||
|
public function getErrorMetadata(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'bid_id' => $this->bid_id
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use App\Contracts\Controller;
|
use App\Contracts\Controller;
|
||||||
|
use App\Exceptions\BidNotFound;
|
||||||
use App\Exceptions\Unauthorized;
|
use App\Exceptions\Unauthorized;
|
||||||
use App\Exceptions\UserNotFound;
|
use App\Exceptions\UserNotFound;
|
||||||
use App\Http\Resources\Bid as BidResource;
|
use App\Http\Resources\Bid as BidResource;
|
||||||
@ -160,6 +161,10 @@ class UserController extends Controller
|
|||||||
|
|
||||||
// Return the current bid
|
// Return the current bid
|
||||||
$bid = $this->bidSvc->getBid($user, $bid_id);
|
$bid = $this->bidSvc->getBid($user, $bid_id);
|
||||||
|
if ($bid === null) {
|
||||||
|
throw new BidNotFound($bid_id);
|
||||||
|
}
|
||||||
|
|
||||||
if ($bid->user_id !== $user->id) {
|
if ($bid->user_id !== $user->id) {
|
||||||
throw new Unauthorized(new \Exception('Bid not not belong to authenticated user'));
|
throw new Unauthorized(new \Exception('Bid not not belong to authenticated user'));
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,9 @@ class BidService extends Service
|
|||||||
|
|
||||||
/** @var Bid $bid */
|
/** @var Bid $bid */
|
||||||
$bid = Bid::with($with)->where(['id' => $bid_id])->first();
|
$bid = Bid::with($with)->where(['id' => $bid_id])->first();
|
||||||
|
if ($bid === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Reconcile the aircraft for this bid
|
// Reconcile the aircraft for this bid
|
||||||
// TODO: Only do this if there isn't a Simbrief attached?
|
// TODO: Only do this if there isn't a Simbrief attached?
|
||||||
|
Loading…
Reference in New Issue
Block a user