File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/BDTController.php
Back
<?php namespace App\Http\Controllers; use App\Models\BDT; use App\Rules\ArrayInput; use App\Rules\BooleanInput; use Illuminate\Http\Request; use App\Http\Services\BDTService; use Illuminate\Http\JsonResponse; use App\Classes\BaseServiceResponse; use Illuminate\Support\Facades\Validator; class BDTController extends Controller { private BDTService $bdtService; public function __construct() { $this->bdtService = new BDTService(); $this->middleware('auth.permissions:gestao-de-ocorrencias'); } /** * @OA\Get( * path="/api/bdt/me", * summary="Retorna os bdts do dia atual do usuário autenticado", * description="Retorna os bdts do dia atual do usuário autenticado", * operationId="GetMyBDT", * security={{"bearerAuth":{}}}, * tags={"BDT"}, * @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 me(): JsonResponse { return $this->response($this->bdtService->me()); } /** * @OA\Get( * path="/api/bdt/{bdt_id}", * summary="Detalhes do item", * description="Detalhes do item", * operationId="ShowBDT", * security={{"bearerAuth":{}}}, * tags={"BDT"}, * @OA\Parameter( * name="bdt_id", * in="path", * required=true, * description="BDT 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."), * ) * ), * ) */ public function show(BDT $bdt): JsonResponse { return $this->response($this->bdtService->show($bdt)); } /** * @OA\Post( * path="/api/bdt/{bdt_id}/tranportation-supply", * summary="Adiciona um novo registro", * description="Adiciona um novo registro", * operationId="BDTTransportationSupply", * security={{"bearerAuth":{}}}, * tags={"BDT"}, * @OA\Parameter( * name="bdt_id", * in="path", * required=true, * description="BDT ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"hour","odometer","liters","document_number","file"}, * @OA\Property( * property="hour", * type="string", * example="08:00", * description="Hora do abastecimento" * ), * @OA\Property( * property="odometer", * type="string", * example="58", * description="Valor do odômetro do carro após o abastecimento" * ), * @OA\Property( * property="liters", * type="string", * example="20", * description="Quantidade de litros do abastecimento" * ), * @OA\Property( * property="document_number", * type="string", * example="897897", * description="Número do recibo do abastecimento" * ), * @OA\Property( * property="file", * type="file", * example="base64", * description="Comprovante do recibo" * ), * ) * ), * ), * @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 transportationSupply(BDT $bdt): JsonResponse { $validator = Validator::make(request()->all(), [ 'hour' => ['required', 'regex:/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/'], 'odometer' => ['required'], 'liters' => ['required'], 'document_number' => ['required'], 'file' => ['required'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->bdtService->transportationSupply($bdt)); } /** * @OA\Post( * path="/api/bdt/{bdt_id}/finish", * summary="Finaliza um BDT", * description="Finaliza um BDT", * operationId="FinishBDT", * security={{"bearerAuth":{}}}, * tags={"BDT"}, * @OA\Parameter( * name="bdt_id", * in="path", * required=true, * description="BDT ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"occurrencies","tank_completed"}, * @OA\Property( * property="occurrencies", * type="array", * description="Array com as ocorrencias do bdt", * collectionFormat="multi", * @OA\Items( * @OA\Property( * property="id", * type="string", * description="ID da ocorrência" * ), * @OA\Property( * property="finished", * type="boolean", * description="A ocorrência foi finalizada?" * ), * ), * ), * @OA\Property( * property="tank_completed", * type="boolean", * description="O tanque de gasolina do transporte foi completo nesse BDT?" * ), * ) * ), * ), * @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 finish(BDT $bdt): JsonResponse { $validator = Validator::make(request()->all(), [ 'occurrencies' => ['required', new ArrayInput], 'occurrencies.*.id' => ['required', 'exists:occurrencies,id'], 'occurrencies.*.finished' => ['required', new BooleanInput], 'tank_completed' => ['required', new BooleanInput], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->bdtService->finish($bdt)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings