Check for departure airport restrictions #221

This commit is contained in:
Nabeel Shahzad
2018-03-30 11:08:53 -05:00
parent 35fb6f0e52
commit bd30b1f900
12 changed files with 189 additions and 29 deletions

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Exceptions;
/**
* Class AircraftNotAtAirport
* @package App\Exceptions
*/
class AircraftNotAtAirport extends InternalError
{
public const FIELD = 'aircraft_id';
public const MESSAGE = 'The aircraft is not at the departure airport';
}

View File

@@ -2,24 +2,12 @@
namespace App\Exceptions;
use Symfony\Component\HttpKernel\Exception\HttpException;
/**
* Class AircraftPermissionDenied
* @package App\Exceptions
*/
class AircraftPermissionDenied extends HttpException
class AircraftPermissionDenied extends InternalError
{
public function __construct(
string $message = null,
\Exception $previous = null,
int $code = 0,
array $headers = []
) {
parent::__construct(
400,
'User is not allowed to fly this aircraft',
$previous, $headers, $code
);
}
public const FIELD = 'aircraft_id';
public const MESSAGE = 'User is not allowed to fly this aircraft';
}

View File

@@ -14,18 +14,21 @@ use Log;
*/
class InternalError extends ValidationException
{
protected const FLASH_FIELD_NAME = 'internal_error_message';
public const FIELD = 'internal_error_message';
public const MESSAGE = '';
/**
* InternalError constructor.
* @param string|null $message
* @param null $field
*/
final public function __construct(string $message = null, $field = null)
public function __construct(string $message = null, $field = null)
{
Log::error($message);
$validator = Validator::make([], []);
$validator->errors()->add($field ?? static::FLASH_FIELD_NAME, $message);
$validator->errors()->add(
$field ?? static::FIELD,
$message ?? static::MESSAGE);
parent::__construct($validator);
}

View File

@@ -0,0 +1,14 @@
<?php
namespace App\Exceptions;
/**
* Class UserNotAtAirport
* @package App\Exceptions
*/
class UserNotAtAirport extends InternalError
{
public const FIELD = 'dpt_airport_id';
public const MESSAGE = 'Pilot is not at the departure airport';
}