File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/OccurrencyController.php
Back
<?php namespace App\Http\Controllers; use App\Models\Category; use App\Rules\ArrayInput; use App\Models\Occurrency; use Illuminate\Http\Request; use App\Rules\ValidEnumOption; use App\Enums\OccurrencySection; use Illuminate\Http\JsonResponse; use App\Classes\BaseServiceResponse; use App\Http\Requests\OccurrencyRequest; use App\Http\Services\OccurrencyService; use Illuminate\Support\Facades\Validator; class OccurrencyController extends Controller { private OccurrencyService $occurrencyService; public function __construct() { $this->occurrencyService = new OccurrencyService(); // $this->middleware('auth.permissions:gestao-de-ocorrencias'); } /** * @OA\Get( * path="/api/occurrency", * summary="Get a list of all occurrency", * description="Get a list of all occurrency", * operationId="GetAllOccurrency", * security={{"bearerAuth":{}}}, * tags={"occurrencys"}, * @OA\Parameter( * name="page", * in="query", * description="Get items by page", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="code", * in="query", * description="Occurrency code for search", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="category", * in="query", * description="Category ID to filter", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="occurrency_type", * in="query", * description="Occurrency type ID to filter", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="created_at_start", * in="query", * description="Initial date to filter. Date must be in the format: 2023-09-04 00:00:00", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="created_at_end", * in="query", * description="End date to filter. Date must be in the format: 2023-09-04 00:00:00", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="postal_code", * in="query", * description="CEP do endereço da ocorrência", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="street", * in="query", * description="Logradouro do endereço da ocorrência", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="neighborhood", * in="query", * description="Bairro do endereço da ocorrência", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="city", * in="query", * description="Cidade do endereço da ocorrência", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="state", * in="query", * description="Estado do endereço da ocorrência", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="complement", * in="query", * description="Complemento do endereço da ocorrência", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="reference_point", * in="query", * description="Ponto de referência do endereço da ocorrência", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="number", * in="query", * description="Número do endereço da ocorrência", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="current_section", * in="query", * description="Seção atual da ocorrencia. Pode ser enviado múltiplos: EXECUÇÃO,VISTORIA,REGISTRO.", * 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->occurrencyService->index($request)); } /** * @OA\Post( * path="/api/occurrency", * summary="Add a new occurrency", * description="Add a new occurrency. Forms IDs and fields IDs its provided by category.", * operationId="AddNewOccurrency", * security={{"bearerAuth":{}}}, * tags={"occurrencys"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"occurrency_requester","address","category_id"}, * @OA\Property( * property="category_id", * type="string", * description="Categories' ID" * ), * @OA\Property( * property="description", * type="string", * description="Description" * ), * @OA\Property( * property="occurrency_type", * type="string", * description="Occurrency type's ID" * ), * @OA\Property( * property="images", * type="array", * description="Array with base64 images from occurrency.", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="occurrency_requester", * type="object", * description="Array occurrency requester info.", * @OA\Property(property="document", type="string"), * @OA\Property(property="name", type="string"), * @OA\Property(property="social_name", type="string"), * @OA\Property( * property="phones", * type="array", * @OA\Items( * @OA\Property(property="ddd", type="string"), * @OA\Property(property="number", type="string"), * @OA\Property(property="owner", type="string"), * ) * ), * ), * @OA\Property( * property="address", * type="object", * description="Array address info.", * @OA\Property(property="postal_code", type="string"), * @OA\Property(property="street", type="string"), * @OA\Property(property="neighborhood", type="string"), * @OA\Property(property="city", type="string"), * @OA\Property(property="state", type="string"), * @OA\Property(property="complement", type="string"), * @OA\Property(property="reference_point", type="string"), * @OA\Property(property="latitude", type="string"), * @OA\Property(property="longitude", type="string"), * ), * @OA\Property( * property="forms", * type="array", * description="Array with info forms info. Options available for section: REGISTRO,VISTORIA,EXECUÇÃO", * collectionFormat="multi", * @OA\Items( * @OA\Property( * property="id", * type="string", * ), * @OA\Property( * property="section", * type="string", * ), * @OA\Property( * property="fields", * type="array", * @OA\Items( * @OA\Property(property="id", type="string"), * @OA\Property(property="value", type="string"), * ) * ), * ), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"occurrency_requester","address","category_id"}, * @OA\Property( * property="category_id", * type="string", * description="Categories' ID" * ), * @OA\Property( * property="description", * type="string", * description="Description" * ), * @OA\Property( * property="occurrency_type", * type="string", * description="Occurrency type's ID" * ), * @OA\Property( * property="images", * type="array", * description="Array with base64 images from occurrency.", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="occurrency_requester", * type="object", * description="Array occurrency requester info.", * @OA\Property(property="document", type="string"), * @OA\Property(property="name", type="string"), * @OA\Property(property="social_name", type="string"), * @OA\Property( * property="phones", * type="array", * @OA\Items( * @OA\Property(property="ddd", type="string"), * @OA\Property(property="number", type="string"), * @OA\Property(property="owner", type="string"), * ) * ), * ), * @OA\Property( * property="address", * type="object", * description="Array address info.", * @OA\Property(property="postal_code", type="string"), * @OA\Property(property="street", type="string"), * @OA\Property(property="neighborhood", type="string"), * @OA\Property(property="city", type="string"), * @OA\Property(property="state", type="string"), * @OA\Property(property="complement", type="string"), * @OA\Property(property="reference_point", type="string"), * @OA\Property(property="latitude", type="string"), * @OA\Property(property="longitude", type="string"), * ), * @OA\Property( * property="forms", * type="array", * description="Array with info forms info. Options available for section: REGISTRO,VISTORIA,EXECUÇÃO", * collectionFormat="multi", * @OA\Items( * @OA\Property( * property="id", * type="string", * ), * @OA\Property( * property="section", * type="string", * ), * @OA\Property( * property="fields", * type="array", * @OA\Items( * @OA\Property(property="id", type="string"), * @OA\Property(property="value", type="string"), * ) * ), * ), * ), * ) * ), * ), * @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(OccurrencyRequest $request): JsonResponse { $category = Category::findOrFail($request->category_id); if ($category->occurrencyTypes()->count() > 0) { $validator = Validator::make($request->all(), [ 'occurrency_type' => ['required', 'exists:occurrency_types,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } } return $this->response($this->occurrencyService->store($request)); } /** * @OA\Get( * path="/api/occurrency/{occurrency_id}", * summary="Get details from a occurrency", * description="Get details from a occurrency", * operationId="GetOccurrencyDetails", * security={{"bearerAuth":{}}}, * tags={"occurrencys"}, * @OA\Parameter( * name="section", * in="query", * description="Filtra os formulários dinamicos por seção. Valores: REGISTRO, VISTORIA, EXECUÇÃO", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="occurrency_id", * in="path", * required=true, * description="Occurrency 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(Request $request, Occurrency $occurrency): JsonResponse { return $this->response($this->occurrencyService->show($request, $occurrency)); } /** * @OA\Put( * path="/api/occurrency/{occurrency_id}", * summary="Update a occurrency", * description="Update a occurrency. Forms IDs and Fields IDs are provided by occurrency itself.", * operationId="UpdateOccurrency", * security={{"bearerAuth":{}}}, * tags={"occurrencys"}, * @OA\Parameter( * name="occurrency_id", * in="path", * required=true, * description="Occurrency ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"occurrency_requester","address","category_id"}, * @OA\Property( * property="description", * type="string", * description="Description" * ), * @OA\Property( * property="occurrency_type", * type="string", * description="Occurrency type's ID" * ), * @OA\Property( * property="images", * type="array", * description="Array with base64 images from occurrency.", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="occurrency_requester", * type="object", * description="Field from REGISTRO. Array occurrency requester info.", * @OA\Property(property="id", type="string"), * @OA\Property(property="document", type="string"), * @OA\Property(property="name", type="string"), * @OA\Property(property="social_name", type="string"), * @OA\Property( * property="phones", * type="array", * @OA\Items( * @OA\Property(property="id", type="string"), * @OA\Property(property="ddd", type="string"), * @OA\Property(property="number", type="string"), * @OA\Property(property="owner", type="string"), * ) * ), * ), * @OA\Property( * property="address", * type="object", * description="Field from REGISTRO. Array address info.", * @OA\Property(property="id", type="string"), * @OA\Property(property="postal_code", type="string"), * @OA\Property(property="street", type="string"), * @OA\Property(property="neighborhood", type="string"), * @OA\Property(property="city", type="string"), * @OA\Property(property="state", type="string"), * @OA\Property(property="complement", type="string"), * @OA\Property(property="reference_point", type="string"), * @OA\Property(property="latitude", type="string"), * @OA\Property(property="longitude", type="string"), * ), * @OA\Property( * property="forms", * type="array", * description="Can be from any section. Array with info forms info", * collectionFormat="multi", * @OA\Items( * @OA\Property( * property="id", * type="string", * ), * @OA\Property( * property="fields", * type="array", * @OA\Items( * @OA\Property(property="id", type="string"), * @OA\Property(property="value", type="string"), * ) * ), * ), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"occurrency_requester","address","category_id"}, * @OA\Property( * property="description", * type="string", * description="Description" * ), * @OA\Property( * property="occurrency_type", * type="string", * description="Occurrency type's ID" * ), * @OA\Property( * property="images", * type="array", * description="Array with base64 images from occurrency.", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="occurrency_requester", * type="object", * description="Field from REGISTRO. Array occurrency requester info.", * @OA\Property(property="id", type="string"), * @OA\Property(property="document", type="string"), * @OA\Property(property="name", type="string"), * @OA\Property(property="social_name", type="string"), * @OA\Property( * property="phones", * type="array", * @OA\Items( * @OA\Property(property="id", type="string"), * @OA\Property(property="ddd", type="string"), * @OA\Property(property="number", type="string"), * @OA\Property(property="owner", type="string"), * ) * ), * ), * @OA\Property( * property="address", * type="object", * description="Field from REGISTRO. Array address info.", * @OA\Property(property="id", type="string"), * @OA\Property(property="postal_code", type="string"), * @OA\Property(property="street", type="string"), * @OA\Property(property="neighborhood", type="string"), * @OA\Property(property="city", type="string"), * @OA\Property(property="state", type="string"), * @OA\Property(property="complement", type="string"), * @OA\Property(property="reference_point", type="string"), * @OA\Property(property="latitude", type="string"), * @OA\Property(property="longitude", type="string"), * ), * @OA\Property( * property="forms", * type="array", * description="Can be from any section. Array with info forms info", * collectionFormat="multi", * @OA\Items( * @OA\Property( * property="id", * type="string", * ), * @OA\Property( * property="fields", * type="array", * @OA\Items( * @OA\Property(property="id", type="string"), * @OA\Property(property="value", type="string"), * ) * ), * ), * ), * ) * ), * ), * @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(OccurrencyRequest $request, Occurrency $occurrency): JsonResponse { return $this->response($this->occurrencyService->update($request, $occurrency)); } /** * @OA\Delete( * path="/api/occurrency/{occurrency_id}", * summary="Delete a occurrency", * description="Delete a occurrency", * operationId="DeleteOccurrency", * security={{"bearerAuth":{}}}, * tags={"occurrencys"}, * @OA\Parameter( * name="occurrency_id", * in="path", * required=true, * description="Occurrency 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(Occurrency $occurrency): JsonResponse { return $this->response($this->occurrencyService->destroy($occurrency)); } /** * @OA\Post( * path="/api/occurrency/destroy-many", * summary="Delete multiple occurrency", * description="Delete multiple occurrency", * operationId="DeleteManyOccurrencies", * security={{"bearerAuth":{}}}, * tags={"occurrencys"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"occurrencies"}, * @OA\Property( * property="occurrencies", * type="array", * description="Ids of occurrencies to delete", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"occurrencies"}, * @OA\Property( * property="occurrencies", * type="array", * description="Ids of occurrencies 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(), [ 'occurrencies' => ['required', new ArrayInput()], 'occurrencies.*' => ['exists:occurrencies,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->occurrencyService->destroyMany($request)); } /** * @OA\Post( * path="/api/occurrency/{occurrency_id}/move", * summary="Movimenta uma ocorrência", * description="Movimenta uma ocorrência", * operationId="MoveOccurrency", * security={{"bearerAuth":{}}}, * tags={"occurrencys"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"section"}, * @OA\Property( * property="section", * type="string", * ), * ) * ), * ), * @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 move(Request $request, Occurrency $occurrency): JsonResponse { $validator = Validator::make($request->all(), [ 'section' => ['required', new ValidEnumOption(OccurrencySection::cases())], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->occurrencyService->move($request, $occurrency)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings