migrate to gtea from bistbucket
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\RestaurantDelivery\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class AssignmentException extends Exception
|
||||
{
|
||||
protected string $errorCode;
|
||||
|
||||
public function __construct(
|
||||
string $message,
|
||||
string $errorCode = 'ASSIGNMENT_ERROR',
|
||||
int $code = 400,
|
||||
?\Throwable $previous = null
|
||||
) {
|
||||
$this->errorCode = $errorCode;
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error code.
|
||||
*/
|
||||
public function getErrorCode(): string
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the exception as JSON response.
|
||||
*/
|
||||
public function render(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $this->getMessage(),
|
||||
'error_code' => $this->errorCode,
|
||||
], $this->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for no riders available.
|
||||
*/
|
||||
public static function noRidersAvailable(): self
|
||||
{
|
||||
return new self(
|
||||
'No riders are available in the area',
|
||||
'NO_RIDERS_AVAILABLE',
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for assignment timeout.
|
||||
*/
|
||||
public static function timeout(): self
|
||||
{
|
||||
return new self(
|
||||
'Assignment request timed out',
|
||||
'ASSIGNMENT_TIMEOUT',
|
||||
408
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for max reassignments reached.
|
||||
*/
|
||||
public static function maxReassignmentsReached(): self
|
||||
{
|
||||
return new self(
|
||||
'Maximum reassignment attempts reached',
|
||||
'MAX_REASSIGNMENTS_REACHED',
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for rider already assigned.
|
||||
*/
|
||||
public static function alreadyAssigned(): self
|
||||
{
|
||||
return new self(
|
||||
'A rider has already been assigned to this delivery',
|
||||
'RIDER_ALREADY_ASSIGNED',
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for assignment rejected.
|
||||
*/
|
||||
public static function rejected(string $reason = ''): self
|
||||
{
|
||||
$message = 'Assignment was rejected';
|
||||
if ($reason) {
|
||||
$message .= ": {$reason}";
|
||||
}
|
||||
|
||||
return new self($message, 'ASSIGNMENT_REJECTED', 400);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\RestaurantDelivery\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class DeliveryException extends Exception
|
||||
{
|
||||
protected string $errorCode;
|
||||
|
||||
public function __construct(
|
||||
string $message,
|
||||
string $errorCode = 'DELIVERY_ERROR',
|
||||
int $code = 400,
|
||||
?\Throwable $previous = null
|
||||
) {
|
||||
$this->errorCode = $errorCode;
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error code.
|
||||
*/
|
||||
public function getErrorCode(): string
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the exception as JSON response.
|
||||
*/
|
||||
public function render(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $this->getMessage(),
|
||||
'error_code' => $this->errorCode,
|
||||
], $this->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for invalid status transition.
|
||||
*/
|
||||
public static function invalidStatusTransition(string $from, string $to): self
|
||||
{
|
||||
return new self(
|
||||
"Cannot transition from '{$from}' to '{$to}'",
|
||||
'INVALID_STATUS_TRANSITION',
|
||||
422
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for delivery not found.
|
||||
*/
|
||||
public static function notFound(string $identifier): self
|
||||
{
|
||||
return new self(
|
||||
"Delivery '{$identifier}' not found",
|
||||
'DELIVERY_NOT_FOUND',
|
||||
404
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for delivery not trackable.
|
||||
*/
|
||||
public static function notTrackable(): self
|
||||
{
|
||||
return new self(
|
||||
'Tracking is not available for this delivery',
|
||||
'DELIVERY_NOT_TRACKABLE',
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for delivery already completed.
|
||||
*/
|
||||
public static function alreadyCompleted(): self
|
||||
{
|
||||
return new self(
|
||||
'This delivery has already been completed',
|
||||
'DELIVERY_ALREADY_COMPLETED',
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for delivery already cancelled.
|
||||
*/
|
||||
public static function alreadyCancelled(): self
|
||||
{
|
||||
return new self(
|
||||
'This delivery has already been cancelled',
|
||||
'DELIVERY_ALREADY_CANCELLED',
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for no rider assigned.
|
||||
*/
|
||||
public static function noRiderAssigned(): self
|
||||
{
|
||||
return new self(
|
||||
'No rider has been assigned to this delivery',
|
||||
'NO_RIDER_ASSIGNED',
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\RestaurantDelivery\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class PaymentException extends Exception
|
||||
{
|
||||
protected string $errorCode;
|
||||
|
||||
public function __construct(
|
||||
string $message,
|
||||
string $errorCode = 'PAYMENT_ERROR',
|
||||
int $code = 400,
|
||||
?\Throwable $previous = null
|
||||
) {
|
||||
$this->errorCode = $errorCode;
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error code.
|
||||
*/
|
||||
public function getErrorCode(): string
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the exception as JSON response.
|
||||
*/
|
||||
public function render(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $this->getMessage(),
|
||||
'error_code' => $this->errorCode,
|
||||
], $this->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for payment failed.
|
||||
*/
|
||||
public static function failed(string $reason = ''): self
|
||||
{
|
||||
$message = 'Payment processing failed';
|
||||
if ($reason) {
|
||||
$message .= ": {$reason}";
|
||||
}
|
||||
|
||||
return new self($message, 'PAYMENT_FAILED', 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for invalid amount.
|
||||
*/
|
||||
public static function invalidAmount(): self
|
||||
{
|
||||
return new self(
|
||||
'Invalid payment amount',
|
||||
'INVALID_PAYMENT_AMOUNT',
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for tip already paid.
|
||||
*/
|
||||
public static function tipAlreadyPaid(): self
|
||||
{
|
||||
return new self(
|
||||
'This tip has already been paid',
|
||||
'TIP_ALREADY_PAID',
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for payout failed.
|
||||
*/
|
||||
public static function payoutFailed(string $reason = ''): self
|
||||
{
|
||||
$message = 'Payout processing failed';
|
||||
if ($reason) {
|
||||
$message .= ": {$reason}";
|
||||
}
|
||||
|
||||
return new self($message, 'PAYOUT_FAILED', 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for insufficient balance.
|
||||
*/
|
||||
public static function insufficientBalance(): self
|
||||
{
|
||||
return new self(
|
||||
'Insufficient balance for payout',
|
||||
'INSUFFICIENT_BALANCE',
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\RestaurantDelivery\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class RiderException extends Exception
|
||||
{
|
||||
protected string $errorCode;
|
||||
|
||||
public function __construct(
|
||||
string $message,
|
||||
string $errorCode = 'RIDER_ERROR',
|
||||
int $code = 400,
|
||||
?\Throwable $previous = null
|
||||
) {
|
||||
$this->errorCode = $errorCode;
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error code.
|
||||
*/
|
||||
public function getErrorCode(): string
|
||||
{
|
||||
return $this->errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the exception as JSON response.
|
||||
*/
|
||||
public function render(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $this->getMessage(),
|
||||
'error_code' => $this->errorCode,
|
||||
], $this->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for rider not found.
|
||||
*/
|
||||
public static function notFound(int|string $identifier): self
|
||||
{
|
||||
return new self(
|
||||
"Rider '{$identifier}' not found",
|
||||
'RIDER_NOT_FOUND',
|
||||
404
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for rider not verified.
|
||||
*/
|
||||
public static function notVerified(): self
|
||||
{
|
||||
return new self(
|
||||
'Rider account is not verified',
|
||||
'RIDER_NOT_VERIFIED',
|
||||
403
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for rider suspended.
|
||||
*/
|
||||
public static function suspended(): self
|
||||
{
|
||||
return new self(
|
||||
'Rider account is suspended',
|
||||
'RIDER_SUSPENDED',
|
||||
403
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for rider not available.
|
||||
*/
|
||||
public static function notAvailable(): self
|
||||
{
|
||||
return new self(
|
||||
'Rider is not available to accept orders',
|
||||
'RIDER_NOT_AVAILABLE',
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for rider at max capacity.
|
||||
*/
|
||||
public static function atMaxCapacity(): self
|
||||
{
|
||||
return new self(
|
||||
'Rider has reached maximum concurrent orders limit',
|
||||
'RIDER_AT_MAX_CAPACITY',
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for invalid location.
|
||||
*/
|
||||
public static function invalidLocation(): self
|
||||
{
|
||||
return new self(
|
||||
'Invalid rider location data',
|
||||
'INVALID_RIDER_LOCATION',
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create exception for rider offline.
|
||||
*/
|
||||
public static function offline(): self
|
||||
{
|
||||
return new self(
|
||||
'Rider is currently offline',
|
||||
'RIDER_OFFLINE',
|
||||
400
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user