File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/ScaleFunctionController.php
Back
<?php namespace App\Http\Controllers; use App\Rules\ArrayInput; use Illuminate\Http\Request; use App\Models\ScaleFunction; use Illuminate\Http\JsonResponse; use App\Classes\BaseServiceResponse; use Illuminate\Support\Facades\Validator; use App\Http\Requests\ScaleFunctionRequest; use App\Http\Services\ScaleFunctionService; use App\Http\Requests\StoreScaleFunctionRequest; use App\Http\Requests\UpdateScaleFunctionRequest; class ScaleFunctionController extends Controller { private ScaleFunctionService $scaleFunctionService; public function __construct() { $this->scaleFunctionService = new ScaleFunctionService(); $this->middleware('auth.permissions:gestao-de-ocorrencias'); } /** * @OA\Get( * path="/api/scale-function", * summary="Lista todas as funções já cadastradas", * description="Lista todas as funções já cadastradas", * operationId="GetAllScaleFunctions", * security={{"bearerAuth":{}}}, * tags={"scale_functions"}, * @OA\Parameter( * name="page", * in="query", * description="Get items by page", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="type", * in="query", * description="Tipo da função: INTERNA ou EXTERNA.", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="enable", * in="query", * description="A função está ativa: 1, 0. Por padrão, será retornado somente as ativas.", * required=false, * @OA\Schema(type="string") * ), * @OA\Response( * response="200", * description="OK", * @OA\JsonContent( * @OA\Property(property="data", type="json", example="{}"), * @OA\Property(property="message", type="string", example="Success."), * ) * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized."), * ) * ), * ) */ public function index(Request $request): JsonResponse { return $this->response($this->scaleFunctionService->index($request)); } /** * @OA\Post( * path="/api/scale-function", * summary="Adicionar uma nova função de escala", * description="Adicionar uma nova função de escala", * operationId="AddNewScaleFunction", * security={{"bearerAuth":{}}}, * tags={"scale_functions"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"name", "type"}, * @OA\Property( * property="name", * type="string", * example="Chefe", * description="Nome da função" * ), * @OA\Property( * property="enable", * type="string", * example="1", * description="Função habilitada para uso. Caso não seja enviado, o valor será true" * ), * @OA\Property( * property="type", * type="string", * example="INTERNO", * description="As funções podem ser: EXTERNA, INTERNA" * ), * @OA\Property( * property="external_agents", * type="array", * description="Ids de todos os agentes externos que deverão ser vinculados a essa função, caso ela seja uma função EXTERNA", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="internal_agents", * type="array", * description="Ids de todos os agentes externos que deverão ser vinculados a essa função, caso ela seja uma função INTERNA", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"name", "type"}, * @OA\Property( * property="name", * type="string", * example="Chefe", * description="Nome da função" * ), * @OA\Property( * property="enable", * type="string", * example="1", * description="Função habilitada para uso. Caso não seja enviado, o valor será true" * ), * @OA\Property( * property="type", * type="string", * example="INTERNO", * description="As funções podem ser: EXTERNA, INTERNA" * ), * @OA\Property( * property="external_agents", * type="array", * description="Ids de todos os agentes externos que deverão ser vinculados a essa função", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="internal_agents", * type="array", * description="Ids de todos os agentes externos que deverão ser vinculados a essa função, caso ela seja uma função INTERNA", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * ), * @OA\Response( * response="201", * description="Created", * @OA\JsonContent( * @OA\Property(property="data", type="json", example="{}"), * @OA\Property(property="message", type="string", example="Success."), * ) * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized."), * ) * ), * @OA\Response( * response="422", * description="Validation Error", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Validation Error."), * @OA\Property(property="errors", type="json", example="{}"), * ) * ), * ) */ public function store(ScaleFunctionRequest $request): JsonResponse { return $this->response($this->scaleFunctionService->store($request)); } /** * @OA\Get( * path="/api/scale-function/{scale_function_id}", * summary="Exibe os detalhes de uma função", * description="Exibe os detalhes de uma função", * operationId="GetScaleFunctionDetails", * security={{"bearerAuth":{}}}, * tags={"scale_functions"}, * @OA\Parameter( * name="scale_function_id", * in="path", * required=true, * description="ScaleFunction ID", * @OA\Schema(type="string") * ), * @OA\Response( * response="200", * description="OK", * @OA\JsonContent( * @OA\Property(property="data", type="json", example="{}"), * @OA\Property(property="message", type="string", example="Success."), * ) * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized."), * ) * ), * @OA\Response( * response="404", * description="Not found", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Not found."), * ) * ), * ) */ public function show(ScaleFunction $scaleFunction): JsonResponse { return $this->response($this->scaleFunctionService->show($scaleFunction)); } /** * @OA\Put( * path="/api/scale-function/{scale_function_id}", * summary="Altera os dados de uma função", * description="Altera os dados de uma função", * operationId="UpdateScaleFunction", * security={{"bearerAuth":{}}}, * tags={"scale_functions"}, * @OA\Parameter( * name="scale_function_id", * in="path", * required=true, * description="ScaleFunction ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"name", "type"}, * @OA\Property( * property="name", * type="string", * example="Chefe", * description="Nome da função" * ), * @OA\Property( * property="enable", * type="string", * example="1", * description="Função habilitada para uso. Caso não seja enviado, o valor será true" * ), * @OA\Property( * property="type", * type="string", * example="INTERNO", * description="As funções podem ser: EXTERNA, INTERNA" * ), * @OA\Property( * property="external_agents", * type="array", * description="Ids de todos os agentes externos que deverão ser vinculados a essa função", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"name", "type"}, * @OA\Property( * property="name", * type="string", * example="Chefe", * description="Nome da função" * ), * @OA\Property( * property="enable", * type="string", * example="1", * description="Função habilitada para uso. Caso não seja enviado, o valor será true" * ), * @OA\Property( * property="type", * type="string", * example="INTERNO", * description="As funções podem ser: EXTERNA, INTERNA" * ), * @OA\Property( * property="external_agents", * type="array", * description="Ids de todos os agentes externos que deverão ser vinculados a essa função", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * ), * @OA\Response( * response="201", * description="OK", * @OA\JsonContent( * @OA\Property(property="data", type="json", example="{}"), * @OA\Property(property="message", type="string", example="Success."), * ) * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized."), * ) * ), * @OA\Response( * response="422", * description="Validation Error", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Validation Error."), * @OA\Property(property="errors", type="json", example="{}"), * ) * ), * ) */ public function update(ScaleFunctionRequest $request, ScaleFunction $scaleFunction): JsonResponse { return $this->response($this->scaleFunctionService->update($request, $scaleFunction)); } /** * @OA\Post( * path="/api/scale-function/enable", * summary="Habilita múltiplas funções", * description="Habilita múltiplas funções", * operationId="EnableManyScaleFunctions", * security={{"bearerAuth":{}}}, * tags={"scale_functions"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"scale_functions"}, * @OA\Property( * property="scale_functions", * type="array", * description="IDs das funções que deverão ser habilitadas", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"scale_functions"}, * @OA\Property( * property="scale_functions", * type="array", * description="IDs das funções que deverão ser habilitadas", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * ), * @OA\Response( * response="204", * description="No content", * @OA\JsonContent( * @OA\Property(property="data", type="json", example="{}"), * @OA\Property(property="message", type="string", example="Success."), * ) * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized."), * ) * ), * @OA\Response( * response="422", * description="Validation Error", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Validation Error."), * @OA\Property(property="errors", type="json", example="{}"), * ) * ), * ) */ public function enable(Request $request): JsonResponse { $validator = Validator::make($request->all(), [ 'scale_functions' => ['required', new ArrayInput(), 'min:1'], 'scale_functions.*' => ['exists:scale_functions,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->scaleFunctionService->enable($request)); } /** * @OA\Post( * path="/api/scale-function/disable", * summary="Desabilita múltiplas funções", * description="Desabilita múltiplas funções", * operationId="DisableManyScaleFunctions", * security={{"bearerAuth":{}}}, * tags={"scale_functions"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"scale_functions"}, * @OA\Property( * property="scale_functions", * type="array", * description="IDs das funções que deverão ser desabilitadas", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"scale_functions"}, * @OA\Property( * property="scale_functions", * type="array", * description="IDs das funções que deverão ser desabilitadas", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * ), * @OA\Response( * response="204", * description="No content", * @OA\JsonContent( * @OA\Property(property="data", type="json", example="{}"), * @OA\Property(property="message", type="string", example="Success."), * ) * ), * @OA\Response( * response="401", * description="Unauthorized", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Unauthorized."), * ) * ), * @OA\Response( * response="422", * description="Validation Error", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Validation Error."), * @OA\Property(property="errors", type="json", example="{}"), * ) * ), * ) */ public function disable(Request $request): JsonResponse { $validator = Validator::make($request->all(), [ 'scale_functions' => ['required', new ArrayInput(), 'min:1'], 'scale_functions.*' => ['exists:scale_functions,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->scaleFunctionService->disable($request)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings