File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/FieldController.php
Back
<?php namespace App\Http\Controllers; use App\Models\Field; use App\Rules\ArrayInput; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use App\Http\Requests\FieldRequest; use App\Http\Services\FieldService; use App\Classes\BaseServiceResponse; use Illuminate\Support\Facades\Validator; class FieldController extends Controller { private FieldService $fieldService; public function __construct() { $this->fieldService = new FieldService(); // $this->middleware('auth.permissions:gestao-de-formularios'); } /** * @OA\Get( * path="/api/field", * summary="Get a list of all fields", * description="Get a list of all fields", * operationId="GetAllFields", * security={{"bearerAuth":{}}}, * tags={"fields"}, * @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 categories' 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->fieldService->index($request)); } /** * @OA\Post( * path="/api/field", * summary="Add a new field", * description="Add a new field", * operationId="AddNewField", * security={{"bearerAuth":{}}}, * tags={"fields"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"label", "type"}, * @OA\Property( * property="label", * type="string", * example="Nome", * description="Input label" * ), * @OA\Property( * property="type", * type="string", * enum={"text", "select", "textarea", "file", "number"}, * example="text", * description="Input type" * ), * @OA\Property( * property="title", * type="string", * description="Input title" * ), * @OA\Property( * property="description", * type="string", * description="Internal description to admin, not used on input config" * ), * @OA\Property( * property="multiple", * type="boolean", * description="Field to be used on all inputs that can use multiple prop (ex.: select, file). Default value is false.", * example=false * ), * @OA\Property( * property="options", * type="array", * description="Options to be used with select input.", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="system_item", * type="boolean", * description="Set if this field's value should be set by backend", * example=false * ), * @OA\Property( * property="system_item_type", * type="string", * enum={"CURRENT_USER", "CURRENT_TIME", "CURRENT_DATE", "CURRENT_DATE_TIME"}, * description="If the field is system_field, select wich value should be" * ), * @OA\Property( * property="must_be_updated", * type="boolean", * description="Set if the value of the field must be updated on form update. Ex.: field with CURRENT_TIME value must have his value updated when form is updated.", * example=false * ), * @OA\Property( * property="validations", * type="array", * description="Ids of all validations that will be applyed on this field", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"label", "type"}, * @OA\Property( * property="label", * type="string", * example="Nome", * description="Input label" * ), * @OA\Property( * property="type", * type="string", * enum={"text", "select", "textarea", "file", "number"}, * example="text", * description="Input type" * ), * @OA\Property( * property="title", * type="string", * description="Input title" * ), * @OA\Property( * property="description", * type="string", * description="Internal description to admin, not used on input config" * ), * @OA\Property( * property="multiple", * type="boolean", * description="Field to be used on all inputs that can use multiple prop (ex.: select, file). Default value is false.", * example=false * ), * @OA\Property( * property="options", * type="array", * description="Options to be used with select input.", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="system_item", * type="boolean", * description="Set if this field's value should be set by backend", * example=false * ), * @OA\Property( * property="system_item_type", * type="string", * enum={"CURRENT_USER", "CURRENT_TIME", "CURRENT_DATE", "CURRENT_DATE_TIME"}, * description="If the field is system_field, select wich value should be" * ), * @OA\Property( * property="must_be_updated", * type="boolean", * description="Set if the value of the field must be updated on form update. Ex.: field with CURRENT_TIME value must have his value updated when form is updated.", * example=false * ), * @OA\Property( * property="validations", * type="array", * description="Ids of all validations that will be applyed on this field", * 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(FieldRequest $request): JsonResponse { return $this->response($this->fieldService->store($request)); } /** * @OA\Get( * path="/api/field/{field_id}", * summary="Get details from a field", * description="Get details from a field", * operationId="GetFieldDetails", * security={{"bearerAuth":{}}}, * tags={"fields"}, * @OA\Parameter( * name="field_id", * in="path", * required=true, * description="Field 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(Field $field): JsonResponse { return $this->response($this->fieldService->show($field)); } /** * @OA\Put( * path="/api/field/{field_id}", * summary="Update a field", * description="Update a field", * operationId="UpdateField", * security={{"bearerAuth":{}}}, * tags={"fields"}, * @OA\Parameter( * name="field_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={"label", "type"}, * @OA\Property( * property="label", * type="string", * example="Nome", * description="Input label" * ), * @OA\Property( * property="type", * type="string", * enum={"text", "select", "textarea", "file", "number"}, * example="text", * description="Input type" * ), * @OA\Property( * property="title", * type="string", * description="Input title" * ), * @OA\Property( * property="description", * type="string", * description="Internal description to admin, not used on input config" * ), * @OA\Property( * property="multiple", * type="boolean", * description="Field to be used on all inputs that can use multiple prop (ex.: select, file). Default value is false.", * example=false * ), * @OA\Property( * property="options", * type="array", * description="Options to be used with select input.", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="system_item", * type="boolean", * description="Set if this field's value should be set by backend", * example=false * ), * @OA\Property( * property="system_item_type", * type="string", * enum={"CURRENT_USER", "CURRENT_TIME", "CURRENT_DATE", "CURRENT_DATE_TIME"}, * description="If the field is system_field, select wich value should be" * ), * @OA\Property( * property="must_be_updated", * type="boolean", * description="Set if the value of the field must be updated on form update. Ex.: field with CURRENT_TIME value must have his value updated when form is updated.", * example=false * ), * @OA\Property( * property="validations", * type="array", * description="Ids of all validations that will be applyed on this field", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"label", "type"}, * @OA\Property( * property="label", * type="string", * example="Nome", * description="Input label" * ), * @OA\Property( * property="type", * type="string", * enum={"text", "select", "textarea", "file", "number"}, * example="text", * description="Input type" * ), * @OA\Property( * property="title", * type="string", * description="Input title" * ), * @OA\Property( * property="description", * type="string", * description="Internal description to admin, not used on input config" * ), * @OA\Property( * property="multiple", * type="boolean", * description="Field to be used on all inputs that can use multiple prop (ex.: select, file). Default value is false.", * example=false * ), * @OA\Property( * property="options", * type="array", * description="Options to be used with select input.", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="system_item", * type="boolean", * description="Set if this field's value should be set by backend", * example=false * ), * @OA\Property( * property="system_item_type", * type="string", * enum={"CURRENT_USER", "CURRENT_TIME", "CURRENT_DATE", "CURRENT_DATE_TIME"}, * description="If the field is system_field, select wich value should be" * ), * @OA\Property( * property="must_be_updated", * type="boolean", * description="Set if the value of the field must be updated on form update. Ex.: field with CURRENT_TIME value must have his value updated when form is updated.", * example=false * ), * @OA\Property( * property="validations", * type="array", * description="Ids of all validations that will be applyed on this field", * 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(FieldRequest $request, Field $field): JsonResponse { return $this->response($this->fieldService->update($request, $field)); } /** * @OA\Delete( * path="/api/field/{field_id}", * summary="Delete a field", * description="Delete a field", * operationId="DeleteField", * security={{"bearerAuth":{}}}, * tags={"fields"}, * @OA\Parameter( * name="field_id", * in="path", * required=true, * description="Field 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(Field $field): JsonResponse { return $this->response($this->fieldService->destroy($field)); } /** * @OA\Post( * path="/api/field/destroy-many", * summary="Delete multiple fields", * description="Delete multiple fields", * operationId="DeleteManyFields", * security={{"bearerAuth":{}}}, * tags={"fields"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"fields"}, * @OA\Property( * property="fields", * type="array", * description="Ids of fields to delete", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"fields"}, * @OA\Property( * property="fields", * type="array", * description="Ids of fields 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(), [ 'fields' => ['required', new ArrayInput()], 'fields.*' => ['exists:fields,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->fieldService->destroyMany($request)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings