File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/FormController.php
Back
<?php namespace App\Http\Controllers; use App\Models\Form; use App\Rules\ArrayInput; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use App\Http\Requests\FormRequest; use App\Http\Services\FormService; use App\Classes\BaseServiceResponse; use Illuminate\Support\Facades\Validator; class FormController extends Controller { private FormService $formService; public function __construct() { $this->formService = new FormService(); // $this->middleware('auth.permissions:gestao-de-formularios'); } /** * @OA\Get( * path="/api/form", * summary="Get a list of all forms", * description="Get a list of all forms", * operationId="GetAllForms", * security={{"bearerAuth":{}}}, * tags={"forms"}, * @OA\Parameter( * name="page", * in="query", * description="Get items by page", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="search_term", * in="query", * description="Search the given substring on forms' properties", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="without_pages", * in="query", * description="Return results without pagination. Value: 1", * 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->formService->index($request)); } /** * @OA\Post( * path="/api/form", * summary="Add a new form", * description="Add a new form", * operationId="AddNewForm", * security={{"bearerAuth":{}}}, * tags={"forms"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"name", "fields"}, * @OA\Property( * property="name", * type="string", * example="Formulário 1", * description="Form name" * ), * @OA\Property( * property="description", * type="string", * example="Descrição do formulário 1", * description="Form description" * ), * @OA\Property( * property="fields", * type="array", * description="Array with fields' ids that will compose this form.", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"name", "fields"}, * @OA\Property( * property="name", * type="string", * example="Formulário 1", * description="Form name" * ), * @OA\Property( * property="description", * type="string", * example="Descrição do formulário 1", * description="Form description" * ), * @OA\Property( * property="fields", * type="array", * description="Array with fields' ids that will compose this form.", * 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(FormRequest $request): JsonResponse { return $this->response($this->formService->store($request)); } /** * @OA\Get( * path="/api/form/{form_id}", * summary="Get details from a form", * description="Get details from a form", * operationId="GetFormDetails", * security={{"bearerAuth":{}}}, * tags={"forms"}, * @OA\Parameter( * name="form_id", * in="path", * required=true, * description="Form 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(Form $form): JsonResponse { return $this->response($this->formService->show($form)); } /** * @OA\Put( * path="/api/form/{form_id}", * summary="Update a form", * description="Update a form", * operationId="UpdateForm", * security={{"bearerAuth":{}}}, * tags={"forms"}, * @OA\Parameter( * name="form_id", * in="path", * required=true, * description="Field ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"name", "fields"}, * @OA\Property( * property="name", * type="string", * example="Formulário 1", * description="Form name" * ), * @OA\Property( * property="description", * type="string", * example="Descrição do formulário 1", * description="Form description" * ), * @OA\Property( * property="fields", * type="array", * description="Array with fields' ids that will compose this form.", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"name", "fields"}, * @OA\Property( * property="name", * type="string", * example="Formulário 1", * description="Form name" * ), * @OA\Property( * property="description", * type="string", * example="Descrição do formulário 1", * description="Form description" * ), * @OA\Property( * property="fields", * type="array", * description="Array with fields' ids that will compose this form.", * 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(FormRequest $request, Form $form): JsonResponse { return $this->response($this->formService->update($request, $form)); } /** * @OA\Delete( * path="/api/form/{form_id}", * summary="Delete a form", * description="Delete a form", * operationId="DeleteForm", * security={{"bearerAuth":{}}}, * tags={"forms"}, * @OA\Parameter( * name="form_id", * in="path", * required=true, * description="Form ID", * @OA\Schema(type="string") * ), * @OA\Response( * response="204", * description="No content", * ), * @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 destroy(Form $form): JsonResponse { return $this->response($this->formService->destroy($form)); } /** * @OA\Post( * path="/api/form/destroy-many", * summary="Delete multiple forms", * description="Delete multiple forms", * operationId="DeleteManyForms", * security={{"bearerAuth":{}}}, * tags={"forms"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"forms"}, * @OA\Property( * property="forms", * type="array", * description="Ids of forms to delete", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"forms"}, * @OA\Property( * property="forms", * type="array", * description="Ids of forms to delete", * 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(), [ 'forms' => ['required', new ArrayInput], 'forms.*' => ['exists:forms,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->formService->destroyMany($request)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings