File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/ScaleTradesController.php
Back
<?php namespace App\Http\Controllers; use App\Models\Scale; use App\Models\ScaleDay; use App\Rules\ArrayInput; use App\Models\Department; use App\Rules\BooleanInput; use Illuminate\Http\Request; use App\Models\ScaleExtraHour; use App\Models\ScaleDayRequest; use Illuminate\Http\JsonResponse; use App\Http\Requests\ScaleRequest; use App\Classes\BaseServiceResponse; use App\Models\ScaleExtraHourRequest; use App\Models\ScaleWarningDayRequest; use App\Http\Services\ScaleTradesService; use Illuminate\Support\Facades\Validator; class ScaleTradesController extends Controller { private ScaleTradesService $scaleTradeService; public function __construct() { $this->scaleTradeService = new ScaleTradesService(); // $this->middleware('auth.permissions:gestao-de-ocorrencias'); } /** * @OA\Get( * path="/api/scale-trade/requested-days/{department_id}", * summary="Lista as solicitações de troca de escala.", * description="Lista as solicitações de troca de escala.", * operationId="GetAllScaleDayRequest", * security={{"bearerAuth":{}}}, * tags={"scales_trades"}, * @OA\Parameter( * name="department_id", * in="path", * required=true, * description="Department ID", * @OA\Schema(type="string") * ), * @OA\Parameter( * name="page", * in="query", * description="Get items by page", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="approved", * in="query", * description="Atributo que define se a escala já foi aprovada pela chefia do departamento", * required=false, * @OA\Schema(type="boolean") * ), * @OA\Parameter( * name="approved_by_member", * in="query", * description="Atributo que define se a escala já foi aprovada pelo usuário que recebeu a solicitação de troca", * required=false, * @OA\Schema(type="boolean") * ), * @OA\Parameter( * name="current_user", * in="query", * description="Filtra as solicitações somente do usuário autenticado. Valor: 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 indexScaleDayRequest(Request $request, Department $department): JsonResponse { return $this->response($this->scaleTradeService->indexScaleDayRequest($request, $department)); } /** * @OA\Get( * path="/api/scale-trade/requested-extra-hours/{department_id}", * summary="Lista as solicitações de solicitação de hora extra.", * description="Lista as solicitações de solicitação de hora extra.", * operationId="GetAllScaleExtraHourRequest", * security={{"bearerAuth":{}}}, * tags={"scales_trades"}, * @OA\Parameter( * name="department_id", * in="path", * required=true, * description="Department ID", * @OA\Schema(type="string") * ), * @OA\Parameter( * name="page", * in="query", * description="Get items by page", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="approved", * in="query", * description="Atributo que define se a escala já foi aprovada pela chefia do departamento", * required=false, * @OA\Schema(type="boolean") * ), * @OA\Parameter( * name="current_user", * in="query", * description="Filtra as solicitações somente do usuário autenticado. Valor: 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 indexScaleExtraHourRequest(Request $request, Department $department): JsonResponse { return $this->response($this->scaleTradeService->indexScaleExtraHourRequest($request, $department)); } /** * @OA\Get( * path="/api/scale-trade/requested-warning-days/{department_id}", * summary="Lista as solicitações de troca de escala de sobreaviso.", * description="Lista as solicitações de troca de escala de sobreaviso.", * operationId="GetAllScaleWarningDayRequest", * security={{"bearerAuth":{}}}, * tags={"scales_trades"}, * @OA\Parameter( * name="department_id", * in="path", * required=true, * description="Department ID", * @OA\Schema(type="string") * ), * @OA\Parameter( * name="page", * in="query", * description="Get items by page", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="approved", * in="query", * description="Atributo que define se a escala já foi aprovada pela chefia do departamento", * required=false, * @OA\Schema(type="boolean") * ), * @OA\Parameter( * name="approved_by_member", * in="query", * description="Atributo que define se a escala já foi aprovada pelo usuário que recebeu a solicitação de troca", * required=false, * @OA\Schema(type="boolean") * ), * @OA\Parameter( * name="current_user", * in="query", * description="Filtra as solicitações somente do usuário autenticado. Valor: 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 indexScaleWarningDayRequest(Request $request, Department $department): JsonResponse { return $this->response($this->scaleTradeService->indexScaleWarningDayRequest($request, $department)); } /** * @OA\Post( * path="/api/scale-trade/request-extra-hour/{extra_hour_id}", * summary="Solicitar hora extra disponível", * description="Solicitar hora extra disponível", * operationId="RequestExtraHour", * security={{"bearerAuth":{}}}, * tags={"scales_trades"}, * @OA\Parameter( * name="extra_hour_id", * in="path", * required=true, * description="ID da hora extra em aberto", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * @OA\Property( * property="user_id", * type="string", * description="ID do usuário que está solicitando a hora extra para si." * ), * ) * ), * ), * @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 requestExtraHour(Request $request, ScaleExtraHour $extraHour): JsonResponse { $validator = Validator::make($request->all(), [ 'user_id' => ['required', 'max:255'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->scaleTradeService->requestExtraHour($request, $extraHour)); } /** * @OA\Post( * path="/api/scale-trade/accept-extra-hour/{extra_hour_request_id}", * summary="Aceitar solicitação de hora extra", * description="Aceitar solicitação de hora extra", * operationId="AcceptExtraHour", * security={{"bearerAuth":{}}}, * tags={"scales_trades"}, * @OA\Parameter( * name="extra_hour_request_id", * in="path", * required=true, * description="ID da hora extra para ser aceita", * @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="422", * description="Validation Error", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Validation Error."), * @OA\Property(property="errors", type="json", example="{}"), * ) * ), * ) */ public function acceptExtraHour(Request $request, ScaleExtraHourRequest $extraHourRequest): JsonResponse { // $validator = Validator::make($request->all(), [ // 'user_id' => ['required', 'max:255'], // ]); // if ($validator->fails()) { // return $this->response(new BaseServiceResponse( // JsonResponse::HTTP_UNPROCESSABLE_ENTITY, // $validator->errors()->toArray(), // __('general.validation_error') // )); // } return $this->response($this->scaleTradeService->acceptExtraHour($request, $extraHourRequest)); } /** * @OA\Post( * path="/api/scale-trade/request-warning-day/{scale_day_id}", * summary="Solicitar dia de sobreaviso", * description="Solicitar dia de sobreaviso", * operationId="RequestWarningDay", * security={{"bearerAuth":{}}}, * tags={"scales_trades"}, * @OA\Parameter( * name="scale_day_id", * in="path", * required=true, * description="ID do dia para troca de escala", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * @OA\Property( * property="scale_member_id", * type="string", * description="ID do agente que está atualmente de sobreaviso" * ), * @OA\Property( * property="requester_user_id", * type="string", * description="ID do dia do usuário que está solicitando o dia do sobreaviso" * ), * ) * ), * ), * @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="422", * description="Validation Error", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Validation Error."), * @OA\Property(property="errors", type="json", example="{}"), * ) * ), * ) */ public function requestWarningDay(Request $request, ScaleDay $scaleDay): JsonResponse { $validator = Validator::make($request->all(), [ 'scale_member_id' => ['required', 'exists:scale_members,id'], 'requester_user_id' => ['required', 'max:255'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->scaleTradeService->requestWarningDay($request, $scaleDay)); } /** * @OA\Post( * path="/api/scale-trade/accept-warning-day/{warning_request_id}", * summary="Aceitar dia de sobreaviso", * description="Aceitar dia de sobreaviso", * operationId="AcceptWarningDay", * security={{"bearerAuth":{}}}, * tags={"scales_trades"}, * @OA\Parameter( * name="warning_request_id", * in="path", * required=true, * description="ID da requisição da troca de sobreaviso", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * @OA\Property( * property="approved", * type="boolean", * description="Aprovação do ADM" * ), * @OA\Property( * property="approved_by_member", * type="boolean", * description="Aprovação do atual agente da escala" * ), * ) * ), * ), * @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="422", * description="Validation Error", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Validation Error."), * @OA\Property(property="errors", type="json", example="{}"), * ) * ), * ) */ public function acceptWarningDay(Request $request, ScaleWarningDayRequest $warningRequest): JsonResponse { $validator = Validator::make($request->all(), [ 'approved' => ['nullable', new BooleanInput()], 'approved_by_member' => ['nullable', new BooleanInput()], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->scaleTradeService->acceptWarningDay($request, $warningRequest)); } /** * @OA\Post( * path="/api/scale-trade/request-day", * summary="Solicitar troca de escala", * description="Solicitar troca de escala", * operationId="RequestDay", * security={{"bearerAuth":{}}}, * tags={"scales_trades"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * @OA\Property( * property="current_scale_day_id", * type="string", * description="Dia que será oferecido na troca" * ), * @OA\Property( * property="current_scale_member_id", * type="string", * description="Usuário atual que está solicitanto a troca" * ), * @OA\Property( * property="requested_scale_day_id", * type="string", * description="Dia que deseja a troca" * ), * @OA\Property( * property="requested_scale_member_id", * type="string", * description="Usuário do dia da troca desejada" * ), * ) * ), * ), * @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="422", * description="Validation Error", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Validation Error."), * @OA\Property(property="errors", type="json", example="{}"), * ) * ), * ) */ public function requestDay(Request $request): JsonResponse { $validator = Validator::make($request->all(), [ 'current_scale_day_id' => ['required', 'exists:scale_days,id'], 'current_scale_member_id' => ['required', 'exists:scale_members,id'], 'requested_scale_day_id' => ['required', 'exists:scale_days,id'], 'requested_scale_member_id' => ['required', 'exists:scale_members,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->scaleTradeService->requestDay($request)); } /** * @OA\Post( * path="/api/scale-trade/accept-day/{day_request_id}", * summary="Aceitar troca de escala", * description="Aceitar troca de escala", * operationId="AcceptDay", * security={{"bearerAuth":{}}}, * tags={"scales_trades"}, * @OA\Parameter( * name="day_request_id", * in="path", * required=true, * description="ID da requisição de troca de escala", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * @OA\Property( * property="approved", * type="boolean", * description="Aprovação do ADM" * ), * @OA\Property( * property="approved_by_member", * type="boolean", * description="Aprovação do atual agente da escala" * ), * ) * ), * ), * @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="422", * description="Validation Error", * @OA\JsonContent( * @OA\Property(property="message", type="string", example="Validation Error."), * @OA\Property(property="errors", type="json", example="{}"), * ) * ), * ) */ public function acceptDay(Request $request, ScaleDayRequest $dayRequest): JsonResponse { $validator = Validator::make($request->all(), [ 'approved' => ['nullable', new BooleanInput()], 'approved_by_member' => ['nullable', new BooleanInput()], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->scaleTradeService->acceptDay($request, $dayRequest)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings