From f019bee87f1888f9510ee2c26b3846f6d4477d43 Mon Sep 17 00:00:00 2001 From: Elton Leite Ayres de Medeiros Borges Date: Fri, 8 Jan 2021 10:27:39 -0300 Subject: [PATCH] Developer (#4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * numero de projetos * numero de projetos * ultimos ajustes * :lipstick: Card 51322040 - Modifica e padroniza botões (#2) * numero de projetos * :lipstick: Modifica botão da tela de listagem de projetos * :lipstick: Modifica botões da tela de cadastro de projeto * :lipstick: Modifica botões da tela de listagem de tasks * :lipstick: Modifica botões da tela de cadastro de tasks Co-authored-by: Hélio Cardoso R. de Souza * :arrow_up: Modifica versão do php para 7.4 no composer * Adiciona Cadastro de Usuários (#3) * :recycle: Cria modulo Application e move Controllers para ele * :recycle: Move interface de ProjetoRepository para o modulo de infrastructure * :recycle: Move Interface de ProjetoRepository para modulo de Infrastructure * :recycle: Cria interface para ProjetoService e move a implementação para o modulo de Application * :recycle: Modifica ProjectController para utilizar ProjectService * :sparkles: Adiciona listar a UsuarioRepository * :sparkles: Adiciona serviço para usuário * :recycle: Refatora UsuarioController para usar UsuarioService * :sparkles: Adiciona ação de salvar para o Usuário Co-authored-by: Hélio Cardoso R. de Souza --- Data/tasks.db | Bin 45056 -> 45056 bytes composer.json | 2 +- config/routes/annotations.yaml | 2 +- config/services.yaml | 4 +- .../Controller/.gitignore | 0 .../Controller/Action/PostAction.php | 4 +- .../Controller/ProjetoController.php | 7 +- .../Controller/SecurityController.php | 2 +- .../Controller/TaskController.php | 2 +- .../Controller/TasksTrackerController.php | 57 ++++++ .../Controller/UsuarioController.php} | 27 ++- .../Service/ProjetoServiceImpl.php | 53 ++++++ .../Service/UsuarioServiceImpl.php | 51 ++++++ src/Domain/Model/Projeto.php | 2 - .../Model/ProjetoRepositoryInterface.php | 14 -- src/Domain/Model/Usuario.php | 4 +- src/Domain/Model/UsuarioAtribuicao.php | 5 +- .../UsuarioAtribuicaoRepositoryInterface.php | 13 ++ src/Domain/Service/ProjetoService.php | 18 ++ src/Domain/Service/UsuarioService.php | 19 ++ src/Domain/Services/ProjetoService.php | 44 ----- src/Infrastructure/Command/AddUserCommand.php | 4 +- .../Controller/TasksTrackerController.php | 62 ------- .../Repository/ProjetoRepository.php | 31 +--- .../Repository/ProjetoRepositoryImpl.php | 56 ++++++ .../UsuarioAtribuicaoRepository.php | 40 +++++ .../Repository/UsuarioRepository.php | 44 +---- .../Repository/UsuarioRepositoryImpl.php | 36 ++++ templates/index.html.twig | 8 +- templates/lista-projetos.html.twig | 108 +++++------ templates/novo-projeto.html.twig | 51 +++--- templates/novo-task.html.twig | 72 ++++---- templates/projeto.html.twig | 169 +++++++++--------- 33 files changed, 605 insertions(+), 406 deletions(-) rename src/{Infrastructure => Application}/Controller/.gitignore (100%) rename src/{Infrastructure => Application}/Controller/Action/PostAction.php (92%) rename src/{Infrastructure => Application}/Controller/ProjetoController.php (94%) rename src/{Infrastructure => Application}/Controller/SecurityController.php (96%) rename src/{Infrastructure => Application}/Controller/TaskController.php (98%) create mode 100644 src/Application/Controller/TasksTrackerController.php rename src/{Infrastructure/Controller/UsuarioAtribuicaoController.php => Application/Controller/UsuarioController.php} (66%) create mode 100644 src/Application/Service/ProjetoServiceImpl.php create mode 100644 src/Application/Service/UsuarioServiceImpl.php delete mode 100644 src/Domain/Model/ProjetoRepositoryInterface.php create mode 100644 src/Domain/Model/UsuarioAtribuicaoRepositoryInterface.php create mode 100644 src/Domain/Service/ProjetoService.php create mode 100644 src/Domain/Service/UsuarioService.php delete mode 100644 src/Domain/Services/ProjetoService.php delete mode 100644 src/Infrastructure/Controller/TasksTrackerController.php create mode 100644 src/Infrastructure/Repository/ProjetoRepositoryImpl.php create mode 100644 src/Infrastructure/Repository/UsuarioAtribuicaoRepository.php create mode 100644 src/Infrastructure/Repository/UsuarioRepositoryImpl.php diff --git a/Data/tasks.db b/Data/tasks.db index 57ed5d508a869aa3f1139848b5216c37d1fc6e3d..6f45f4c8a0c914a633c8fde13ccf87fc7d6487db 100644 GIT binary patch delta 344 zcmZp8z|`=7X@WH4*@-gFtY;bY>~C&NS-{W1#P^ngUy|?bW*&jNdKM7|_*U>4^H%a4<(K5A7AvHrDwO5tlmNw2 za}|;kQxX+QQgag7;078f7#LWA5femgGP^u)J+bCE@^Uc9a{_IaFDy@mAehMpmT;3< zU}A=5a50GD^1@V}^$gDPAjiuZ8W|flx+-xoG;aQHZNbdb=qAg_&=|^S%xPRWxyx!V o4;L`R8To%P@c-g}x0%P`1wR`o3gqNA|MLH<&*;1PM?HrD0JwjJxc~qF diff --git a/composer.json b/composer.json index aa84db9..8407ef1 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "type": "project", "license": "proprietary", "require": { - "php": ">=7.1.3", + "php": ">=7.4", "ext-ctype": "*", "ext-iconv": "*", "composer/package-versions-deprecated": "1.11.99.1", diff --git a/config/routes/annotations.yaml b/config/routes/annotations.yaml index c685c71..5a98b67 100644 --- a/config/routes/annotations.yaml +++ b/config/routes/annotations.yaml @@ -1,5 +1,5 @@ controllers: - resource: ../../src/Infrastructure/Controller/ + resource: ../../src/Application/Controller/ type: annotation kernel: diff --git a/config/services.yaml b/config/services.yaml index 6a2a1fd..ec28731 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -23,8 +23,8 @@ services: # controllers are imported separately to make sure services can be injected # as action arguments even if you don't extend any base controller class - App\Infrastructure\Controller\: - resource: '../src/Infrastructure/Controller' + App\Application\Controller\: + resource: '../src/Application/Controller' tags: ['controller.service_arguments'] # add more service definitions when explicit configuration is needed diff --git a/src/Infrastructure/Controller/.gitignore b/src/Application/Controller/.gitignore similarity index 100% rename from src/Infrastructure/Controller/.gitignore rename to src/Application/Controller/.gitignore diff --git a/src/Infrastructure/Controller/Action/PostAction.php b/src/Application/Controller/Action/PostAction.php similarity index 92% rename from src/Infrastructure/Controller/Action/PostAction.php rename to src/Application/Controller/Action/PostAction.php index 5a36f94..41f8c15 100644 --- a/src/Infrastructure/Controller/Action/PostAction.php +++ b/src/Application/Controller/Action/PostAction.php @@ -1,6 +1,6 @@ projetoService = $projetoService; + $this->usuarioRepository = $usuarioRepository; + } + + + /** + * @Route("/index", name="index") + * @IsGranted("ROLE_ADMIN") + */ + public function index() + { + + $numeroProjetos = $this->projetoService->getNumroDeProjetos(); + $numeroUsuario = $this->usuarioRepository->getNumeroUsers(); + + return $this->render( + 'index.html.twig', + [ + 'numeroProjeto' => $numeroProjetos, + 'numeroUsuarios' => $numeroUsuario + ] + ); + } + +} diff --git a/src/Infrastructure/Controller/UsuarioAtribuicaoController.php b/src/Application/Controller/UsuarioController.php similarity index 66% rename from src/Infrastructure/Controller/UsuarioAtribuicaoController.php rename to src/Application/Controller/UsuarioController.php index 3ee089d..288fdc6 100644 --- a/src/Infrastructure/Controller/UsuarioAtribuicaoController.php +++ b/src/Application/Controller/UsuarioController.php @@ -1,34 +1,45 @@ usuarioService = $usuarioService; + } + /** * @Route("/tasks" , name="usuario_tasks") */ public function listarAtribuicoes() { $usuario = $this->getUser(); - $atribuicoes = $this - ->getDoctrine() - ->getRepository(UsuarioAtribuicao::class) - ->findBy(['usuario' => $usuario->getId()]) - ; + $atribuicoes = $this->usuarioService.atribuicoes($usuario.getId()); return $this->render('usuario-tasks.html.twig', [ diff --git a/src/Application/Service/ProjetoServiceImpl.php b/src/Application/Service/ProjetoServiceImpl.php new file mode 100644 index 0000000..bf6b1be --- /dev/null +++ b/src/Application/Service/ProjetoServiceImpl.php @@ -0,0 +1,53 @@ +projetoRepository = $projetoRepository; + } + + /** + * @param Projeto $projeto + */ + public function salvar(Projeto $projeto): void + { + $this->projetoRepository->salvar($projeto); + } + + /** + * @return array + */ + public function listar(): array + { + return $this->projetoRepository->listar(); + } + + /** + * @return int + */ + public function getNumeroProjetos(): int + { + return $this->projetoRepository->getNumeroProjetos(); + } +} diff --git a/src/Application/Service/UsuarioServiceImpl.php b/src/Application/Service/UsuarioServiceImpl.php new file mode 100644 index 0000000..5357312 --- /dev/null +++ b/src/Application/Service/UsuarioServiceImpl.php @@ -0,0 +1,51 @@ +usuarioRepository = $usuarioRepository; + } + + public function salvar(Usuario $usuario): void + { + $this->usuarioRepository->salvar($usuario); + } + + public function listar(): array + { + return $this->usuarioRepository->listar(); + } + + public function atribuicoes(int $id): array + { + return $this + ->getDoctrine() + ->getRepository(UsuarioAtribuicao::class) + ->findBy(['usuario' => $id]); + + } + +} \ No newline at end of file diff --git a/src/Domain/Model/Projeto.php b/src/Domain/Model/Projeto.php index c82c2e7..5b749e0 100644 --- a/src/Domain/Model/Projeto.php +++ b/src/Domain/Model/Projeto.php @@ -5,8 +5,6 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; -use Monolog\Logger; -use Psr\Log\LoggerInterface; /** * @ORM\Entity diff --git a/src/Domain/Model/ProjetoRepositoryInterface.php b/src/Domain/Model/ProjetoRepositoryInterface.php deleted file mode 100644 index ee55a03..0000000 --- a/src/Domain/Model/ProjetoRepositoryInterface.php +++ /dev/null @@ -1,14 +0,0 @@ -projetoRepository = $projetoRepository; - } - - /** - * @param Projeto $projeto - */ - public function salvar(Projeto $projeto) - { - $this->projetoRepository->salvar($projeto); - } - - /** - * @return array - */ - public function listar(): array - { - return $this->projetoRepository->listar(); - } -} diff --git a/src/Infrastructure/Command/AddUserCommand.php b/src/Infrastructure/Command/AddUserCommand.php index e8e6c01..5933cc7 100755 --- a/src/Infrastructure/Command/AddUserCommand.php +++ b/src/Infrastructure/Command/AddUserCommand.php @@ -12,7 +12,7 @@ namespace App\Infrastructure\Command; use App\Domain\Model\Usuario; -use App\Infrastructure\Repository\UsuarioRepository; +use App\Infrastructure\Repository\UsuarioRepositoryImpl; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -38,7 +38,7 @@ class AddUserCommand extends Command private $entityManager; private $users; - public function __construct(EntityManagerInterface $em, UsuarioRepository $users) + public function __construct(EntityManagerInterface $em, UsuarioRepositoryImpl $users) { parent::__construct(); diff --git a/src/Infrastructure/Controller/TasksTrackerController.php b/src/Infrastructure/Controller/TasksTrackerController.php deleted file mode 100644 index b230c5c..0000000 --- a/src/Infrastructure/Controller/TasksTrackerController.php +++ /dev/null @@ -1,62 +0,0 @@ -get('doctrine'); - - -// $status = $doctrine->getManager()->getRepository(Status::class)->find(1); -// -// $task = new Task(); -// $task->setStatus($status); -// $task->setNome("Criar Crud para os status"); -// $task->setDescircao("Possibilitar o gerente da empresa adicionar um status para as tasks"); -// $task->setDtCadastro(new \DateTime()); -// $projeto->addTask($task); -// $task->setProjeto($projeto); - -// $usuario = new Usuario(); -// $usuario->setNome('Hélio Cardoso'); -// $usuario->setEmail('heliosouza@gmail.com'); -// $usuario->setRoles(['ROLE_ADMIM1']); -// - - - - $result = $doctrine->getRepository(Usuario::class)->findAll(); - dump($result);exit; - } - - /** - * @Route("/index", name="index") - * @IsGranted("ROLE_ADMIN") - */ - public function index() - { - return $this->render('index.html.twig'); - } - -} diff --git a/src/Infrastructure/Repository/ProjetoRepository.php b/src/Infrastructure/Repository/ProjetoRepository.php index 4393401..c2303fb 100644 --- a/src/Infrastructure/Repository/ProjetoRepository.php +++ b/src/Infrastructure/Repository/ProjetoRepository.php @@ -3,37 +3,16 @@ namespace App\Infrastructure\Repository; use App\Domain\Model\Projeto; -use App\Domain\Model\ProjetoRepositoryInterface; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; /** - * Class ProjetoRepository + * class ProjetoRepository * @package App\Infrastructure\Repository */ -class ProjetoRepository extends ServiceEntityRepository implements ProjetoRepositoryInterface +interface ProjetoRepository { - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Projeto::class); - } + public function salvar(Projeto $projeto): void; - /** - * @param Projeto $projeto - * @throws \Doctrine\ORM\ORMException - * @throws \Doctrine\ORM\OptimisticLockException - */ - public function salvar(Projeto $projeto): void - { - $this->getEntityManager()->persist($projeto); - $this->getEntityManager()->flush(); - } + public function listar(): array; - /** - * @return array - */ - public function listar(): array - { - return $this->findAll(); - } + public function getNumeroProjetos(): int; } diff --git a/src/Infrastructure/Repository/ProjetoRepositoryImpl.php b/src/Infrastructure/Repository/ProjetoRepositoryImpl.php new file mode 100644 index 0000000..be47a16 --- /dev/null +++ b/src/Infrastructure/Repository/ProjetoRepositoryImpl.php @@ -0,0 +1,56 @@ +getEntityManager()->persist($projeto); + $this->getEntityManager()->flush(); + } + + /** + * @return array + */ + public function listar(): array + { + return $this->findAll(); + } + + /** + * @return int + * @throws NoResultException + * @throws NonUniqueResultException + */ + public function getNumeroProjetos(): int + { + $queryBuilder = $this->createQueryBuilder("pro"); + $queryBuilder + ->select($queryBuilder->expr()->count("pro")); + + return $queryBuilder->getQuery()->getSingleScalarResult(); + } +} diff --git a/src/Infrastructure/Repository/UsuarioAtribuicaoRepository.php b/src/Infrastructure/Repository/UsuarioAtribuicaoRepository.php new file mode 100644 index 0000000..19826a3 --- /dev/null +++ b/src/Infrastructure/Repository/UsuarioAtribuicaoRepository.php @@ -0,0 +1,40 @@ +createQueryBuilder("userAtrib"); + + $queryBuilder + ->select( + [ + 'userAtrib.status', + $queryBuilder->expr()->count("userAtrib") + ] + )->groupBy('userAtrib.status') + ; + + return $queryBuilder->getQuery()->execute(); + } +} diff --git a/src/Infrastructure/Repository/UsuarioRepository.php b/src/Infrastructure/Repository/UsuarioRepository.php index 524680c..fae0d7c 100644 --- a/src/Infrastructure/Repository/UsuarioRepository.php +++ b/src/Infrastructure/Repository/UsuarioRepository.php @@ -3,48 +3,14 @@ namespace App\Infrastructure\Repository; use App\Domain\Model\Usuario; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; /** - * @method Usuario|null find($id, $lockMode = null, $lockVersion = null) - * @method Usuario|null findOneBy(array $criteria, array $orderBy = null) - * @method Usuario[] findAll() - * @method Usuario[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + * class UsuarioRepository + * @package App\Infrastructure\Repository */ -class UsuarioRepository extends ServiceEntityRepository +interface UsuarioRepository { - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Usuario::class); - } + public function salvar(Usuario $usuario): void; - // /** - // * @return Usuario[] Returns an array of Usuario objects - // */ - /* - public function findByExampleField($value) - { - return $this->createQueryBuilder('u') - ->andWhere('u.exampleField = :val') - ->setParameter('val', $value) - ->orderBy('u.id', 'ASC') - ->setMaxResults(10) - ->getQuery() - ->getResult() - ; - } - */ - - /* - public function findOneBySomeField($value): ?Usuario - { - return $this->createQueryBuilder('u') - ->andWhere('u.exampleField = :val') - ->setParameter('val', $value) - ->getQuery() - ->getOneOrNullResult() - ; - } - */ + public function listar(): array; } diff --git a/src/Infrastructure/Repository/UsuarioRepositoryImpl.php b/src/Infrastructure/Repository/UsuarioRepositoryImpl.php new file mode 100644 index 0000000..aaff5a1 --- /dev/null +++ b/src/Infrastructure/Repository/UsuarioRepositoryImpl.php @@ -0,0 +1,36 @@ +findAll(); + } + + public function salvar(Usuario $usuario): void + { + $this->getEntityManager()->persist($usuario); + $this->getEntityManager()->flush(); + } + +} diff --git a/templates/index.html.twig b/templates/index.html.twig index 03e6919..e82dea2 100644 --- a/templates/index.html.twig +++ b/templates/index.html.twig @@ -45,7 +45,7 @@
Número de Usuários
-
5.000
+
{{ numeroUsuarios }}
@@ -65,12 +65,12 @@
-
73%
+
{{ numeroProjeto }}
@@ -92,7 +92,7 @@
Projetos Ativos
-
18
+
{{ numeroProjeto }}
diff --git a/templates/lista-projetos.html.twig b/templates/lista-projetos.html.twig index 65ee7b4..b7e6e3e 100644 --- a/templates/lista-projetos.html.twig +++ b/templates/lista-projetos.html.twig @@ -1,57 +1,65 @@ {% include 'header.html.twig' %} -
-
-
-
Lista de Projetos em Andamento
-
-
-
- - - - - - - - - - - - - - - - - - - - - {% for projeto in projetos %} - - - - - - - +
+
+
+
Lista de Projetos em Andamento
+
+
+
+
NomeDescricaoGerenteData Cadastro
NomeDescricaoGerenteData Cadastro
{{ projeto.nome }}{{ projeto.descricao }}{{ projeto.gerente }}{{ projeto.dtCadastro| date("m/d/Y") }} - - - - - - -
+ + + + + + + + + + + + + + + + + + + + {% for projeto in projetos %} + + + + + + -
NomeDescricaoGerenteData Cadastro
NomeDescricaoGerenteData Cadastro
{{ projeto.nome }}{{ projeto.descricao }}{{ projeto.gerente }}{{ projeto.dtCadastro| date("m/d/Y") }} + + + + + Detalhes + - {% endfor %} -
-
-
-
- -
+ + + + + Editar + + + + {% endfor %} + +
+
+ + + + + {% include 'footer.html.twig' %} diff --git a/templates/novo-projeto.html.twig b/templates/novo-projeto.html.twig index 717e35e..594ce92 100644 --- a/templates/novo-projeto.html.twig +++ b/templates/novo-projeto.html.twig @@ -1,29 +1,40 @@ {% include 'header.html.twig' %} -
-

Cadastrar Novo Projeto

- {{ form_start(form) }} -
-
- {{ form_row(form.nome) }} -
+
+

Cadastrar Novo Projeto

+ {{ form_start(form) }} +
+
+ {{ form_row(form.nome) }}
-
-
- {{ form_row(form.descricao) }} -
+
+
+
+ {{ form_row(form.descricao) }}
-
-
- {{ form_row(form.dtCadastro) }} -
+
+
+
+ {{ form_row(form.dtCadastro) }}
-
-
- {{ form_row(form.gerente) }} -
+
+
+
+ {{ form_row(form.gerente) }}
-
+ + + + + Voltar + + +
{% include 'footer.html.twig' %} diff --git a/templates/novo-task.html.twig b/templates/novo-task.html.twig index aa3e3ba..f6cd9d6 100644 --- a/templates/novo-task.html.twig +++ b/templates/novo-task.html.twig @@ -1,46 +1,46 @@ {% include 'header.html.twig' %} -
-

Cadastrar Nova Task

- {{ form_start(form) }} -
-
- {{ form_row(form.nome) }} -
+
+

Cadastrar Nova Task

+ {{ form_start(form) }} +
+
+ {{ form_row(form.nome) }}
-
-
- {{ form_row(form.descricao) }} -
-
-
-
- {{ form_row(form.dtCadastro) }} -
+
+
+
+ {{ form_row(form.descricao) }}
-
-
- {{ form_row(form.dtConclusao, ) }} -
+
+
+
+ {{ form_row(form.dtCadastro) }}
-
-
- {{ form_row(form.status) }} -
+
+
+
+ {{ form_row(form.dtConclusao, ) }}
- - - - - - Voltar -
+
+
+ {{ form_row(form.status) }} +
+ + + + + Voltar + + +
+
{% include 'footer.html.twig' %} diff --git a/templates/projeto.html.twig b/templates/projeto.html.twig index f1c22ff..365c252 100644 --- a/templates/projeto.html.twig +++ b/templates/projeto.html.twig @@ -1,95 +1,100 @@ {% include 'header.html.twig' %} - + -
+
-
-
-
{{ projeto.nome }}
-
-
-
Descrição: {{projeto.descricao }}
-
-
-
Gerente: {{ projeto.gerente }}
-
-
-
Data de Cadastro: {{ projeto.dtCadastro| date("d/m/Y H:m") }}
-
- -
- - - - - Voltar - +
+ + + + + Voltar + - - - - - Cadastrar nova Task - + + + + + Cadastrar nova Task + -
+
-
+
{% include 'footer.html.twig' %}