From cda4e9c7f600af174301d1ef841bd35341e5fe50 Mon Sep 17 00:00:00 2001 From: Reginaldo Date: Mon, 19 Jun 2023 16:42:11 -0300 Subject: [PATCH] =?UTF-8?q?criada=20a=20fun=C3=A7=C3=A3o=20para=20editar?= =?UTF-8?q?=20e=20deletar=20os=20dados=20do=20banco=20maria?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/Controller.php | 64 +++++++++++++++++++++++++++--- app/controllers/PaisController.php | 15 +++++-- index.php | 11 ++++- routes/router.php | 3 +- 4 files changed, 82 insertions(+), 11 deletions(-) diff --git a/app/controllers/Controller.php b/app/controllers/Controller.php index 8750ec3..850d33a 100644 --- a/app/controllers/Controller.php +++ b/app/controllers/Controller.php @@ -48,13 +48,67 @@ class Controller extends DBA{ //print_r($this->res); //return $this->res; } - public function getPais(){ - $this->sql = "SELECT * FROM usuarios"; + public function getPais($CD_ALUNO){ + $this->sql = "SELECT * FROM usuarios WHERE CD_ALUNO = ?"; + $this->stmt = self::$instMARIA->prepare($this->sql); + $this->stmt->bindValue(1,$CD_ALUNO); + $this->stmt->execute(); + $this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC); + return $this-> res; + } + public function deletaPais($CPF){ + $this->sql = "DELETE FROM usuarios WHERE CPF = ?"; + $this->stmt = self::$instMARIA->prepare($this->sql); + $this->stmt->bindValue(1,$CPF); + $this->stmt->execute(); + if($this->stmt){ + echo 'deletado com sucesso'; + }else{ + echo 'erro'; + } + } + public function inserirPais(){ + $CD_ALUNO = $_POST['CD_ALUNO']; + $CPF = $_POST['CPF']; + $NOME = $_POST['NOME']; + $SENHA = $_POST['SENHA']; + $PARENTESCO = $_POST['PARENTESCO']; + $DATA_CADASTRO = $_POST['DATA_CADASTRO']; + $CONDICAO = $_POST['CONDICAO']; + if($CONDICAO=='NOVO'){ + $this->sql = "INSERT INTO usuarios (CD_ALUNO, CPF, NOME, SENHA, PARENTESCO, DATA_CADASTRO, CONDICAO) VALUES (:CD_ALUNO, :CPF, :NOME, :SENHA, :PARENTESCO, :DATA_CADASTRO, :CONDICAO)"; $this->stmt = self::$instMARIA->prepare($this->sql); + $this->stmt->bindValue(':CD_ALUNO', $CD_ALUNO); + $this->stmt->bindValue(':CPF', $CPF); + $this->stmt->bindValue(':NOME', $NOME); + $this->stmt->bindValue(':SENHA', $SENHA); + $this->stmt->bindValue(':PARENTESCO', $PARENTESCO); + $this->stmt->bindValue(':DATA_CADASTRO', $DATA_CADASTRO); + $this->stmt->bindValue(':CONDICAO', $CONDICAO); $this->stmt->execute(); - $this->res = $this->stmt->fetchAll(PDO::FETCH_ASSOC); - return $this-> res; - } + if($this->stmt){ + echo 'cadastrado com sucesso'; + }else{ + echo 'erro'; + } + }else{ + $this->sql = "UPDATE usuarios SET CD_ALUNO = :CD_ALUNO, NOME = :NOME, SENHA = :SENHA, PARENTESCO = :PARENTESCO, DATA_CADASTRO = :DATA_CADASTRO, CONDICAO = :CONDICAO WHERE CPF = :CPF"; + $this->stmt = self::$instMARIA->prepare($this->sql); + $this->stmt->bindValue(':CD_ALUNO', $CD_ALUNO); + $this->stmt->bindValue(':CPF', $CPF); + $this->stmt->bindValue(':NOME', $NOME); + $this->stmt->bindValue(':SENHA', $SENHA); + $this->stmt->bindValue(':PARENTESCO', $PARENTESCO); + $this->stmt->bindValue(':DATA_CADASTRO', $DATA_CADASTRO); + $this->stmt->bindValue(':CONDICAO', $CONDICAO); + $this->stmt->execute(); + if($this->stmt){ + echo 'editado com sucesso'; + }else{ + echo 'erro'; + } + } + } } class DBA{ diff --git a/app/controllers/PaisController.php b/app/controllers/PaisController.php index 945d899..06ae4b5 100644 --- a/app/controllers/PaisController.php +++ b/app/controllers/PaisController.php @@ -2,13 +2,20 @@ namespace app\controllers; class PaisController{ - public function index(){ + public function index($params){ + $cod = $params->CD_ALUNO; $Log = new Controller(); - $Logins = $Log->getPais(); + $Logins = $Log->getPais($cod); echo json_encode($Logins); return json_encode($Logins); } - public function store(){ - var_dump('store do login'); + public function insert(){ + $Log = new Controller(); + $Logins = $Log->inserirPais(); + } + public function deleta($params){ + $cpf = $params->CPF; + $Log = new Controller(); + $Logins = $Log->deletaPais($cpf); } } \ No newline at end of file diff --git a/index.php b/index.php index 49cd5d9..9aff5f6 100644 --- a/index.php +++ b/index.php @@ -65,4 +65,13 @@ try{ //dados alunos //http://localhost:8000/aluno?NR_LOGRADOURO=715 -//http://localhost:8000/aluno?NOME=JOAO%20MIGUEL%20DE \ No newline at end of file +//http://localhost:8000/aluno?NOME=JOAO%20MIGUEL%20DE + +//inserir +//http://localhost:8000/inserirpais + +//DADOS PAIS +//http://localhost:8000/pais?CD_ALUNO=70B81220937CED736CA3A7D462E3FF6A + +//DELELA PAIS +//http://localhost:8000/deleta?CPF=123 \ No newline at end of file diff --git a/routes/router.php b/routes/router.php index b2bb093..d6c37b8 100644 --- a/routes/router.php +++ b/routes/router.php @@ -24,9 +24,10 @@ $router= [ "/login" => fn()=> load("LoginController","index"), "/aluno" => fn()=> load("AlunoController","index"), "/pais" => fn()=> load("PaisController","index"), + "/deleta" => fn()=> load("PaisController","deleta"), ], "POST"=>[ - "/login" => fn()=> load("LoginController","store") + "/inserirpais" => fn()=> load("PaisController","insert") ] ];