File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/ScaleController.php
Back
<?php namespace App\Http\Controllers; use App\Models\Scale; use App\Rules\ArrayInput; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use App\Http\Requests\ScaleRequest; use App\Http\Services\ScaleService; use App\Classes\BaseServiceResponse; use Illuminate\Support\Facades\Validator; use App\Http\Requests\WarningScaleRequest; class ScaleController extends Controller { private ScaleService $scaleService; public function __construct() { $this->scaleService = new ScaleService(); $this->middleware('auth.permissions:gestao-de-ocorrencias'); } /** * @OA\Get( * path="/api/scale", * summary="Lista todos os escalas já criados", * description="Lista todos os escalas já criados", * operationId="GetAllScales", * security={{"bearerAuth":{}}}, * tags={"scales"}, * @OA\Parameter( * name="page", * in="query", * description="Get items by page", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="warning", * in="query", * description="Escala de sobraviso: 1 ou 0", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="month", * in="query", * description="Mês da escala: 1 a 12", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="year", * in="query", * description="Ano da escala: YYYY", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="department_id", * in="query", * description="ID do departamento da escala", * required=false, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="finished", * in="query", * description="Escala finalizada", * 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->scaleService->index($request)); } /** * @OA\Post( * path="/api/scale", * summary="Adiciona um novo escala", * description="Adiciona um novo escala", * operationId="AddNewScale", * security={{"bearerAuth":{}}}, * tags={"scales"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"month", "year", "department_id"}, * @OA\Property( * property="warning", * type="boolean", * example="false", * description="É uma escala de sobreaviso? O padrão é false." * ), * @OA\Property( * property="month", * type="string", * example="12", * description="Mês da escala" * ), * @OA\Property( * property="year", * type="string", * example="2023", * description="Ano da escala" * ), * @OA\Property( * property="department_id", * type="string", * description="ID do departamento ao qual essa escala pertence" * ), * @OA\Property( * property="members", * type="array", * description="Array com as informações dos membros da escala", * collectionFormat="multi", * @OA\Items( * @OA\Property( * property="user_id", * type="string", * description="Obrigatório." * ), * @OA\Property( * property="scale_function_id", * type="string", * description="Opcional. Enviar somente para escalas em equipe." * ), * @OA\Property( * property="scale_team_id", * type="string", * description="Opcional. Enviar somente para escalas em equipe." * ), * ), * ), * ) * ), * ), * @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(ScaleRequest $request): JsonResponse { return $this->response($this->scaleService->store($request)); } /** * @OA\Post( * path="/api/scale/warning", * summary="Adiciona uma nova escala de sobreaviso", * description="Adiciona uma nova escala de sobreaviso", * operationId="AddNewWarningScale", * security={{"bearerAuth":{}}}, * tags={"scales"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"month", "year", "department_id"}, * @OA\Property( * property="month", * type="string", * example="12", * description="Mês da escala" * ), * @OA\Property( * property="year", * type="string", * example="2023", * description="Ano da escala" * ), * @OA\Property( * property="department_id", * type="string", * description="ID do departamento ao qual essa escala pertence" * ), * @OA\Property( * property="agenda", * type="array", * description="Array com as informações dos membros da escala", * collectionFormat="multi", * @OA\Items( * @OA\Property( * property="user_id", * type="string", * description="Obrigatório." * ), * @OA\Property( * property="day", * type="string", * description="Dia da escala." * ), * @OA\Property( * property="scale_function_id", * type="string", * description="ID da função da escala. Opcional." * ), * ), * ), * ) * ), * ), * @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 storeWarning(WarningScaleRequest $request): JsonResponse { return $this->response($this->scaleService->storeWarning($request)); } /** * @OA\Put( * path="/api/scale/warning/{scale_id}", * summary="Altera os dados de uma escala de sobreaviso", * description="Altera os dados de uma escala de sobreaviso", * operationId="UpdateWarningScale", * security={{"bearerAuth":{}}}, * tags={"scales"}, * @OA\Parameter( * name="scale_id", * in="path", * required=true, * description="Scale ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"month", "year", "department_id"}, * @OA\Property( * property="month", * type="string", * example="12", * description="Mês da escala" * ), * @OA\Property( * property="year", * type="string", * example="2023", * description="Ano da escala" * ), * @OA\Property( * property="department_id", * type="string", * description="ID do departamento ao qual essa escala pertence" * ), * @OA\Property( * property="calendar", * type="array", * description="Array com as informações dos membros da escala", * collectionFormat="multi", * @OA\Items( * @OA\Property( * property="user_id", * type="string", * description="Obrigatório." * ), * @OA\Property( * property="day", * type="string", * description="Dia da escala." * ), * @OA\Property( * property="scale_function_id", * type="string", * description="ID da função da escala. Opcional." * ), * ), * ), * ) * ), * ), * @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 updateWarning(WarningScaleRequest $request, Scale $scale): JsonResponse { return $this->response($this->scaleService->updateWarning($request, $scale)); } /** * @OA\Get( * path="/api/scale/{scale_id}", * summary="Exibe os detalhes de um escala", * description="Exibe os detalhes de um escala", * operationId="GetScaleDetails", * security={{"bearerAuth":{}}}, * tags={"scales"}, * @OA\Parameter( * name="scale_id", * in="path", * required=true, * description="Scale 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(Scale $scale): JsonResponse { return $this->response($this->scaleService->show($scale)); } /** * @OA\Put( * path="/api/scale/{scale_id}", * summary="Altera os dados de um escala", * description="Altera os dados de um escala", * operationId="UpdateScale", * security={{"bearerAuth":{}}}, * tags={"scales"}, * @OA\Parameter( * name="scale_id", * in="path", * required=true, * description="Scale ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"month", "year", "department_id"}, * @OA\Property( * property="warning", * type="boolean", * example="false", * description="É uma escala de sobreaviso? O padrão é false." * ), * @OA\Property( * property="month", * type="string", * example="12", * description="Mês da escala" * ), * @OA\Property( * property="year", * type="string", * example="2023", * description="Ano da escala" * ), * @OA\Property( * property="department_id", * type="string", * description="ID do departamento ao qual essa escala pertence" * ), * @OA\Property( * property="calendar", * type="array", * description="Array occurrency requester info.", * @OA\Property(property="day", type="string"), * @OA\Items( * @OA\Property( * property="day", * type="string", * description="Dia da escala. Ex.: 1, 2, 30" * ), * @OA\Property( * property="team", * type="object", * @OA\Property(property="id", type="string"), * @OA\Property(property="name", type="string"), * ), * @OA\Property( * property="agents", * type="array", * @OA\Items( * @OA\Property( * property="function", * type="object", * @OA\Property(property="id", type="string"), * @OA\Property(property="name", type="string"), * ), * @OA\Property( * property="user", * type="object", * @OA\Property(property="id", type="string"), * @OA\Property(property="name", type="string"), * @OA\Property(property="document", type="string"), * @OA\Property(property="registration", 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(ScaleRequest $request, Scale $scale): JsonResponse { return $this->response($this->scaleService->update($request, $scale)); } /** * @OA\Post( * path="/api/scale/destroy-many", * summary="Exclui múltiplos escalas", * description="Exclui múltiplos escalas", * operationId="DeleteManyScales", * security={{"bearerAuth":{}}}, * tags={"scales"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"scales"}, * @OA\Property( * property="scales", * type="array", * description="Ids dos escalas para excluir", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"scales"}, * @OA\Property( * property="scales", * type="array", * description="Ids dos escalas para excluir", * 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(), [ 'scales' => ['required', new ArrayInput()], 'scales.*' => ['exists:scales,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->scaleService->destroyMany($request)); } /** * @OA\Post( * path="/api/scale/finish/{scale_id}", * summary="Finaliza uma escala.", * description="Finaliza uma escala.", * operationId="FinishScale", * security={{"bearerAuth":{}}}, * tags={"scales"}, * @OA\Parameter( * name="scale_id", * in="path", * required=true, * description="Scale 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="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(Scale $scale): JsonResponse { return $this->response($this->scaleService->finish($scale)); } /** * @OA\Get( * path="/api/scale/suggest-warning/{scale_id}", * summary="Sugere a escala de sobreaviso", * description="Sugere a escala de sobreaviso", * operationId="SuggestWarningScale", * security={{"bearerAuth":{}}}, * tags={"scales"}, * @OA\Parameter( * name="scale_id", * in="path", * required=true, * description="Scale 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 suggestWarningScale(Scale $scale): JsonResponse { return $this->response($this->scaleService->suggestWarningScale($scale)); } /** * @OA\Get( * path="/api/scale/my-agenda", * summary="Lista os dias de escala do usuário autenticado no mês e ano enviados.", * description="Lista os dias de escala do usuário autenticado no mês e ano enviados.", * operationId="GetUserAgenda", * security={{"bearerAuth":{}}}, * tags={"scales"}, * @OA\Parameter( * name="month", * in="query", * description="Mês da escala", * required=true, * @OA\Schema(type="string") * ), * @OA\Parameter( * name="year", * in="query", * description="Ano da escala", * required=true, * @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 myAgenda(Request $request): JsonResponse { $validator = Validator::make($request->all(), [ 'month' => ['required'], 'year' => ['required'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->scaleService->myAgenda($request)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings