Skip to content

Commit

Permalink
🔨 #270 update controller
Browse files Browse the repository at this point in the history
  • Loading branch information
bjverde committed Sep 28, 2022
1 parent 131407b commit 0b62bce
Show file tree
Hide file tree
Showing 19 changed files with 287 additions and 81 deletions.
71 changes: 45 additions & 26 deletions appexemplo_v2.0/api/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,26 @@
* Download SysGen: https://github.com/bjverde/sysgen
* Download Formdin Framework: https://github.com/bjverde/formDin
*
* SysGen Version: 1.9.0-alpha
* FormDin Version: 4.7.5
* SysGen Version: 1.12.0
* FormDin Version: 4.19.0
*
* System appev2 created in: 2019-09-10 09:04:46
* System appev2 created in: 2022-09-28 00:42:11
*/
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteCollectorProxy as RouteCollectorProxy;
use Slim\Factory\AppFactory;

use api_controllers\Authentication;

use api_controllers\SysinfoAPI;
use api_controllers\SelfilhosmenuAPI;
use api_controllers\SelfilhosmenuqtdAPI;
use api_controllers\SelmenuqtdAPI;

use api_controllers\Authentication;

use api_controllers\Acesso_menuAPI;
use api_controllers\Acesso_perfilAPI;
use api_controllers\Acesso_perfil_menuAPI;
use api_controllers\Acesso_perfil_userAPI;
use api_controllers\Acesso_userAPI;
use api_controllers\Acesso_user_menuAPI;
use api_controllers\AutoridadeAPI;
use api_controllers\EnderecoAPI;
use api_controllers\MarcaAPI;
Expand All @@ -45,7 +42,9 @@
use api_controllers\UfAPI;
use api_controllers\Vw_acesso_user_menuAPI;
use api_controllers\Vw_pessoaAPI;
use api_controllers\Vw_pessoa_fisicaAPI;
use api_controllers\Vw_pessoa_marca_produtoAPI;
use api_controllers\Vw_regiao_municipioAPI;

/**
* Instantiate App
Expand All @@ -57,9 +56,9 @@
$app = AppFactory::create();

/**
* The routing middleware should be added earlier than the ErrorMiddleware
* Otherwise exceptions thrown from it will not be handled by the middleware
*/
* The routing middleware should be added earlier than the ErrorMiddleware
* Otherwise exceptions thrown from it will not be handled by the middleware
*/
$app->addRoutingMiddleware();

/**
Expand All @@ -81,8 +80,6 @@
$urlChamada = explode('api/', $urlChamada);
$urlChamada = $urlChamada[0];
$urlChamada = $urlChamada.'api/';


// Define app routes
$app->get($urlChamada, function (Request $request, Response $response, $args) use ($app) {
$url = \ServerHelper::getFullServerName();
Expand All @@ -96,26 +93,58 @@
$routeArray['url'] = $url.$route->getPattern();
$routesArray[] = $routeArray;
}

$msg = array( 'info'=> SysinfoAPI::info()
, 'endpoints'=>array( 'qtd'=> \CountHelper::count($routesArray)
,'result'=>$routesArray
)
);

$msgJson = json_encode($msg);
$response->getBody()->write( $msgJson );
return $response->withHeader('Content-Type', 'application/json');
$result = $response->withHeader('Content-Type', 'application/json');
return $result;
});

//Grupo acesso_menu exige autenticacao
//Entrar na classe Authentication para pegar usuário e senha
//Descomentar as linhas que precisam ser autenticadas
$controllerAuthentication = new Authentication($urlChamada);
//$controllerAuthentication->addPath('selfilhosmenu');
//$controllerAuthentication->addPath('selfilhosmenuqtd');
$controllerAuthentication->addPath('acesso_menu');
//$controllerAuthentication->addPath('acesso_perfil');
//$controllerAuthentication->addPath('acesso_perfil_menu');
//$controllerAuthentication->addPath('acesso_perfil_user');
//$controllerAuthentication->addPath('acesso_user');
//$controllerAuthentication->addPath('autoridade');
//$controllerAuthentication->addPath('endereco');
//$controllerAuthentication->addPath('marca');
//$controllerAuthentication->addPath('meta_tipo');
//$controllerAuthentication->addPath('municipio');
//$controllerAuthentication->addPath('natureza_juridica');
//$controllerAuthentication->addPath('pedido');
//$controllerAuthentication->addPath('pedido_item');
//$controllerAuthentication->addPath('pessoa');
//$controllerAuthentication->addPath('pessoa_fisica');
//$controllerAuthentication->addPath('pessoa_juridica');
//$controllerAuthentication->addPath('produto');
//$controllerAuthentication->addPath('regiao');
//$controllerAuthentication->addPath('telefone');
//$controllerAuthentication->addPath('tipo');
//$controllerAuthentication->addPath('uf');
//$controllerAuthentication->addPath('vw_acesso_user_menu');
//$controllerAuthentication->addPath('vw_pessoa');
//$controllerAuthentication->addPath('vw_pessoa_fisica');
//$controllerAuthentication->addPath('vw_pessoa_marca_produto');
//$controllerAuthentication->addPath('vw_regiao_municipio');
$app->add($controllerAuthentication->basicAuth());

$app->get($urlChamada.'sysinfo', SysinfoAPI::class . ':getInfo');
$app->get($urlChamada.'auth', SysinfoAPI::class . ':getInfo');



//--------------------------------------------------------------------
// VIEW: selFilhosMenu
//--------------------------------------------------------------------
Expand All @@ -126,7 +155,7 @@

});

/*

//--------------------------------------------------------------------
// VIEW: selFilhosMenuQtd
//--------------------------------------------------------------------
Expand All @@ -138,16 +167,6 @@
});


//--------------------------------------------------------------------
// VIEW: selMenuQtd
//--------------------------------------------------------------------
$urlGrupo = $urlChamada.'selmenuqtd';
$app->group($urlGrupo, function(RouteCollectorProxy $group) use ($app,$urlGrupo) {
$app->get('', SelmenuqtdAPI::class . ':selectAll');
$app->get('/{id:[0-9]+}', SelmenuqtdAPI::class . ':selectById');
});
*/

//--------------------------------------------------------------------
// TABLE: acesso_menu
//--------------------------------------------------------------------
Expand Down
19 changes: 15 additions & 4 deletions appexemplo_v2.0/controllers/Acesso_user.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* Download SysGen: https://github.com/bjverde/sysgen
* Download Formdin Framework: https://github.com/bjverde/formDin
*
* SysGen Version: 1.9.0-alpha
* FormDin Version: 4.7.5
* SysGen Version: 1.12.0
* FormDin Version: 4.19.0
*
* System appev2 created in: 2019-09-10 09:04:46
* System appev2 created in: 2022-09-28 00:42:12
*/
class Acesso_user
{
Expand Down Expand Up @@ -37,7 +37,7 @@ public function selectByLogin( $login )
{
$result = $this->dao->selectByLogin($login);
return $result;
}
}
//--------------------------------------------------------------------------------
public function selectCount( $where=null )
{
Expand All @@ -57,10 +57,20 @@ public function selectAll( $orderBy=null, $where=null )
return $result;
}
//--------------------------------------------------------------------------------
private function validatePkNotExist( $id )
{
$where=array('IDUSER'=>$id);
$qtd = $this->selectCount($where);
if( empty($qtd) ){
throw new DomainException(Message::GENERIC_ID_NOT_EXIST);
}
}
//--------------------------------------------------------------------------------
public function save( Acesso_userVO $objVo )
{
$result = null;
if( $objVo->getIduser() ) {
$this->validatePkNotExist( $objVo->getIduser() );
$result = $this->dao->update( $objVo );
} else {
$result = $this->dao->insert( $objVo );
Expand All @@ -70,6 +80,7 @@ public function save( Acesso_userVO $objVo )
//--------------------------------------------------------------------------------
public function delete( $id )
{
$this->validatePkNotExist( $id );
$result = $this->dao->delete( $id );
return $result;
}
Expand Down
17 changes: 14 additions & 3 deletions appexemplo_v2.0/controllers/Autoridade.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* Download SysGen: https://github.com/bjverde/sysgen
* Download Formdin Framework: https://github.com/bjverde/formDin
*
* SysGen Version: 1.9.0-alpha
* FormDin Version: 4.7.5
* SysGen Version: 1.12.0
* FormDin Version: 4.19.0
*
* System appev2 created in: 2019-09-10 09:04:46
* System appev2 created in: 2022-09-28 00:42:12
*/
class Autoridade
{
Expand Down Expand Up @@ -67,11 +67,21 @@ public function validar( AutoridadeVO $objVo) {
}
}
//--------------------------------------------------------------------------------
private function validatePkNotExist( $id )
{
$where=array('IDAUTORIDADE'=>$id);
$qtd = $this->selectCount($where);
if( empty($qtd) ){
throw new DomainException(Message::GENERIC_ID_NOT_EXIST);
}
}
//--------------------------------------------------------------------------------
public function save( AutoridadeVO $objVo )
{
$result = null;
$this->validar($objVo);
if( $objVo->getIdautoridade() ) {
$this->validatePkNotExist( $objVo->getIdautoridade() );
$result = $this->dao->update( $objVo );
} else {
$result = $this->dao->insert( $objVo );
Expand All @@ -81,6 +91,7 @@ public function save( AutoridadeVO $objVo )
//--------------------------------------------------------------------------------
public function delete( $id )
{
$this->validatePkNotExist( $id );
$result = $this->dao->delete( $id );
return $result;
}
Expand Down
17 changes: 14 additions & 3 deletions appexemplo_v2.0/controllers/Endereco.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* Download SysGen: https://github.com/bjverde/sysgen
* Download Formdin Framework: https://github.com/bjverde/formDin
*
* SysGen Version: 1.9.0-alpha
* FormDin Version: 4.7.5
* SysGen Version: 1.12.0
* FormDin Version: 4.19.0
*
* System appev2 created in: 2019-09-10 09:04:46
* System appev2 created in: 2022-09-28 00:42:12
*/
class Endereco
{
Expand Down Expand Up @@ -52,10 +52,20 @@ public function selectAll( $orderBy=null, $where=null )
return $result;
}
//--------------------------------------------------------------------------------
private function validatePkNotExist( $id )
{
$where=array('IDENDERECO'=>$id);
$qtd = $this->selectCount($where);
if( empty($qtd) ){
throw new DomainException(Message::GENERIC_ID_NOT_EXIST);
}
}
//--------------------------------------------------------------------------------
public function save( EnderecoVO $objVo )
{
$result = null;
if( $objVo->getIdendereco() ) {
$this->validatePkNotExist( $objVo->getIdendereco() );
$result = $this->dao->update( $objVo );
} else {
$result = $this->dao->insert( $objVo );
Expand All @@ -65,6 +75,7 @@ public function save( EnderecoVO $objVo )
//--------------------------------------------------------------------------------
public function delete( $id )
{
$this->validatePkNotExist( $id );
$result = $this->dao->delete( $id );
return $result;
}
Expand Down
17 changes: 14 additions & 3 deletions appexemplo_v2.0/controllers/Marca.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* Download SysGen: https://github.com/bjverde/sysgen
* Download Formdin Framework: https://github.com/bjverde/formDin
*
* SysGen Version: 1.9.0-alpha
* FormDin Version: 4.7.5
* SysGen Version: 1.12.0
* FormDin Version: 4.19.0
*
* System appev2 created in: 2019-09-10 09:04:46
* System appev2 created in: 2022-09-28 00:42:12
*/
class Marca
{
Expand Down Expand Up @@ -52,10 +52,20 @@ public function selectAll( $orderBy=null, $where=null )
return $result;
}
//--------------------------------------------------------------------------------
private function validatePkNotExist( $id )
{
$where=array('IDMARCA'=>$id);
$qtd = $this->selectCount($where);
if( empty($qtd) ){
throw new DomainException(Message::GENERIC_ID_NOT_EXIST);
}
}
//--------------------------------------------------------------------------------
public function save( MarcaVO $objVo )
{
$result = null;
if( $objVo->getIdmarca() ) {
$this->validatePkNotExist( $objVo->getIdmarca() );
$result = $this->dao->update( $objVo );
} else {
$result = $this->dao->insert( $objVo );
Expand All @@ -65,6 +75,7 @@ public function save( MarcaVO $objVo )
//--------------------------------------------------------------------------------
public function delete( $id )
{
$this->validatePkNotExist( $id );
$result = $this->dao->delete( $id );
return $result;
}
Expand Down
2 changes: 2 additions & 0 deletions appexemplo_v2.0/controllers/Message.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Message {
const GENERIC_DELETE = 'Registro excluído com sucesso!';
const GENERIC_EXEC = 'Ação executada com sucesso!';

const GENERIC_ID_NOT_EXIST = 'Registro não existe';

const TYPE_NOT_INT = 'Tipo não númerico! ';

const ERROR = 'ERRO no sistema !';
Expand Down
17 changes: 14 additions & 3 deletions appexemplo_v2.0/controllers/Meta_tipo.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* Download SysGen: https://github.com/bjverde/sysgen
* Download Formdin Framework: https://github.com/bjverde/formDin
*
* SysGen Version: 1.9.0-alpha
* FormDin Version: 4.7.5
* SysGen Version: 1.12.0
* FormDin Version: 4.19.0
*
* System appev2 created in: 2019-09-10 09:04:46
* System appev2 created in: 2022-09-28 00:42:12
*/
class Meta_tipo
{
Expand Down Expand Up @@ -56,10 +56,20 @@ public function selectAll( $orderBy=null, $where=null )
return $result;
}
//--------------------------------------------------------------------------------
private function validatePkNotExist( $id )
{
$where=array('IDMETATIPO'=>$id);
$qtd = $this->selectCount($where);
if( empty($qtd) ){
throw new DomainException(Message::GENERIC_ID_NOT_EXIST);
}
}
//--------------------------------------------------------------------------------
public function save( Meta_tipoVO $objVo )
{
$result = null;
if( $objVo->getIdmetatipo() ) {
$this->validatePkNotExist( $objVo->getIdmetatipo() );
$result = $this->dao->update( $objVo );
} else {
$result = $this->dao->insert( $objVo );
Expand All @@ -69,6 +79,7 @@ public function save( Meta_tipoVO $objVo )
//--------------------------------------------------------------------------------
public function delete( $id )
{
$this->validatePkNotExist( $id );
$result = $this->dao->delete( $id );
return $result;
}
Expand Down
Loading

0 comments on commit 0b62bce

Please sign in to comment.