Refactor to use UserInformativeValidatorByMatrixUserNameFactory.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -21,7 +21,7 @@ use App\DotsAPI\Fetcher\v2\AuthApiFetcher;
|
||||
use App\DotsAPI\Fetcher\v2\AuthApiSender;
|
||||
use App\Http\Resources\API\v2\CartItemCollection;
|
||||
|
||||
use App\Models\Validation\UserValidationByMatrixUsername;
|
||||
use App\Models\Validation\Validators\Informative\Factories\UserInformativeValidatorByMatrixUserNameFactory;
|
||||
use App\Models\Validation\Validators\Informative\Factories\CityInformativeValidatorByNameFactory;
|
||||
use App\Models\Validation\Validators\Informative\Factories\CompanyInformativeValidatorByNameFactory;
|
||||
use App\Models\Validation\Validators\Informative\Factories\ItemInformativeValidatorByNameFactory;
|
||||
@@ -119,13 +119,15 @@ class CartController extends Controller
|
||||
$matrixUsername = $request->input('matrixUsername') ?? '';
|
||||
$cityName = $request->input('cityName') ?? '';
|
||||
|
||||
$validator = new UserValidationByMatrixUsername($matrixUsername);
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getMessageMap());
|
||||
$validators = [
|
||||
(new UserInformativeValidatorByMatrixUserNameFactory($matrixUsername))->create(),
|
||||
(new CityInformativeValidatorByNameFactory($cityName))->create()
|
||||
];
|
||||
|
||||
$validator = (new CityInformativeValidatorByNameFactory($cityName))->create();
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getOkStatus());
|
||||
foreach($validators as $validator) {
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getOkStatus());
|
||||
}
|
||||
|
||||
// Get objects
|
||||
$user = User::where('matrix_username', $matrixUsername)->first();
|
||||
@@ -162,13 +164,15 @@ class CartController extends Controller
|
||||
$matrixUsername = $request->input('matrixUsername') ?? '';
|
||||
$companyName = $request->input('companyName') ?? '';
|
||||
|
||||
$validator = new UserValidationByMatrixUsername($matrixUsername);
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getMessageMap());
|
||||
$validators = [
|
||||
(new UserInformativeValidatorByMatrixUserNameFactory($matrixUsername))->create(),
|
||||
(new CompanyInformativeValidatorByNameFactory($companyName))->create()
|
||||
];
|
||||
|
||||
$validator = (new CompanyInformativeValidatorByNameFactory($companyName))->create();
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getOkStatus());
|
||||
foreach($validators as $validator) {
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getOkStatus());
|
||||
}
|
||||
|
||||
// Get objects
|
||||
$user = User::where('matrix_username', $matrixUsername)->first();
|
||||
@@ -203,13 +207,15 @@ class CartController extends Controller
|
||||
$itemName = $request->input('itemName') ?? '';
|
||||
$itemCount = $request->input('itemCount') ?? '';
|
||||
|
||||
$validator = new UserValidationByMatrixUsername($matrixUsername);
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getMessageMap());
|
||||
$validators = [
|
||||
(new UserInformativeValidatorByMatrixUserNameFactory($matrixUsername))->create(),
|
||||
(new ItemInformativeValidatorByNameFactory($itemName))->create()
|
||||
];
|
||||
|
||||
$validator = (new ItemInformativeValidatorByNameFactory($itemName))->create();
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getOkStatus());
|
||||
foreach($validators as $validator) {
|
||||
if(!$validator->isValid())
|
||||
return response()->json($validator->getOkStatus());
|
||||
}
|
||||
|
||||
if($itemCount == 0)
|
||||
return response()->json([
|
||||
|
||||
+1
-15
@@ -9,9 +9,7 @@ use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use App\Models\Validation\ValidationByNameInterface;
|
||||
|
||||
class User extends Authenticatable implements ValidationByNameInterface
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
@@ -29,18 +27,6 @@ class User extends Authenticatable implements ValidationByNameInterface
|
||||
|
||||
|
||||
|
||||
public static function isExistByName(string $name): bool
|
||||
{
|
||||
$count = User::where('matrix_username', $name)->count();
|
||||
|
||||
return $count != 0;
|
||||
}
|
||||
|
||||
public static function isNameValid(string $name): bool
|
||||
{
|
||||
return $name != '';
|
||||
}
|
||||
|
||||
public function userAddresses(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserAddress::class);
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation\Messages;
|
||||
|
||||
use App\Models\Validation\Messages\BaseMessages;
|
||||
|
||||
class UserMessagesFactory
|
||||
{
|
||||
protected array $messages = [
|
||||
'found' => 'A user with the username is valid.',
|
||||
'not_found' => 'A user with the username does not exist!!!',
|
||||
'invalid_name' => 'The username is empty, please, write username!!!',
|
||||
];
|
||||
|
||||
public function create()
|
||||
{
|
||||
return new BaseMessages($this->messages);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Validation;
|
||||
|
||||
use App\Models\Validation\ModelValidationByName;
|
||||
use App\Models\Validation\Messages\UserMessagesFactory;
|
||||
|
||||
class UserValidationByMatrixUsername extends ModelValidationByName
|
||||
{
|
||||
public function __construct(string $name)
|
||||
{
|
||||
parent::__construct(
|
||||
$name,
|
||||
'App\Models\User',
|
||||
(new UserMessagesFactory())->create(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user