File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/TransportationController.php
Back
<?php namespace App\Http\Controllers; use App\Rules\ArrayInput; use Illuminate\Http\Request; use App\Models\Transportation; use Illuminate\Http\JsonResponse; use App\Classes\BaseServiceResponse; use Illuminate\Support\Facades\Validator; use App\Http\Requests\TransportationRequest; use App\Http\Services\TransportationService; use App\Http\Requests\StoreTransportationRequest; use App\Http\Requests\UpdateTransportationRequest; class TransportationController extends Controller { private TransportationService $transportationService; public function __construct() { $this->transportationService = new TransportationService(); // $this->middleware('auth.permissions:gestao-de-formularios'); } /** * @OA\Get( * path="/api/transportation", * summary="Lista todos os itens", * description="Lista todos os itens", * operationId="GetAllTransportations", * security={{"bearerAuth":{}}}, * tags={"transportations"}, * @OA\Parameter( * name="page", * in="query", * description="Página", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="category", * in="query", * description="Categoria: AQUÁTICO ou TERRESTRE", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="search_term", * in="query", * description="Termo para pesquisa em MODEL", * 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->transportationService->index($request)); } /** * @OA\Post( * path="/api/transportation", * summary="Adiciona um novo registro", * description="Adiciona um novo registro", * operationId="AddNewTransportation", * security={{"bearerAuth":{}}}, * tags={"transportations"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"model", "autonomy", "initial_odometer", "category"}, * @OA\Property( * property="model", * type="string", * example="Sandero", * description="Modelo" * ), * @OA\Property( * property="autonomy", * type="number", * example="54.5", * description="Autonomia" * ), * @OA\Property( * property="initial_odometer", * type="number", * example="5", * description="Odômetro atual" * ), * @OA\Property( * property="category", * type="string", * example="TERRESTRE", * description="Categoria: TERRESTRE ou AQUÁTICO" * ), * @OA\Property( * property="identification_code", * type="string", * example="AB4565", * description="Placa" * ), * @OA\Property( * property="vehicle_type_id", * type="string", * example="Vehicle Type ID", * description="Tipo do veículo" * ), * @OA\Property( * property="engine", * type="string", * example="Motor", * description="Motor" * ), * ) * ), * ), * @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(TransportationRequest $request): JsonResponse { return $this->response($this->transportationService->store($request)); } /** * @OA\Get( * path="/api/transportation/{transportation_id}", * summary="Traz os detalhes", * description="Traz os detalhes", * operationId="GetTransportationDetails", * security={{"bearerAuth":{}}}, * tags={"transportations"}, * @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(Transportation $transportation): JsonResponse { return $this->response($this->transportationService->show($transportation)); } /** * @OA\Put( * path="/api/transportation/{transportation_id}", * summary="Altera os dados", * description="Altera os dados", * operationId="UpdateTransportation", * security={{"bearerAuth":{}}}, * tags={"transportations"}, * @OA\Parameter( * name="transportation_id", * in="path", * required=true, * description="ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"model", "autonomy", "initial_odometer", "category"}, * @OA\Property( * property="model", * type="string", * example="Sandero", * description="Modelo" * ), * @OA\Property( * property="autonomy", * type="number", * example="54.5", * description="Autonomia" * ), * @OA\Property( * property="initial_odometer", * type="number", * example="5", * description="Odômetro atual" * ), * @OA\Property( * property="category", * type="string", * example="TERRESTRE", * description="Categoria: TERRESTRE ou AQUÁTICO" * ), * @OA\Property( * property="identification_code", * type="string", * example="AB4565", * description="Placa" * ), * @OA\Property( * property="vehicle_type_id", * type="string", * example="Vehicle Type ID", * description="Tipo do veículo" * ), * @OA\Property( * property="engine", * type="string", * example="Motor", * description="Motor" * ), * ) * ), * ), * @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(TransportationRequest $request, Transportation $transportation): JsonResponse { return $this->response($this->transportationService->update($request, $transportation)); } /** * @OA\Post( * path="/api/transportation/update-status/{transportation_id}", * summary="Altera o status de uma viatura", * description="Altera o status de uma viatura", * operationId="UpdateTransportationStatus", * security={{"bearerAuth":{}}}, * tags={"transportations"}, * @OA\Parameter( * name="transportation_id", * in="path", * required=true, * description="ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"status"}, * @OA\Property( * property="status", * type="string", * example="Operante", * description="Status do veículo" * ), * @OA\Property( * property="note", * type="string", * example="Observação sobre o status", * description="Observacação" * ), * ) * ), * ), * @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 updateStatus(Request $request, Transportation $transportation): JsonResponse { $validator = Validator::make($request->all(), [ 'status' => ['required'], 'note' => ['nullable'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->transportationService->updateStatus($request, $transportation)); } /** * @OA\Delete( * path="/api/transportation/{transportation_id}", * summary="Exclui um item", * description="Exclui um item", * operationId="DeleteTransportation", * security={{"bearerAuth":{}}}, * tags={"transportations"}, * @OA\Parameter( * name="transportation_id", * in="path", * required=true, * description="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(Transportation $transportation): JsonResponse { return $this->response($this->transportationService->destroy($transportation)); } /** * @OA\Post( * path="/api/transportation/destroy-many", * summary="Exclui múltiplos items", * description="Exclui múltiplos items", * operationId="DeleteManyTransportations", * security={{"bearerAuth":{}}}, * tags={"transportations"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"transportations"}, * @OA\Property( * property="transportations", * type="array", * description="IDS para exclusão", * 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(), [ 'transportations' => ['required', new ArrayInput()], 'transportations.*' => ['exists:transportations,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->transportationService->destroyMany($request)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings