File manager - Edit - /var/www/html/spdc/api/app/Http/Controllers/DepartmentController.php
Back
<?php namespace App\Http\Controllers; use App\Rules\ArrayInput; use App\Models\Department; use Illuminate\Http\Request; use Illuminate\Http\JsonResponse; use App\Classes\BaseServiceResponse; use App\Http\Requests\DepartmentRequest; use App\Http\Services\DepartmentService; use Illuminate\Support\Facades\Validator; use App\Http\Requests\StoreDepartmentRequest; use App\Http\Requests\StoreManyDepartmentRequest; use App\Http\Requests\UpdateDepartmentRequest; class DepartmentController extends Controller { private DepartmentService $departmentService; public function __construct() { $this->departmentService = new DepartmentService(); $this->middleware('auth.permissions:gestao-de-ocorrencias'); } /** * @OA\Get( * path="/api/department", * summary="Lista todos os departamentos já criados", * description="Lista todos os departamentos já criados", * operationId="GetAllDepartments", * security={{"bearerAuth":{}}}, * tags={"departments"}, * @OA\Parameter( * name="page", * in="query", * description="Get items by page", * 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(): JsonResponse { return $this->response($this->departmentService->index()); } /** * @OA\Post( * path="/api/department", * summary="Adiciona um novo departamento", * description="Adiciona um novo departamento", * operationId="AddNewDepartment", * security={{"bearerAuth":{}}}, * tags={"departments"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"name", "scale_type"}, * @OA\Property( * property="name", * type="string", * example="Departamento de Engenharia", * description="Nome do departamento" * ), * @OA\Property( * property="acronym", * type="string", * example="DE", * description="Sigla do departamento" * ), * @OA\Property( * property="scale_type", * type="string", * example="INTERNO", * description="Os tipos de escala podem ser: INDIVIDUAL, EQUIPE" * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"name", "scale_type"}, * @OA\Property( * property="name", * type="string", * example="Departamento de Engenharia", * description="Nome do departamento" * ), * @OA\Property( * property="acronym", * type="string", * example="DE", * description="Sigla do departamento" * ), * @OA\Property( * property="scale_type", * type="string", * example="INTERNO", * description="Os tipos de escala podem ser: INDIVIDUAL, 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(DepartmentRequest $request): JsonResponse { return $this->response($this->departmentService->store($request)); } public function storeMany(StoreManyDepartmentRequest $request) { $url = env('AUTH_SERVICE_URL'). '/' .$request->route()->uri(); $response = authServiceClient('post', $url, $request); return response($response->json(), $response->status()); } /** * @OA\Get( * path="/api/department/{department_id}", * summary="Exibe os detalhes de um departamento", * description="Exibe os detalhes de um departamento", * operationId="GetDepartmentDetails", * security={{"bearerAuth":{}}}, * tags={"departments"}, * @OA\Parameter( * name="department_id", * in="path", * required=true, * description="Department 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(Department $department): JsonResponse { return $this->response($this->departmentService->show($department)); } /** * @OA\Put( * path="/api/department/{department_id}", * summary="Altera os dados de um departamento", * description="Altera os dados de um departamento", * operationId="UpdateDepartment", * security={{"bearerAuth":{}}}, * tags={"departments"}, * @OA\Parameter( * name="department_id", * in="path", * required=true, * description="Department ID", * @OA\Schema(type="string") * ), * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"name", "scale_type"}, * @OA\Property( * property="name", * type="string", * example="Departamento de Engenharia", * description="Nome do departamento" * ), * @OA\Property( * property="acronym", * type="string", * example="DE", * description="Sigla do departamento" * ), * @OA\Property( * property="scale_type", * type="string", * example="INTERNO", * description="Os tipos de escala podem ser: INDIVIDUAL, EQUIPE" * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"name", "scale_type"}, * @OA\Property( * property="name", * type="string", * example="Departamento de Engenharia", * description="Nome do departamento" * ), * @OA\Property( * property="acronym", * type="string", * example="DE", * description="Sigla do departamento" * ), * @OA\Property( * property="scale_type", * type="string", * example="INTERNO", * description="Os tipos de escala podem ser: INDIVIDUAL, EQUIPE" * ), * ) * ), * ), * @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(DepartmentRequest $request, Department $department): JsonResponse { return $this->response($this->departmentService->update($request, $department)); } /** * @OA\Post( * path="/api/department/enable", * summary="Habilita múltiplos departamentos", * description="Habilita múltiplos departamentos", * operationId="EnableManyDepartments", * security={{"bearerAuth":{}}}, * tags={"departments"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"departments"}, * @OA\Property( * property="departments", * type="array", * description="IDs das departamentos que deverão ser habilitados", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"departments"}, * @OA\Property( * property="departments", * type="array", * description="IDs das departamentos que deverão ser habilitados", * 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 enable(Request $request): JsonResponse { $validator = Validator::make($request->all(), [ 'departments' => ['required', new ArrayInput(), 'min:1'], 'departments.*' => ['exists:departments,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->departmentService->enable($request)); } /** * @OA\Post( * path="/api/department/disable", * summary="Desabilita múltiplos departamentos", * description="Desabilita múltiplos departamentos", * operationId="DisableManyDepartments", * security={{"bearerAuth":{}}}, * tags={"departments"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"departments"}, * @OA\Property( * property="departments", * type="array", * description="IDs das departamentos que deverão ser desabilitados", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"departments"}, * @OA\Property( * property="departments", * type="array", * description="IDs das departamentos que deverão ser desabilitados", * 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 disable(Request $request): JsonResponse { $validator = Validator::make($request->all(), [ 'departments' => ['required', new ArrayInput(), 'min:1'], 'departments.*' => ['exists:departments,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->departmentService->disable($request)); } /** * @OA\Post( * path="/api/department/destroy-many", * summary="Exclui múltiplos departamentos", * description="Exclui múltiplos departamentos", * operationId="DeleteManyDepartments", * security={{"bearerAuth":{}}}, * tags={"departments"}, * @OA\RequestBody( * required=true, * @OA\MediaType( * mediaType="application/x-www-form-urlencoded", * @OA\Schema( * required={"departments"}, * @OA\Property( * property="departments", * type="array", * description="Ids dos departamentos para excluir", * collectionFormat="multi", * @OA\Items(type="string", format="id"), * ), * ) * ), * @OA\MediaType( * mediaType="application/json", * @OA\Schema( * required={"departments"}, * @OA\Property( * property="departments", * type="array", * description="Ids dos departamentos 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(), [ 'departments' => ['required', new ArrayInput()], 'departments.*' => ['exists:departments,id'], ]); if ($validator->fails()) { return $this->response(new BaseServiceResponse( JsonResponse::HTTP_UNPROCESSABLE_ENTITY, $validator->errors()->toArray(), __('general.validation_error') )); } return $this->response($this->departmentService->destroyMany($request)); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings