File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/ScheduleController.php
Back
<?php namespace App\Http\Controllers; use App\Models\Schedule; use App\Rules\ArrayInput; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use App\Classes\BaseServiceResponse; use App\Http\Requests\ScheduleRequest; use App\Http\Services\ScheduleService; use Illuminate\Support\Facades\Validator; class ScheduleController extends Controller { private ScheduleService $scheduleService; public function __construct() { $this->scheduleService = new ScheduleService(); // $this->middleware('auth.permissions:gestao-de-formularios'); } /** * @OA\Get( * path="/api/schedule", * summary="Lista todos os itens", * description="Lista todos os itens", * operationId="GetAllSchedules", * security={{"bearerAuth":{}}}, * tags={"schedules"}, * @OA\Parameter( * name="page", * in="query", * description="Página", * 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->scheduleService->index($request)); } /** * @OA\Post( * path="/api/schedule", * summary="Adiciona um novo registro", * description="Adiciona um novo registro", * operationId="AddNewSchedule", * security={{"bearerAuth":{}}}, * tags={"schedules"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"type", "date", "exit_time", "driver_id", "transportation_id", "agents"}, * @OA\Property( * property="type", * type="string", * example="PADRÃO", * description="Tipo da programação: PADRÃO, EXTRA" * ), * @OA\Property( * property="date", * type="date", * example="2024-01-01", * description="Dia da programação" * ), * @OA\Property( * property="exit_time", * type="time", * example="14:00", * description="Hora de saída" * ), * @OA\Property( * property="driver_id", * type="string", * description="ID do usuário que será o motorista" * ), * @OA\Property( * property="note", * type="string", * description="Observação" * ), * @OA\Property( * property="emergency", * type="boolean", * description="Define se a programação é uma emergencia" * ), * @OA\Property( * property="transportation_id", * type="string", * description="ID do meio de transporte que será utilizado na programação" * ), * @OA\Property( * property="agents", * type="array", * description="Array com os agentes da escala", * collectionFormat="multi", * @OA\Items( * @OA\Property( * property="id", * type="string", * description="Obrigatório." * ), * @OA\Property( * property="type", * type="string", * description="Obrigatório. (EXTERNO, INTERNO)" * ), * ), * ), * @OA\Property( * property="occurrencies", * type="array", * description="IDS das ocorrências vinculadas a essa programação. Enviar somente se o tipo for PADRÃO.", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="name", * type="string", * description="Nome da programação. Enviar somente se o tipo for EXTRA." * ), * ) * ), * ), * @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(ScheduleRequest $request): JsonResponse { return $this->response($this->scheduleService->store($request)); } /** * @OA\Get( * path="/api/schedule/{schedule_id}", * summary="Traz os detalhes", * description="Traz os detalhes", * operationId="GetScheduleDetails", * security={{"bearerAuth":{}}}, * tags={"schedules"}, * @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(Schedule $schedule): JsonResponse { return $this->response($this->scheduleService->show($schedule)); } /** * @OA\Put( * path="/api/schedule/{schedule_id}", * summary="Altera os dados", * description="Altera os dados", * operationId="UpdateSchedule", * security={{"bearerAuth":{}}}, * tags={"schedules"}, * @OA\Parameter( * name="schedule_id", * in="path", * required=true, * description="ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"type", "date", "exit_time", "driver_id", "transportation_id", "agents"}, * @OA\Property( * property="type", * type="string", * example="PADRÃO", * description="Tipo da programação: PADRÃO, EXTRA" * ), * @OA\Property( * property="date", * type="date", * example="2024-01-01", * description="Dia da programação" * ), * @OA\Property( * property="exit_time", * type="time", * example="14:00", * description="Hora de saída" * ), * @OA\Property( * property="driver_id", * type="string", * description="ID do usuário que será o motorista" * ), * @OA\Property( * property="note", * type="string", * description="Observação" * ), * @OA\Property( * property="emergency", * type="boolean", * description="Define se a programação é uma emergencia" * ), * @OA\Property( * property="transportation_id", * type="string", * description="ID do meio de transporte que será utilizado na programação" * ), * @OA\Property( * property="agents", * type="array", * description="IDS dos agentes que participarão da programação", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="occurrencies", * type="array", * description="IDS das ocorrências vinculadas a essa programação. Enviar somente se o tipo for PADRÃO.", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * @OA\Property( * property="name", * type="string", * description="Nome da programação. Enviar somente se o tipo for EXTRA." * ), * ) * ), * ), * @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(ScheduleRequest $request, Schedule $schedule): JsonResponse { return $this->response($this->scheduleService->update($request, $schedule)); } /** * @OA\Delete( * path="/api/schedule/{schedule_id}", * summary="Exclui um item", * description="Exclui um item", * operationId="DeleteSchedule", * security={{"bearerAuth":{}}}, * tags={"schedules"}, * @OA\Parameter( * name="schedule_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(Schedule $schedule): JsonResponse { return $this->response($this->scheduleService->destroy($schedule)); } /** * @OA\Post( * path="/api/schedule/destroy-many", * summary="Exclui múltiplos items", * description="Exclui múltiplos items", * operationId="DeleteManySchedules", * security={{"bearerAuth":{}}}, * tags={"schedules"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"schedules"}, * @OA\Property( * property="schedules", * 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(), [ 'schedules' => ['required', new ArrayInput()], 'schedules.*' => ['exists:schedules,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->scheduleService->destroyMany($request)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings