feat(funcionario): adicionar módulo de gerenciamento de funcionários com rotas e controle de API
This commit is contained in:
73
app/Module/Funcionario/bootstrap.php
Normal file
73
app/Module/Funcionario/bootstrap.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace Workbloom\Module\Funcionario;
|
||||
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use AxiumPHP\Core\Router;
|
||||
|
||||
// Caminho do manifest.json
|
||||
$manifestPath = realpath(path: __DIR__ . "/manifest.json");
|
||||
|
||||
if (!$manifestPath || !file_exists(filename: $manifestPath)) {
|
||||
throw new Exception(message: "Arquivo 'manifest.json' não encontrado.");
|
||||
}
|
||||
|
||||
// Lê e decodifica
|
||||
$manifest = json_decode(json: file_get_contents(filename: $manifestPath), associative: true);
|
||||
|
||||
// Verifica estrutura
|
||||
if (!isset($manifest['apis']) || !is_array(value: $manifest['apis'])) {
|
||||
throw new Exception(message: "Estrutura de 'apis' inválida no manifest.");
|
||||
}
|
||||
|
||||
$now = (new DateTime())->format(format: 'Y-m-d');
|
||||
$newApis = [];
|
||||
$updated = false;
|
||||
|
||||
// Checa se tem versão esperando que começa hoje
|
||||
foreach ($manifest['apis'] as $api) {
|
||||
if ($api['status'] === 'planned' && $api['start_date'] === $now) {
|
||||
// Promote a nova
|
||||
$api['status'] = 'active';
|
||||
$newApis[] = $api;
|
||||
$updated = true;
|
||||
} elseif ($api['status'] === 'active' && $api['start_date'] !== $now) {
|
||||
// Ignora versão antiga ativa
|
||||
continue;
|
||||
} else {
|
||||
$newApis[] = $api;
|
||||
}
|
||||
}
|
||||
|
||||
// Atualiza manifest se tiver mudança
|
||||
if ($updated) {
|
||||
$manifest['apis'] = $newApis;
|
||||
file_put_contents(filename: $manifestPath, data: json_encode(value: $manifest, flags: JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
// Carrega a versão ativa
|
||||
$loaded = false;
|
||||
foreach ($manifest['apis'] as $api) {
|
||||
$startDate = new DateTime(datetime: $api['start_date']);
|
||||
if ($api['status'] === 'active' && $startDate <= new DateTime()) {
|
||||
$routeFile = MODULE_PATH . "/{$manifest['dirName']}/{$api['version']}/Routes/Routes.php";
|
||||
if (file_exists(filename: $routeFile)) {
|
||||
Router::group(
|
||||
prefix: "/{$manifest['slug']}",
|
||||
callback: function() use ($routeFile) {
|
||||
require_once realpath(path: $routeFile);
|
||||
},
|
||||
middlewares: []
|
||||
);
|
||||
$loaded = true;
|
||||
break;
|
||||
} else {
|
||||
throw new Exception(message: "Arquivo de rotas não encontrado para a versão '{$api['version']}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verifica se carregou
|
||||
if (!$loaded) {
|
||||
throw new Exception(message: "Nenhuma versão ativa da API foi carregada.");
|
||||
}
|
||||
16
app/Module/Funcionario/manifest.json
Normal file
16
app/Module/Funcionario/manifest.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "Funcionários",
|
||||
"dirName": "Funcionario",
|
||||
"slug": "funcionario",
|
||||
"description": "Gerencia dados e operações relacionadas aos funcionários.",
|
||||
"uuid": "019a0bfa-fc2f-7955-94d3-5f5273f07b3b",
|
||||
"version": "1.0",
|
||||
"dependencies": [],
|
||||
"apis": [
|
||||
{
|
||||
"version": "v0",
|
||||
"status": "active",
|
||||
"start_date": "2025-10-22"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace Workbloom\Module\Funcionario\v0\Controllers;
|
||||
|
||||
use AxiumPHP\Helpers\RequestHelper;
|
||||
|
||||
class FuncionarioController {
|
||||
public function listFuncionarios() {
|
||||
// Resposta JSON
|
||||
RequestHelper::sendJsonResponse(
|
||||
response_code: 200,
|
||||
status: 'success',
|
||||
message: 'Lista de funcionários obtida com sucesso',
|
||||
output: []
|
||||
);
|
||||
}
|
||||
}
|
||||
33
app/Module/Funcionario/v0/Routes/FuncionarioRoutes.php
Normal file
33
app/Module/Funcionario/v0/Routes/FuncionarioRoutes.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
use AxiumPHP\Core\Router;
|
||||
use Workbloom\Module\Funcionario\v0\Controllers\FuncionarioController;
|
||||
|
||||
// Listagem de funcionários
|
||||
Router::GET(
|
||||
uri: '/',
|
||||
handler: [FuncionarioController::class, 'listFuncionarios']
|
||||
);
|
||||
|
||||
// Registro de novo funcionário
|
||||
Router::POST(
|
||||
uri: '/',
|
||||
handler: [FuncionarioController::class, 'createFuncionario']
|
||||
);
|
||||
|
||||
// Detalhes de um funcionário
|
||||
Router::GET(
|
||||
uri: '/{uuid}',
|
||||
handler: [FuncionarioController::class, 'getFuncionario']
|
||||
);
|
||||
|
||||
// Atualização de um funcionário
|
||||
Router::PATCH(
|
||||
uri: '/{uuid}',
|
||||
handler: [FuncionarioController::class, 'updateFuncionario']
|
||||
);
|
||||
|
||||
// Remoção de um funcionário
|
||||
Router::DELETE(
|
||||
uri: '/{uuid}',
|
||||
handler: [FuncionarioController::class, 'deleteFuncionario']
|
||||
);
|
||||
2
app/Module/Funcionario/v0/Routes/Routes.php
Normal file
2
app/Module/Funcionario/v0/Routes/Routes.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
require_once 'FuncionarioRoutes.php';
|
||||
Reference in New Issue
Block a user