This commit is contained in:
63
api/app/Http/Requests/Cadastro/Localizacao/BairroRequest.php
Normal file
63
api/app/Http/Requests/Cadastro/Localizacao/BairroRequest.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Localizacao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
|
||||
class BairroRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST': {
|
||||
|
||||
return $this->getPostRules();
|
||||
}
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,180',
|
||||
'unique:\App\Models\Cadastro\Localizacao\Bairro,nome,NULL,id,deleted_at,NULL',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:3,180',
|
||||
"unique:\App\Models\Cadastro\Localizacao\Bairro,nome,{$this->bairro},id,deleted_at,NULL",
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'O nome do Bairro já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
148
api/app/Http/Requests/Cadastro/Localizacao/LogradouroRequest.php
Normal file
148
api/app/Http/Requests/Cadastro/Localizacao/LogradouroRequest.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Localizacao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
use App\Rules\CnsTermoValido;
|
||||
use App\Utils\DataUtil;
|
||||
use App\Utils\ImportacaoCns;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class LogradouroRequest extends FormRequest
|
||||
{
|
||||
private $regexCep = '/[^0-9]/';
|
||||
private $tamanhoNome = '3,250';
|
||||
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'logradouro_nome' => html_entity_decode($this->logradouro_nome, ENT_QUOTES, 'UTF-8'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST': {
|
||||
|
||||
return $this->getPostRules();
|
||||
}
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
if (DataUtil::getBooleanValueFromStringBoolean($this->search_by_base_endereco_nacional) === true) {
|
||||
$rules = [
|
||||
'municipio_id' => ['required', 'integer'],
|
||||
'logradouro_nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:' . $this->tamanhoNome,
|
||||
'not_regex:' . ImportacaoCns::regexValidacao(),
|
||||
new CnsTermoValido(['attribute' => 'Nome']),
|
||||
],
|
||||
'logradouro_cep' => [
|
||||
'required',
|
||||
'not_regex:' . $this->regexCep,
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$rules = [
|
||||
'municipio_id' => ['required', 'integer'],
|
||||
'bairro_id' => ['required', 'integer'],
|
||||
'tipo_id' => ['required', 'integer'],
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:' . $this->tamanhoNome,
|
||||
'not_regex:' . ImportacaoCns::regexValidacao(),
|
||||
new CnsTermoValido(['attribute' => 'Nome']),
|
||||
Rule::unique('\App\Models\Cadastro\Localizacao\Logradouro')->where(function ($query) {
|
||||
|
||||
return $query
|
||||
->where('municipio_id', $this->municipio_id)
|
||||
->where('bairro_id', $this->bairro_id)
|
||||
->where('tipo_id', $this->tipo_id)
|
||||
->whereNull('deleted_at');
|
||||
}),
|
||||
],
|
||||
'cep' => [
|
||||
'required',
|
||||
'not_regex:' . $this->regexCep,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
if (DataUtil::getBooleanValueFromStringBoolean($this->search_by_base_endereco_nacional) === true) {
|
||||
$rules = [
|
||||
'municipio_id' => ['required', 'integer'],
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:' . $this->tamanhoNome,
|
||||
'not_regex:' . ImportacaoCns::regexValidacao(),
|
||||
new CnsTermoValido(['attribute' => 'Nome']),
|
||||
],
|
||||
'cep' => [
|
||||
'required',
|
||||
'not_regex:' . $this->regexCep,
|
||||
],
|
||||
];
|
||||
} else {
|
||||
|
||||
$rules = [
|
||||
'municipio_id' => ['required', 'integer'],
|
||||
'bairro_id' => ['required', 'integer'],
|
||||
'tipo_id' => ['required', 'integer'],
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:' . $this->tamanhoNome,
|
||||
'not_regex:' . ImportacaoCns::regexValidacao(),
|
||||
new CnsTermoValido(['attribute' => 'Nome']),
|
||||
Rule::unique('\App\Models\Cadastro\Localizacao\Logradouro')->where(function ($query) {
|
||||
|
||||
return $query
|
||||
->where('municipio_id', $this->municipio_id)
|
||||
->where('bairro_id', $this->bairro_id)
|
||||
->where('tipo_id', $this->tipo_id)
|
||||
->whereNull('deleted_at');
|
||||
})->ignore($this->logradouro)
|
||||
],
|
||||
'cep' => [
|
||||
'required',
|
||||
'not_regex:' . $this->regexCep,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'Um Logradouro com o mesmo Tipo, Bairro, Município e Nome já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Cadastro\Localizacao;
|
||||
|
||||
use App\Http\Requests\FormRequest;
|
||||
|
||||
class LoteamentoRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
|
||||
case 'POST': {
|
||||
|
||||
return $this->getPostRules();
|
||||
}
|
||||
case 'PUT': {
|
||||
|
||||
return $this->getPutRules();
|
||||
}
|
||||
default: {
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPostRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:1,100',
|
||||
'unique:\App\Models\Cadastro\Localizacao\Loteamento,nome,NULL,id,deleted_at,NULL',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function getPutRules()
|
||||
{
|
||||
return [
|
||||
'nome' => [
|
||||
'required',
|
||||
'string',
|
||||
'between:1,100',
|
||||
"unique:\App\Models\Cadastro\Localizacao\Loteamento,nome,{$this->loteamento},id,deleted_at,NULL",
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'nome.unique' => 'O nome do Loteamento já foi inserido anteriormente.'
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user