diff --git a/app/Http/Controllers/API/v2/CartController.php b/app/Http/Controllers/API/v2/CartController.php index e0f2790..5f2817c 100644 --- a/app/Http/Controllers/API/v2/CartController.php +++ b/app/Http/Controllers/API/v2/CartController.php @@ -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([ diff --git a/app/Models/Validation/ItemValidationByName.php b/app/Models/Validation/ItemValidationByName.php deleted file mode 100644 index 637b2c6..0000000 --- a/app/Models/Validation/ItemValidationByName.php +++ /dev/null @@ -1,18 +0,0 @@ -create(), - ); - } -} diff --git a/app/Models/Validation/Messages/InformativeValidator.php b/app/Models/Validation/Messages/InformativeValidator.php index 3a7290c..d65ea98 100644 --- a/app/Models/Validation/Messages/InformativeValidator.php +++ b/app/Models/Validation/Messages/InformativeValidator.php @@ -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(); } } diff --git a/app/Models/Validation/Messages/ItemMessagesFactory.php b/app/Models/Validation/Messages/ItemMessagesFactory.php deleted file mode 100644 index 4316065..0000000 --- a/app/Models/Validation/Messages/ItemMessagesFactory.php +++ /dev/null @@ -1,20 +0,0 @@ - '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); - } -} - diff --git a/app/Models/Validation/Messages/OkInformativeValidator.php b/app/Models/Validation/Messages/OkInformativeValidator.php index f06027d..d820631 100644 --- a/app/Models/Validation/Messages/OkInformativeValidator.php +++ b/app/Models/Validation/Messages/OkInformativeValidator.php @@ -17,7 +17,7 @@ class OkInformativeValidator extends InformativeValidator { return $this->message; } - public function okStatus(): array + public function getOkStatus(): array { return ['ok' => $this->getMessage()]; } diff --git a/tests/Feature/Validation/Factories/ItemValidatorByNameFactoryTest.php b/tests/Feature/Validation/Factories/ItemInformativeValidatorByNameFactoryTest.php similarity index 90% rename from tests/Feature/Validation/Factories/ItemValidatorByNameFactoryTest.php rename to tests/Feature/Validation/Factories/ItemInformativeValidatorByNameFactoryTest.php index dec6aad..779b48e 100644 --- a/tests/Feature/Validation/Factories/ItemValidatorByNameFactoryTest.php +++ b/tests/Feature/Validation/Factories/ItemInformativeValidatorByNameFactoryTest.php @@ -6,7 +6,7 @@ use Tests\TestCase; use App\Models\Validation\Messages\Factories\ItemInformativeValidatorByNameFactory; -class ItemValidatorByNameFactoryTest extends TestCase +class ItemInformativeValidatorByNameFactoryTest extends TestCase { public function dataProvider() { return [ @@ -40,7 +40,7 @@ class ItemValidatorByNameFactoryTest extends TestCase $validator = $factory->create(); $this->assertEquals($validator->getMessage(), $message); - $this->assertEquals($validator->okStatus(), [$key => $message]); + $this->assertEquals($validator->getOkStatus(), [$key => $message]); $this->assertEquals($validator->isValid(), $isValid); } }