Refactor to use ItemInformativeValidatorByNameFactory.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -24,7 +24,7 @@ use App\Http\Resources\API\v2\CartItemCollection;
|
||||
use App\Models\Validation\UserValidationByMatrixUsername;
|
||||
use App\Models\Validation\CityValidationByName;
|
||||
use App\Models\Validation\CompanyValidationByName;
|
||||
use App\Models\Validation\ItemValidationByName;
|
||||
use App\Models\Validation\Messages\Factories\ItemInformativeValidatorByNameFactory;
|
||||
|
||||
class CartController extends Controller
|
||||
{
|
||||
@@ -207,9 +207,9 @@ class CartController extends Controller
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getMessageMap());
|
||||
|
||||
$validator = new ItemValidationByName($itemName);
|
||||
$validator = (new ItemInformativeValidatorByNameFactory($itemName))->create();
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getMessageMap());
|
||||
return response()->json($validator->getOkStatus());
|
||||
|
||||
if($itemCount == 0)
|
||||
return response()->json([
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation;
|
||||
|
||||
use App\Models\Validation\ModelValidationByName;
|
||||
use App\Models\Validation\Messages\ItemMessagesFactory;
|
||||
|
||||
class ItemValidationByName extends ModelValidationByName
|
||||
{
|
||||
public function __construct(string $name)
|
||||
{
|
||||
parent::__construct(
|
||||
$name,
|
||||
'App\Models\Item',
|
||||
(new ItemMessagesFactory())->create(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -36,12 +36,12 @@ abstract class InformativeValidator extends Validator {
|
||||
return $this->nextValidator->getMessage();
|
||||
}
|
||||
|
||||
public function okStatus(): array
|
||||
public function getOkStatus(): array
|
||||
{
|
||||
if(!$this->isCurrentValid())
|
||||
return ['error' => $this->message];
|
||||
|
||||
return $this->nextValidator->okStatus();
|
||||
return $this->nextValidator->getOkStatus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages;
|
||||
|
||||
use App\Models\Validation\Messages\BaseMessages;
|
||||
|
||||
class ItemMessagesFactory
|
||||
{
|
||||
protected array $messages = [
|
||||
'found' => 'A item with the name is valid.',
|
||||
'not_found' => 'A item with the name does not exist!!!',
|
||||
'invalid_name' => 'The item name is empty, please, write the name!!!',
|
||||
];
|
||||
|
||||
public function create()
|
||||
{
|
||||
return new BaseMessages($this->messages);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ class OkInformativeValidator extends InformativeValidator {
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
public function okStatus(): array
|
||||
public function getOkStatus(): array
|
||||
{
|
||||
return ['ok' => $this->getMessage()];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user