Refactor to use CompanyInformativeValidatorByNameFactory.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -23,7 +23,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\Messages\Factories\CompanyInformativeValidatorByNameFactory;
|
||||
use App\Models\Validation\Messages\Factories\ItemInformativeValidatorByNameFactory;
|
||||
|
||||
class CartController extends Controller
|
||||
@@ -166,9 +166,9 @@ class CartController extends Controller
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getMessageMap());
|
||||
|
||||
$validator = new CompanyValidationByName($companyName);
|
||||
$validator = (new CompanyInformativeValidatorByNameFactory($companyName))->create();
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getMessageMap());
|
||||
return response()->json($validator->getOkStatus());
|
||||
|
||||
// Get objects
|
||||
$user = User::where('matrix_username', $matrixUsername)->first();
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation;
|
||||
|
||||
use App\Models\Validation\ModelValidationByName;
|
||||
use App\Models\Validation\Messages\CompanyMessagesFactory;
|
||||
|
||||
class CompanyValidationByName extends ModelValidationByName
|
||||
{
|
||||
public function __construct(string $name)
|
||||
{
|
||||
parent::__construct(
|
||||
$name,
|
||||
'App\Models\Company',
|
||||
(new CompanyMessagesFactory())->create(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages;
|
||||
|
||||
use App\Models\Validation\Messages\BaseMessages;
|
||||
|
||||
class CompanyMessagesFactory
|
||||
{
|
||||
protected array $messages = [
|
||||
'found' => 'A company with the name is valid.',
|
||||
'not_found' => 'A company with the name does not exist!!!',
|
||||
'invalid_name' => 'The company name is empty, please, write the name!!!',
|
||||
];
|
||||
|
||||
public function create()
|
||||
{
|
||||
return new BaseMessages($this->messages);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user