mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim.git
synced 2026-08-19 04:24:00 +00:00
46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Orders\Processors;
|
|
|
|
use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
|
|
use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
|
|
use App\Classes\Modules\Orders\DataTransferObjects\StepObject;
|
|
use App\Classes\Modules\Orders\Services\Steps\CompletesOrderStep;
|
|
use App\Classes\ValueObjects\Constants\HttpStatus;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
abstract class AbstractStepProcessor
|
|
{
|
|
|
|
abstract function validator(): bool;
|
|
|
|
abstract function execute(): JsonResponse;
|
|
|
|
/**
|
|
* @param OrderObject $order
|
|
* @param StepObject $step
|
|
* @return JsonResponse
|
|
* @throws InternalServerErrorException
|
|
*/
|
|
public function handler(OrderObject $order, StepObject $step) {
|
|
try {
|
|
|
|
if(!$this->validator()){
|
|
return new JsonResponse(['message' => 'Updating step validation has failed due to missing requirements'], HttpStatus::VALIDATION_FAILED);
|
|
}
|
|
|
|
(new CompletesOrderStep())->execute($order, $step);
|
|
|
|
/** notification */
|
|
|
|
|
|
return new JsonResponse(null, HttpStatus::REQUEST_ACCEPTED);
|
|
|
|
} catch (\Exception $exception){
|
|
|
|
throw new InternalServerErrorException("Failed to update order step because {$exception->getMessage()}");
|
|
|
|
}
|
|
}
|
|
|
|
} |