diff --git a/.gitignore b/.gitignore index a3dafb9..edd7a45 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ /vendor/ ###< symfony/framework-bundle ### /.idea/ +/nbproject/ +.project diff --git a/Data/tasks.db b/Data/tasks.db index 2c6f902..4bb4864 100644 Binary files a/Data/tasks.db and b/Data/tasks.db differ diff --git a/src/Domain/Form/Type/StatusType.php b/src/Domain/Form/Type/StatusType.php new file mode 100644 index 0000000..f49fa61 --- /dev/null +++ b/src/Domain/Form/Type/StatusType.php @@ -0,0 +1,35 @@ +add('descricao', TextType::class, ['label' => false, 'attr' => ['placeholder' => 'Descrição da Task ']]) + ->add('salvar', SubmitType::class); + } + + /** + * @param OptionsResolver $resolver + */ + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Status::class + ]); + } +} diff --git a/src/Domain/Form/Type/TaskType.php b/src/Domain/Form/Type/TaskType.php index a5f1b1c..e997e61 100644 --- a/src/Domain/Form/Type/TaskType.php +++ b/src/Domain/Form/Type/TaskType.php @@ -28,7 +28,7 @@ class TaskType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options): void { $builder - ->add('nome', TextType::class, ['label' => false, 'attr' => ['placeholder' => 'Nome do Projeto ']]) + ->add('nome', TextType::class, ['label' => false, 'attr' => ['placeholder' => 'Nome da Task ']]) ->add('descricao', TextareaType::class) ->add('dtCadastro', DateType::class, [ 'label' => 'Data de Cadastro', diff --git a/src/Domain/Repository/ProjetoRepositoryInterface.php b/src/Domain/Repository/ProjetoRepositoryInterface.php new file mode 100644 index 0000000..2e19f24 --- /dev/null +++ b/src/Domain/Repository/ProjetoRepositoryInterface.php @@ -0,0 +1,16 @@ +statusRepository = $statusRepository; + } + + /** + * @param Status $status + */ + public function salvar(Status $status) + { + $this->statusRepository->salvar($status); + } + + /** + * @return array + */ + public function listar(): array + { + return $this->statusRepository->listar(); + } +} diff --git a/src/Domain/Services/TaskService.php b/src/Domain/Services/TaskService.php new file mode 100644 index 0000000..3d70eb6 --- /dev/null +++ b/src/Domain/Services/TaskService.php @@ -0,0 +1,55 @@ +taskRepository = $taskRepository; + } + + /** + * @param Task $task + */ + public function salvar(Task $task) + { + $this->taskRepository->salvar($task); + } + + /** + * @return array + */ + public function listar(): array + { + return $this->taskRepository->listar(); + } + + public function listarPorProjeto(Projeto $projeto): array + { + return $this->taskRepository->listarPorProjeto($projeto); + } + + public function deletar(Task $task): void + { + $this->taskRepository->deletar($task); + } +} diff --git a/src/Infrastructure/Controller/StatusController.php b/src/Infrastructure/Controller/StatusController.php new file mode 100644 index 0000000..0a06dd0 --- /dev/null +++ b/src/Infrastructure/Controller/StatusController.php @@ -0,0 +1,82 @@ +statusService = $statusService; + } + + /** + * @Route("/listar", name="status_listar") + */ + public function listarStatus() + { + $statusList = $this->statusService->listar(); + + return $this->render('lista-status.html.twig', [ + 'statusList' => $statusList + ]); + } + + /** + * @Route("/cadastrar", name="status_cadastrar", methods={"GET", "POST"}) + */ + public function cadastrar(Request $request) + { + $form = $this->createForm(StatusType::class); + $form->handleRequest($request); + + if ($form->isSubmitted()) { + $status = $form->getData(); + $this->statusService->salvar($status); + + $this->addFlash('success','Status Cadastrada com sucesso'); + + return $this->redirect('/status/listar'); + } + + return $this->render('novo-status.html.twig', [ + 'form' => $form->createView() + ]); + } + + /** + * @Route("/editar/{status}", name="status_editar", methods={"GET", "POST"}) + * @ParamConverter("status", class="App\Domain\Model\Status") + */ + public function editar(Status $status, Request $request) + { + $form = $this->createForm(StatusType::class, $status); + $form->handleRequest($request); + + if ($form->isSubmitted()) { + $status = $form->getData(); + $this->statusService->salvar($status); + + $this->addFlash('success','Status alterado com sucesso'); + + return $this->redirect('/status/listar'); + } + + return $this->render('novo-status.html.twig', [ + 'form' => $form->createView() + ]); + } + +} diff --git a/src/Infrastructure/Controller/TaskController.php b/src/Infrastructure/Controller/TaskController.php index d5db585..413b986 100644 --- a/src/Infrastructure/Controller/TaskController.php +++ b/src/Infrastructure/Controller/TaskController.php @@ -7,25 +7,49 @@ use App\Domain\Model\Status; use App\Domain\Model\Task; use App\Domain\Model\UsuarioAtribuicao; +use \App\Domain\Services\TaskService; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; /** - * @Route("/task") + * @Route("/tasks") */ class TaskController extends AbstractController { + private TaskService $taskService; + + public function __construct(TaskService $taskService) + { + $this->taskService = $taskService; + } /** - * @Route("/usuario/{id}") + * @Route("/listar", name="task_listar") */ - public function listTasks() + public function listarTasks() { + $tasks = $this->taskService->listar(); + return $this->render('lista-tasks.html.twig', [ + 'tasks' => $tasks + ]); + } + /** + * @Route("/projeto/{projeto}", name="task_projeto_listar") + * @ParamConverter("projeto", class="App\Domain\Model\Projeto") + * @param Projeto $projeto + */ + public function listarTasksPorProjeto(Projeto $projeto) + { + $tasks = $this->taskService->listarPorProjeto($projeto); + + return $this->render('lista-tasks.html.twig', [ + 'tasks' => $tasks, + 'projeto' => $projeto + ]); } /** @@ -57,7 +81,9 @@ public function atribuir(Task $task) } /** - * @Route("/cadastrar/{projeto}", name="cadastrar_task", methods={"GET", "POST"}) + * @Route("/cadastrar/{projeto}", name="task_cadastrar", methods={"GET", "POST"}) + * @ParamConverter("projeto", class="App\Domain\Model\Projeto") + * @param Projeto $projeto */ public function cadastrar(Projeto $projeto, Request $request) { @@ -67,23 +93,21 @@ public function cadastrar(Projeto $projeto, Request $request) if ($form->isSubmitted()) { $task = $form->getData(); $task->setProjeto($projeto); - $doctrine = $this->getDoctrine()->getManager(); - - $doctrine->persist($task); - $doctrine->flush(); + $this->taskService->salvar($task); $this->addFlash('success','Task Cadastrada com sucesso'); - return $this->redirect('/projetos/visualizar/'.$projeto->getId()); + return $this->redirect('/tasks/projeto/'.$projeto->getId()); } return $this->render('novo-task.html.twig', [ - 'form' => $form->createView(), 'projeto' => $projeto + 'form' => $form->createView(), + 'projeto' => $projeto ]); } /** - * @Route("/editar/{task}", name="editar_task", methods={"GET", "POST"}) + * @Route("/editar/{task}", name="task_editar", methods={"GET", "POST"}) * @ParamConverter("task", class="App\Domain\Model\Task") */ public function editar(Task $task, Request $request) @@ -93,37 +117,31 @@ public function editar(Task $task, Request $request) if ($form->isSubmitted()) { $task = $form->getData(); - $doctrine = $this->getDoctrine()->getManager(); + $this->taskService->salvar($task); - $doctrine->persist($task); - $doctrine->flush(); + $this->addFlash('success','Task alterada com sucesso'); - $this->addFlash('success','Task Cadastrada com sucesso'); - - return $this->redirect('/usuario/tasks'); + return $this->redirect('/tasks/projeto/' . $task->getProjeto()->getId()); } return $this->render('novo-task.html.twig', [ - 'form' => $form->createView(), 'projeto' => $task->getProjeto() + 'form' => $form->createView(), + 'projeto' => $task->getProjeto() ]); } /** - * @Route("/deletar/{atribuicao}", name="deletar_task", methods={"GET", "POST"}) - * @ParamConverter("atribuicao", class="App\Domain\Model\UsuarioAtribuicao") + * @Route("/deletar/{task}", name="task_deletar", methods={"GET", "POST"}) + * @ParamConverter("task", class="App\Domain\Model\Task") */ - public function deletar(UsuarioAtribuicao $atribuicao) + public function deletar(Task $task) { - $doctrine = $this->getDoctrine()->getManager(); - $task = $atribuicao->getTask(); - - $doctrine->remove($atribuicao); - $doctrine->remove($task); - $doctrine->flush(); + $idProjeto = $task->getProjeto()->getId(); + $this->taskService->deletar($task); $this->addFlash('success','Task Deletada com sucesso'); - return $this->redirect('/usuario/tasks'); + return $this->redirect('/tasks/projeto/' . $idProjeto); } } diff --git a/src/Infrastructure/Repository/ProjetoRepository.php b/src/Infrastructure/Repository/ProjetoRepository.php index 068b0d0..1f77424 100644 --- a/src/Infrastructure/Repository/ProjetoRepository.php +++ b/src/Infrastructure/Repository/ProjetoRepository.php @@ -3,7 +3,7 @@ namespace App\Infrastructure\Repository; use App\Domain\Model\Projeto; -use App\Domain\Model\ProjetoRepositoryInterface; +use App\Domain\Repository\ProjetoRepositoryInterface; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; diff --git a/src/Infrastructure/Repository/StatusRepository.php b/src/Infrastructure/Repository/StatusRepository.php new file mode 100644 index 0000000..cdbcd71 --- /dev/null +++ b/src/Infrastructure/Repository/StatusRepository.php @@ -0,0 +1,39 @@ +getEntityManager()->persist($status); + $this->getEntityManager()->flush(); + } + + /** + * @return array + */ + public function listar(): array + { + return $this->findAll(); + } +} diff --git a/src/Infrastructure/Repository/TaskRepository.php b/src/Infrastructure/Repository/TaskRepository.php new file mode 100644 index 0000000..dd7c27b --- /dev/null +++ b/src/Infrastructure/Repository/TaskRepository.php @@ -0,0 +1,56 @@ +getEntityManager()->persist($task); + $this->getEntityManager()->flush(); + } + + /** + * @return array + */ + public function listar(): array + { + return $this->findAll(); + } + + public function listarPorProjeto(Projeto $projeto) + { + return $this->createQueryBuilder('t') + ->andWhere('t.projeto = :projeto') + ->setParameter('projeto', $projeto->getId()) + ->orderBy('t.id', 'ASC') + ->getQuery() + ->getResult(); + } + + public function deletar(Task $task): void + { + $this->getEntityManager()->remove($task); + $this->getEntityManager()->flush(); + } +} diff --git a/templates/header.html.twig b/templates/header.html.twig index c2b89c6..b8f08b7 100644 --- a/templates/header.html.twig +++ b/templates/header.html.twig @@ -34,7 +34,7 @@
diff --git a/templates/lista-projetos.html.twig b/templates/lista-projetos.html.twig index 65ee7b4..d1005f2 100644 --- a/templates/lista-projetos.html.twig +++ b/templates/lista-projetos.html.twig @@ -33,9 +33,12 @@| Descricao | ++ |
|---|---|
| Descricao | ++ |
| {{ status.descricao }} | ++ + + + | +
Projeto: {{ projeto.nome }}
+| Nome | +Descricao | +Projeto | +Status | +Data Cadastro | +Data Conclusão | ++ |
|---|---|---|---|---|---|---|
| Nome | +Descricao | +Projeto | +Status | +Data Cadastro | +Data Conclusão | ++ |
| {{ task.nome }} | +{{ task.descricao }} | +{{ task.projeto.nome }} | +{{ task.status.descricao }} | +{{ task.dtCadastro| date("m/d/Y") }} | +{{ task.dtConclusao| date("m/d/Y") }} | ++ + + + + + + | +
Projeto: {{ projeto.nome }}
{{ form_start(form) }}