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 Pos Web - Imobiliaria2.0 - Vicente Albuquerque #49

Open
wants to merge 2 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.
109 changes: 109 additions & 0 deletions src/Controller/ContratoAdmController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace App\Controller;

use App\Entity\ContratoAdm;
use App\Forms\ContratoAdmType;
use App\Repository\ContratoAdmRepository;
use App\Services\ContratoAdmService;
use App\Services\ImovelService;
use App\Services\UsuarioService;
use Psr\Container\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ContratoAdmController extends AbstractController
{
private $usuario;
private $imovel;
private $contratoAdm;

public function __construct(UsuarioService $usuarioService, ImovelService $imovelService, ContratoAdmService $contratoAdm)
{
$this->usuario = $usuarioService;
$this->imovel = $imovelService;
$this->contratoAdm = $contratoAdm;

}


/**
* @Route("/contrato/listar", name="contrato_adm_index")
*/
public function index(ContratoAdmRepository $contratoAdmRepository): Response
{
return $this->render('contratoAdm.html.twig', [
'contrato_adms' => $contratoAdmRepository->findAll(),
]);
}

/**
* @Route("/contrato/cadastro", name="contrato_adm_cadastro", methods={"GET","POST"})
*/
public function cadastro(Request $request): Response
{
$contratoAdm = new ContratoAdm();
$form = $this->createForm(ContratoAdmType::class, $contratoAdm);

$form->handleRequest($request);

if ($form->isSubmitted()) {

$this->contratoAdm->salvar($contratoAdm);
// $entityManager = $this->getDoctrine()->getManager();
// $entityManager->persist($contratoAdm);
// $entityManager->flush();

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

return $this->render('contratoAdm_cadastro.html.twig', [
'contrato_adm' => $contratoAdm,
'form' => $form->createView(),
]);
}

/**
* @Route("/contrato/{id}", name="contrato_adm_show", methods={"GET"})
*/
public function show(ContratoAdm $contratoAdm): Response
{
return $this->render('contrato_adm/show.html.twig', [
'contrato_adm' => $contratoAdm,
]);
}

/**
* @Route("/contratoEditar/{id}", name="contrato_adm_editar")
*/
public function editar(Request $request, ContratoAdm $contratoAdm): Response
{
$form = $this->createForm(ContratoAdmType::class, $contratoAdm);
$form->handleRequest($request);

if ($form->isSubmitted()) {
$this->getDoctrine()->getManager()->flush();

return $this->redirectToRoute('contrato_adm_index', [
'id' => $contratoAdm->getId(),
]);
}

return $this->render('contratoAdm_editar.html.twig', [
'contrato_adm' => $contratoAdm,
'form' => $form->createView(),
]);
}

/**
* @Route("/contratoDeletar/{id}", name="contrato_adm_delete")
*/
public function delete(Request $request, ContratoAdm $contratoAdm): Response
{
$this->contratoAdm->deletar($contratoAdm->getId());

return $this->redirectToRoute('contrato_adm_index');
}
}
69 changes: 63 additions & 6 deletions src/Controller/ImovelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@

use App\Entity\Imovel;
use App\Forms\ImovelType;
use App\Services\ImovelService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class ImovelController extends AbstractController
{

private $imovelService;

public function __construct(ImovelService $imovelService)
{
$this->imovelService = $imovelService;
}

/**
* @Route("/imovel/cadastro", name="cadasto_imovel")
*
Expand All @@ -28,11 +36,10 @@ public function cadastroImovel(Request $request)

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

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

return $this->render('imovel_cadastro.html.twig', [
Expand All @@ -46,8 +53,7 @@ public function cadastroImovel(Request $request)
*/
public function listarImoveis()
{
$em = $this->getDoctrine()->getManager();
$imoveis = $em->getRepository(Imovel::class)->findAll();
$imoveis = $this->imovelService->listar();

return $this->render('listar_imoveis.html.twig', [
'imoveis' => $imoveis
Expand Down Expand Up @@ -81,6 +87,57 @@ public function imovelVisualizar(Request $request)
]);
}

/**
* @Route("/editarImovel/{id}", name="editar_imovel")
*/
public function editarImovel(int $id, Request $request)
{
//pegando o imovel a ser editado
$em = $this->getDoctrine()->getManager();
$imovel = $em->getRepository(Imovel::class)->find($id);

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

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


//renderizando o form
$form->handleRequest($request);

if($form->isSubmitted())
{
$imovel = $form->getData();
$this->imovelService->editar($imovel);
//msg
$this->addFlash('success', 'Imovel editado com sucesso!!!');

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

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


/**
* @Route("/deletarImovel/{id}", name="deletar_imovel")
*/
public function deletarImovel(int $id, Request $request)
{

$this->imovelService->deletar($id);

$this->addFlash('success', 'Imovel deletado com sucesso!!!');

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





}
25 changes: 10 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\Services\UsuarioService;
use phpDocumentor\Reflection\DocBlock\Tags\Throws;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
Expand All @@ -21,20 +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();
//enviando para o serviço
$usuarioService->salvar($usuario);

return $this->redirectToRoute('index');
}
Expand All @@ -59,7 +59,6 @@ public function listarUsuarios(Request $request)
$em->flush();



$em = $this->getDoctrine()->getManager();
$usuarios = $em->getRepository(Usuario::class)->findAll();

Expand All @@ -69,7 +68,7 @@ public function listarUsuarios(Request $request)
}

/**
* @Route("/editar/{id}", name="editar_usuario")
* @Route("/editarUsuario/{id}", name="editar_usuario")
*/
public function editarUsuario(int $id, Request $request)
{
Expand All @@ -81,7 +80,6 @@ public function editarUsuario(int $id, Request $request)
}

$form = $this->createForm(UsuarioType::class, $usuario);

$form->handleRequest($request);

if ($form->isSubmitted()) {
Expand All @@ -94,19 +92,16 @@ public function editarUsuario(int $id, Request $request)
}

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

/**
* @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($id);

$this->addFlash('success', 'Usuario de id:'.$id.' deletado com sucesso!!!');

return $this->redirectToRoute('listar_usuarios');
Expand Down
93 changes: 93 additions & 0 deletions src/Entity/ContratoAdm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity()
*/
class ContratoAdm
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;

/**
* @ORM\Column(type="datetime")
*/
private $dtCadastro;

/**
* @ORM\Column(type="text", nullable=true)
*/
private $clausulaContratual;

/**
* @ORM\ManyToOne(targetEntity="App\Entity\Usuario", inversedBy="contratosAdm")
* @ORM\JoinColumn(name="usuario_id", nullable=false)
*/
private $usuario;

/**
* @ORM\ManyToOne(targetEntity="App\Entity\Imovel", inversedBy="contratosAdm")
* @ORM\JoinColumn(name="imovel_id", nullable=false)
*/
private $imovel;

public function getId(): ?int
{
return $this->id;
}

public function getDtCadastro(): ?\DateTimeInterface
{
return $this->dtCadastro;
}

public function setDtCadastro(\DateTimeInterface $dtCadastro): self
{
$this->dtCadastro = $dtCadastro;

return $this;
}

public function getClausulaContratual(): ?string
{
return $this->clausulaContratual;
}

public function setClausulaContratual(?string $clausulaContratual): self
{
$this->clausulaContratual = $clausulaContratual;

return $this;
}

public function getUsuario(): ?Usuario
{
return $this->usuario;
}

public function setUsuario(?Usuario $usuario): self
{
$this->usuario = $usuario;

return $this;
}

public function getImovel(): ?Imovel
{
return $this->imovel;
}

public function setImovel(?Imovel $imovel): self
{
$this->imovel = $imovel;

return $this;
}
}
Loading