Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projeto Final - Jakson Rodrigues #50

Open
wants to merge 6 commits into
base: imobiliaria2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified data/database.sqlite
Binary file not shown.
51 changes: 47 additions & 4 deletions src/Controller/ImovelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Entity\Imovel;
use App\Forms\ImovelType;
use App\Service\ImovelService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
Expand All @@ -19,7 +20,7 @@ class ImovelController extends AbstractController
* @param Request $request
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function cadastroImovel(Request $request)
public function cadastroImovel(Request $request, ImovelService $imovelService)
{

$imovel = new Imovel();
Expand All @@ -28,9 +29,7 @@ public function cadastroImovel(Request $request)

if ($form->isSubmitted()) {
$imovel = $form->getData();
$em = $this->getDoctrine()->getManager();
$em->persist($imovel);
$em->flush();
$imovelService->salvar($imovel);

return $this->redirectToRoute('index');
}
Expand Down Expand Up @@ -69,6 +68,7 @@ public function imoveisPortifolios()

/**
* @Route("/imovel/visualizar/{id}", name="imovel_visualizar")
* @param Request $request
*/
public function imovelVisualizar(Request $request)
{
Expand All @@ -82,5 +82,48 @@ public function imovelVisualizar(Request $request)
}


/**
* @Route("/imovel/editar/{id}", name="imovel_editar")
*/
public function editarImovel(int $id, Request $request, ImovelService $imovelService)
{
$em = $this->getDoctrine()->getManager();
$imovel = $em->getRepository(Imovel::class)->find($id);

if (!$imovel) {
throw new \Exception('Imovel não encontrado');
}

$form = $this->createForm(ImovelType::class, $imovel);

$form->handleRequest($request);

if ($form->isSubmitted()) {
$imovel = $form->getData();
$imovelService->editar($imovel);
return $this->redirectToRoute('listar_imoveis');
}

return $this->render('imovel_cadastro.html.twig', [
'form' => $form->createView()
]);

$clienteServico = $this->container->get('logger');
}


/**
* @Route("/imovel/deletar/{id}", name="deletar_imovel")
*/
public function imovelDeletar(Request $request, ImovelService $imovelService)
{
$id = $request->get('id');
$em = $this->getDoctrine()->getManager();
$imovel = $em->getRepository(Imovel::class)->find($id);
$imovelService->deletar($imovel);
$this->addFlash('success', 'Imóvel de id: '.$id.' deletado com sucesso!!!');

return $this->redirectToRoute('listar_imoveis');
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

psr

}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

falta linha em branco no fim do arquivo.

24 changes: 9 additions & 15 deletions src/Controller/UsuarioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Entity\Corretor;
use App\Forms\UsuarioType;
use App\Entity\Usuario;
use App\Service\UsuarioService;
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
Expand All @@ -21,24 +22,19 @@ class UsuarioController extends AbstractController
{

/**
*@IsGranted("ROLE_ADMIN")
* @Route("/usuario", name="usuario_novo")
*/
public function cadastroUsuario(Request $request)
public function cadastroUsuario(Request $request, UsuarioService $usuarioService)
{
$usuario = new Usuario();
$form = $this->createForm(UsuarioType::class, $usuario);
$form->handleRequest($request);

if ($form->isSubmitted()) {
$usuario = $form->getData();
$em = $this->getDoctrine()->getManager();
$em->persist($usuario);
$em->flush();

$usuarioService->salvar($usuario);
return $this->redirectToRoute('index');
}

return $this->render('usuario_cadastro.html.twig', [
'form' => $form->createView()
]);
Expand Down Expand Up @@ -71,7 +67,7 @@ public function listarUsuarios(Request $request)
/**
* @Route("/editar/{id}", name="editar_usuario")
*/
public function editarUsuario(int $id, Request $request)
public function editarUsuario(int $id, Request $request, UsuarioService $usuarioService)
{
$em = $this->getDoctrine()->getManager();
$usuario = $em->getRepository(Usuario::class)->find($id);
Expand All @@ -86,27 +82,25 @@ public function editarUsuario(int $id, Request $request)

if ($form->isSubmitted()) {
$usuario = $form->getData();
$em = $this->getDoctrine()->getManager();
$em->merge($usuario);
$em->flush();

$usuarioService->editar($usuario);
return $this->redirectToRoute('listar_usuarios');
}

return $this->render('usuario_cadastro.html.twig', [
'form' => $form->createView()
]);

$clienteServico = $this->container->get('logger');
}

/**
* @Route("/deletar/{id}", name="deletar_usuario")
*/
public function deletarUsuario(int $id, Request $request)
public function deletarUsuario(int $id, Request $request, UsuarioService $usuarioService)
{
$em = $this->getDoctrine()->getManager();
$usuario = $em->getRepository(Usuario::class)->find($id);
$em->remove($usuario);
$em->flush();
$usuarioService->deletar($usuario);
$this->addFlash('success', 'Usuario de id:'.$id.' deletado com sucesso!!!');

return $this->redirectToRoute('listar_usuarios');
Expand Down
5 changes: 3 additions & 2 deletions src/Forms/ImovelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Date;
Expand Down Expand Up @@ -40,10 +41,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
]

])
->add('caracteristicas', TextType::class, [
->add('caracteristicas', TextareaType::class, [
'label' => 'Caracterisiticas do Imovel',
])
->add('observacao', TextType::class, [
->add('observacao', TextareaType::class, [
'label' => 'Observações Geral',
])
->add('tipoImovel', ChoiceType::class, [
Expand Down
46 changes: 46 additions & 0 deletions src/Repository/ImovelRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Repository;

use App\Entity\Imovel;
use Doctrine\ORM\EntityRepository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

class ImovelRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Imovel::class);
}

/**
* @return EntityManager
*/
public function salvar(Imovel $imovel)
{
$em = $this->getEntityManager();
$em->persist($imovel);
$em->flush();
}

/**
* @return EntityManager
*/
public function editar(Imovel $imovel)
{
$em = $this->getEntityManager();
$em->merge($imovel);
$em->flush();
}

/**
* @return EntityManager
*/
public function deletar(Imovel $imovel)
{
$em = $this->getEntityManager();
$em->remove($imovel);
$em->flush();
}
}
46 changes: 46 additions & 0 deletions src/Repository/UsuarioRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Repository;

use App\Entity\Usuario;
use Doctrine\ORM\EntityRepository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

class UsuarioRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Usuario::class);
}

/**
* @return EntityManager
*/
public function salvar(Usuario $usuario)
{
$em = $this->getEntityManager();
$em->persist($usuario);
$em->flush();
}

/**
* @return EntityManager
*/
public function editar(Usuario $usuario)
{
$em = $this->getEntityManager();
$em->merge($usuario);
$em->flush();
}

/**
* @return EntityManager
*/
public function deletar(Usuario $usuario)
{
$em = $this->getEntityManager();
$em->remove($usuario);
$em->flush();
}
}
34 changes: 34 additions & 0 deletions src/Service/ImovelService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Service;

use App\Repository\ImovelRepository;
use App\Entity\Imovel;

class ImovelService
{
/**
* @var ImovelRepository
*/
private $imovelRepository;

public function __construct(ImovelRepository $imovelRepository)
{
$this->imovelRepository = $imovelRepository;
}

public function salvar(Imovel $imovel)
{
$this->imovelRepository->salvar($imovel);
}

public function editar(Imovel $imovel)
{
$this->imovelRepository->editar($imovel);
}

public function deletar(Imovel $imovel)
{
$this->imovelRepository->deletar($imovel);
}
}
34 changes: 34 additions & 0 deletions src/Service/UsuarioService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Service;

use App\Repository\UsuarioRepository;
use App\Entity\Usuario;

class UsuarioService
{
/**
* @var UsuarioRepository
*/
private $usuarioRepository;

public function __construct(UsuarioRepository $usuarioRepository)
{
$this->usuarioRepository = $usuarioRepository;
}

public function salvar(Usuario $usuario)
{
$this->usuarioRepository->salvar($usuario);
}

public function editar(Usuario $usuario)
{
$this->usuarioRepository->editar($usuario);
}

public function deletar(Usuario $usuario)
{
$this->usuarioRepository->deletar($usuario);
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linha em branco no fim do arquivo

6 changes: 3 additions & 3 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<title>Imobiliária</title>

<!-- Custom fonts for this template-->
<link href="../vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">

<!-- Custom styles for this template-->
<link href="../css/sb-admin-2.min.css" rel="stylesheet">
<link href="../vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">
<link href="/css/sb-admin-2.min.css" rel="stylesheet">
<link href="/vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">

</head>

Expand Down
14 changes: 7 additions & 7 deletions templates/footer.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@


<!-- Bootstrap core JavaScript-->
<script src="../vendor/jquery/jquery.min.js"></script>
<script src="../vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="/vendor/jquery/jquery.min.js"></script>
<script src="/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

<!-- Core plugin JavaScript-->
<script src="../vendor/jquery-easing/jquery.easing.min.js"></script>
<script src="/vendor/jquery-easing/jquery.easing.min.js"></script>

<!-- Custom scripts for all pages-->
<script src="../js/sb-admin-2.min.js"></script>
<script src="/js/sb-admin-2.min.js"></script>

<!-- Page level plugins -->
<script src="../vendor/datatables/jquery.dataTables.min.js"></script>
<script src="../vendor/datatables/dataTables.bootstrap4.min.js"></script>
<script src="/vendor/datatables/jquery.dataTables.min.js"></script>
<script src="/vendor/datatables/dataTables.bootstrap4.min.js"></script>

<!-- Page level custom scripts -->
<script src="../js/demo/datatables-demo.js"></script>
<script src="/js/demo/datatables-demo.js"></script>
<script type="text/javascript" src='https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.15/jquery.mask.js'></script>

</body>
Expand Down
Loading