-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #750 from portabilis/portabilis-patch-2021-01-26
[2.5] Portabilis patch 26/01/2021
- Loading branch information
Showing
19 changed files
with
379 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\Api\UpdateStateRegistrationRequest; | ||
use App\Models\LegacyStudent; | ||
use Throwable; | ||
|
||
class StudentController extends Controller | ||
{ | ||
/** | ||
* Atualiza a inscrição estadual de um aluno. | ||
* | ||
* @param UpdateStateRegistrationRequest $request | ||
* @param LegacyStudent $student | ||
* | ||
* @throws Throwable | ||
* @return array | ||
*/ | ||
public function updateStateRegistration(UpdateStateRegistrationRequest $request, LegacyStudent $student) | ||
{ | ||
$student->state_registration_id = $request->getStateRegistration(); | ||
$student->saveOrFail(); | ||
|
||
return [ | ||
'id' => $student->getKey(), | ||
'state_registration_id' => $student->state_registration_id, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Validation\UnauthorizedException; | ||
|
||
class CheckToken | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param Request $request | ||
* @param Closure $next | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle($request, Closure $next) | ||
{ | ||
$token = $request->bearerToken(); | ||
|
||
if ($token && config('legacy.apis.access_key') === $token) { | ||
return $next($request); | ||
} | ||
|
||
throw new UnauthorizedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Api; | ||
|
||
use App\Rules\StateRegistrationFormatRule; | ||
use App\Rules\StateRegistrationUniqueRule; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class UpdateStateRegistrationRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'state_registration_id' => [ | ||
new StateRegistrationFormatRule(), | ||
new StateRegistrationUniqueRule($this->student), | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getStateRegistration() | ||
{ | ||
return $this->input('state_registration_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Rules; | ||
|
||
use Illuminate\Contracts\Validation\Rule; | ||
|
||
class StateRegistrationFormatRule implements Rule | ||
{ | ||
/** | ||
* Determine if the validation rule passes. | ||
* | ||
* @param string $attribute | ||
* @param mixed $value | ||
* | ||
* @return bool | ||
*/ | ||
public function passes($attribute, $value) | ||
{ | ||
return preg_match('/[0-9]{3}\.[0-9]{3}\.[0-9]{3}(\-[0-9]{1})?/', $value); | ||
} | ||
|
||
/** | ||
* Get the validation error message. | ||
* | ||
* @return string | ||
*/ | ||
public function message() | ||
{ | ||
return 'O número de inscrição é inválido.'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Rules; | ||
|
||
use App\Models\LegacyStudent; | ||
use Illuminate\Contracts\Validation\Rule; | ||
|
||
class StateRegistrationUniqueRule implements Rule | ||
{ | ||
private $studentToIgnore; | ||
|
||
/** | ||
* Create a new rule instance. | ||
* | ||
* @param LegacyStudent $studentToIgnore | ||
*/ | ||
public function __construct($studentToIgnore = null) | ||
{ | ||
$this->studentToIgnore = $studentToIgnore; | ||
} | ||
|
||
/** | ||
* Determine if the validation rule passes. | ||
* | ||
* @param string $attribute | ||
* @param mixed $value | ||
* @return bool | ||
*/ | ||
public function passes($attribute, $value) | ||
{ | ||
return LegacyStudent::query() | ||
->where('aluno_estado_id', $value) | ||
->when($this->studentToIgnore, function ($query) use ($value) { | ||
$query->where('cod_aluno', '<>', $this->studentToIgnore->getKey()); | ||
}) | ||
->doesntExist(); | ||
} | ||
|
||
/** | ||
* Get the validation error message. | ||
* | ||
* @return string | ||
*/ | ||
public function message() | ||
{ | ||
return 'Já existe uma aluno com este número de inscrição.'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.