Skip to content

Commit

Permalink
Adicionado os handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Xavier committed Sep 5, 2019
1 parent c592ce5 commit 22a02aa
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"zendframework/zend-expressive-helpers": "^5.0",
"zendframework/zend-expressive-zendviewrenderer": "^2.0",
"zendframework/zend-hydrator": "^3.0",
"zendframework/zend-json": "^3.1",
"zendframework/zend-servicemanager": "^3.3",
"zendframework/zend-stdlib": "^3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/App/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public function getDependencies() : array
'factories' => [
Handler\HomePageHandler::class => Handler\HomePageHandlerFactory::class,
Handler\TestDoctrineConnectionHandler::class => Handler\Factory\TestDoctrineConnectionHandlerFactory::class,
Handler\TipoUsuario\TipoUsuarioListarHandler::class => Handler\Factory\TipoUsuario\TipoUsuarioListarHandlerFactory::class,
Handler\TipoUsuario\TipoUsuarioListarUmHandler::class => Handler\Factory\TipoUsuario\TipoUsuarioListarUmHandlerFactory::class,
Handler\TipoUsuario\TipoUsuarioCriarHandler::class => Handler\Factory\TipoUsuario\TipoUsuarioCriarHandlerFactory::class,
Handler\TipoUsuario\TipoUsuarioAlterarHandler::class => Handler\Factory\TipoUsuario\TipoUsuarioAlterarHandlerFactory::class,
Handler\TipoUsuario\TipoUsuarioDeletarHandler::class => Handler\Factory\TipoUsuario\TipoUsuarioDeletarHandlerFactory::class,
//Registrando Serviços
Service\TipoUsuarioService::class => Service\Factory\TipoUsuarioServiceFactory::class,
Service\UsuarioService::class => Service\Factory\UsuarioServiceFactory::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace App\Handler\Factory\TipoUsuario;

use App\Handler\TipoUsuario\TipoUsuarioAlterarHandler;
use Interop\Container\ContainerInterface;

/**
* Class TipoUsuarioAlterarHandlerFactory
* @package App\Handler\Factory\TipoUsuario
*/
class TipoUsuarioAlterarHandlerFactory
{
/**
* @param ContainerInterface $container
* @return TipoUsuarioAlterarHandler
*/
public function __invoke(ContainerInterface $container): TipoUsuarioAlterarHandler{
return new TipoUsuarioAlterarHandler($container);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Handler\Factory\TipoUsuario;

use App\Handler\TipoUsuario\TipoUsuarioCriarHandler;
use Interop\Container\ContainerInterface;

/**
* Class TipoUsuarioCriarHandlerFactory
* @package App\Handler\Factory\TipoUsuario
*/
class TipoUsuarioCriarHandlerFactory
{
/**
* @param ContainerInterface $container
* @return TipoUsuarioCriarHandler
*/
public function __invoke(ContainerInterface $container): TipoUsuarioCriarHandler
{
return new TipoUsuarioCriarHandler($container);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace App\Handler\Factory\TipoUsuario;

use App\Handler\TipoUsuario\TipoUsuarioDeletarHandler;
use Interop\Container\ContainerInterface;

/**
* Class TipoUsuarioDeletarHandlerFactory
* @package App\Handler\Factory\TipoUsuario
*/
class TipoUsuarioDeletarHandlerFactory
{

/**
* @param ContainerInterface $container
* @return TipoUsuarioDeletarHandler
*/
public function __invoke(ContainerInterface $container): TipoUsuarioDeletarHandler
{
return new TipoUsuarioDeletarHandler($container);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Handler\Factory\TipoUsuario;

use App\Handler\TipoUsuario\TipoUsuarioListarHandler;
use Interop\Container\ContainerInterface;

/**
* Class TipoUsuarioListarHandlerFactory
* @package App\Handler\Factory\TipoUsuario
*/
class TipoUsuarioListarHandlerFactory
{
/**
* @param ContainerInterface $container
* @return TipoUsuarioListarHandler
*/
public function __invoke(ContainerInterface $container): TipoUsuarioListarHandler
{
return new TipoUsuarioListarHandler($container);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Handler\Factory\TipoUsuario;

use App\Handler\TipoUsuario\TipoUsuarioListarUmHandler;
use Interop\Container\ContainerInterface;

/**
* Class TipoUsuarioListarUmHandlerFactory
* @package App\Handler\Factory\TipoUsuario
*/
class TipoUsuarioListarUmHandlerFactory
{
/**
* @param ContainerInterface $container
* @return TipoUsuarioListarUmHandler
*/
public function __invoke(ContainerInterface $container): TipoUsuarioListarUmHandler
{
return new TipoUsuarioListarUmHandler($container);
}
}
28 changes: 28 additions & 0 deletions src/App/src/Handler/HandlerAbstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Handler;

use Interop\Container\ContainerInterface;

/**
* Class HandlerAbstract
* @package App\Handler
*/
abstract class HandlerAbstract
{
/**
* @var ContainerInterface
*/
protected $container;

/**
* * HandlerAbstract constructor.
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
}
37 changes: 37 additions & 0 deletions src/App/src/Handler/TipoUsuario/TipoUsuarioAlterarHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace App\Handler\TipoUsuario;

use App\Handler\HandlerAbstract;
use App\Service\TipoUsuarioService;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Json\Json;

/**
* Class TipoUsuarioAlterarHandler
* @package App\Handler\TipoUsuario
*/
class TipoUsuarioAlterarHandler extends HandlerAbstract implements RequestHandlerInterface
{

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$data = Json::decode($request->getBody()->getContents(), JSON_OBJECT_AS_ARRAY);
$data['id'] = (int)$request->getAttribute('id');
$service = $this->container->get(TipoUsuarioService::class);
$userType = $service->update($data);

return new JsonResponse([
'data' => $userType
], 200);
}
}
35 changes: 35 additions & 0 deletions src/App/src/Handler/TipoUsuario/TipoUsuarioCriarHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace App\Handler\TipoUsuario;

use App\Handler\HandlerAbstract;
use App\Service\TipoUsuarioService;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Json\Json;

/**
* Class TipoUsuarioCriarHandler
* @package App\Handler\TipoUsuario
*/
class TipoUsuarioCriarHandler extends HandlerAbstract implements RequestHandlerInterface
{
/**
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$data = Json::decode($request->getBody()->getContents(), JSON_OBJECT_AS_ARRAY);
$service = $this->container->get(TipoUsuarioService::class);
$userType = $service->insert($data);

return new JsonResponse([
'data' => $userType
], 200);
}
}
36 changes: 36 additions & 0 deletions src/App/src/Handler/TipoUsuario/TipoUsuarioDeletarHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Handler\TipoUsuario;

use App\Handler\HandlerAbstract;
use App\Service\TipoUsuarioService;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\JsonResponse;
use Zend\Json\Json;

/**
* Class TipoUsuarioDeletarHandler
* @package App\Handler\TipoUsuario
*/
class TipoUsuarioDeletarHandler extends HandlerAbstract implements RequestHandlerInterface
{

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$id = (int)$request->getAttribute('id');
$service = $this->container->get(TipoUsuarioService::class);
$userTypeDeleted = $service->delete($id);

return new JsonResponse([
'data' => $userTypeDeleted
], 200);
}
}
37 changes: 37 additions & 0 deletions src/App/src/Handler/TipoUsuario/TipoUsuarioListarHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace App\Handler\TipoUsuario;

use App\Handler\HandlerAbstract;
use App\Service\TipoUsuarioService;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\JsonResponse;

/**
* Class TipoUsuarioListarHandler
* @package App\Handler\TipoUsuario
*/
class TipoUsuarioListarHandler extends HandlerAbstract implements RequestHandlerInterface
{

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$service = $this->container->get(TipoUsuarioService::class);
$resultWithDQL = $service->getAll();
$resultWithoutDQL = $service->getAllWithDQL();

return new JsonResponse([
'result_with_dql' => $resultWithDQL,
'result_without_dql' => $resultWithoutDQL
]);
}

}
45 changes: 45 additions & 0 deletions src/App/src/Handler/TipoUsuario/TipoUsuarioListarUmHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace App\Handler\TipoUsuario;

use App\Handler\HandlerAbstract;
use App\Service\TipoUsuarioService;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\JsonResponse;

/**
* Class TipoUsuarioListarUmHandler
* @package App\Handler\TipoUsuario
*/
class TipoUsuarioListarUmHandler extends HandlerAbstract implements RequestHandlerInterface
{

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$id = (int)$request->getAttribute('id');
$service = $this->container->get(TipoUsuarioService::class);
$resultWithDQL = $service->getOne($id);
$resultWithoutDQL = $service->getOneWithDQL($id);

if (!empty($resultWithDQL) && !empty($resultWithoutDQL))
{
return new JsonResponse([
'result_with_dql' => $resultWithDQL,
'result_without_dql' => $resultWithoutDQL
], 200);
}

return new JsonResponse([
'error' => true,
'message' => 'Nenhum registro encontrado'
], 404);
}
}

0 comments on commit 22a02aa

Please sign in to comment.