File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/ExternalAgentController.php
Back
<?php namespace App\Http\Controllers; use App\Rules\ArrayInput; use Illuminate\Http\Request; use App\Models\ExternalAgent; use Illuminate\Http\JsonResponse; use App\Classes\BaseServiceResponse; use Illuminate\Support\Facades\Validator; use App\Http\Requests\ExternalAgentRequest; use App\Http\Services\ExternalAgentService; use App\Http\Requests\StoreExternalAgentRequest; use App\Http\Requests\UpdateExternalAgentRequest; class ExternalAgentController extends Controller { private ExternalAgentService $externalAgentService; public function __construct() { $this->externalAgentService = new ExternalAgentService(); $this->middleware('auth.permissions:gestao-de-ocorrencias'); } /** * @OA\Get( * path="/api/external-agent", * summary="Lista todos os agentes externos já criados", * description="Lista todos os agentes externos já criados", * operationId="GetAllExternalAgents", * security={{"bearerAuth":{}}}, * tags={"external_agents"}, * @OA\Parameter( * name="page", * in="query", * description="Get items by page", * 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(): JsonResponse { return $this->response($this->externalAgentService->index()); } /** * @OA\Post( * path="/api/external-agent", * summary="Adiciona um novo agente externo", * description="Adiciona um novo agente externo", * operationId="AddNewExternalAgent", * security={{"bearerAuth":{}}}, * tags={"external_agents"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"name"}, * @OA\Property( * property="name", * type="string", * example="Carlos", * description="Nome do agente externo" * ), * * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"name"}, * @OA\Property( * property="name", * type="string", * example="Carlos", * description="Nome do agente externo" * ), * * ) * ), * ), * @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(ExternalAgentRequest $request): JsonResponse { return $this->response($this->externalAgentService->store($request)); } /** * @OA\Get( * path="/api/external-agent/{external_agent_id}", * summary="Exibe os detalhes de um agente externo", * description="Exibe os detalhes de um agente externo", * operationId="GetExternalAgentDetails", * security={{"bearerAuth":{}}}, * tags={"external_agents"}, * @OA\Parameter( * name="external_agent_id", * in="path", * required=true, * description="ExternalAgent 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(ExternalAgent $externalAgent): JsonResponse { return $this->response($this->externalAgentService->show($externalAgent)); } /** * @OA\Put( * path="/api/external-agent/{external_agent_id}", * summary="Altera os dados de um agente externo", * description="Altera os dados de um agente externo", * operationId="UpdateExternalAgent", * security={{"bearerAuth":{}}}, * tags={"external_agents"}, * @OA\Parameter( * name="external_agent_id", * in="path", * required=true, * description="ExternalAgent ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"name"}, * @OA\Property( * property="name", * type="string", * example="Carlos", * description="Nome do agente externo" * ), * * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"name"}, * @OA\Property( * property="name", * type="string", * example="Carlos", * description="Nome do agente externo" * ), * * ) * ), * ), * @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(ExternalAgentRequest $request, ExternalAgent $externalAgent): JsonResponse { return $this->response($this->externalAgentService->update($request, $externalAgent)); } /** * @OA\Post( * path="/api/external-agent/destroy-many", * summary="Exclui múltiplos agentes externos", * description="Exclui múltiplos agentes externos", * operationId="DeleteManyExternalAgents", * security={{"bearerAuth":{}}}, * tags={"external_agents"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"external_agents"}, * @OA\Property( * property="external_agents", * type="array", * description="Ids dos agentes externos para excluir", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"external_agents"}, * @OA\Property( * property="external_agents", * type="array", * description="Ids dos agentes externos para excluir", * 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 destroyMany(Request $request): JsonResponse { $validator = Validator::make($request->all(), [ 'external_agents' => ['required', new ArrayInput()], 'external_agents.*' => ['exists:external_agents,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->externalAgentService->destroyMany($request)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings