From 251cebdb374091d5ff355ab3bb8b5abc1c54c83e Mon Sep 17 00:00:00 2001 From: devfzn Date: Fri, 24 Mar 2023 19:45:38 -0300 Subject: [PATCH] edited: pacientes.php y pacientes.class.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pacientes.php: manejo condición PUT pacientes.class.php: creación función PUT y modifcarPaciente --- README.md | 2 +- apirest_yt/clases/pacientes.class.php | 46 +++++++++++++++++++++++++++ apirest_yt/pacientes.php | 15 ++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 99ab738..abd6a18 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ Combinación de 2 funciones de *php* para generar un *token* único en ` [Metodos HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) diff --git a/apirest_yt/clases/pacientes.class.php b/apirest_yt/clases/pacientes.class.php index 508c036..86c0eb8 100644 --- a/apirest_yt/clases/pacientes.class.php +++ b/apirest_yt/clases/pacientes.class.php @@ -76,6 +76,52 @@ class pacientes extends conexion{ return 0; } } + + public function put($json){ + $_respuestas = new respuestas; + $datos = json_decode($json, true); + if (!isset($datos['pacienteid'])){ + return $_respuestas->error_400(); + } else { + $this->pacienteid = $datos['pacienteid']; + if (isset($datos['nombre'])){ $this->nombre = $datos['nombre']; } + if (isset($datos['dni'])){ $this->dni = $datos['dni']; } + if (isset($datos['correo'])){ $this->correo = $datos['correo']; } + if (isset($datos['telefono'])){ $this->telefono = $datos['telefono']; } + if (isset($datos['direccion'])){ $this->direccion = $datos['direccion']; } + if (isset($datos['codigo_postal'])){ $this->codigo_postal = $datos['codigo_postal']; } + if (isset($datos['genero'])){ $this->genero = $datos['genero']; } + if (isset($datos['fecha_nacimiento'])){ $this->fecha_nacimiento = $datos['fecha_nacimiento']; } + + $resp = $this->modificarPaciente(); + if ($resp){ + $respuesta = $_respuestas->response; + $respuesta['result'] = array( + //'filas_afectadas' => $resp, + 'pacienteid' => $this->pacienteid + ); + return $respuesta; + } else { + return $_respuestas->error_500(); + } + } + } + + private function modificarPaciente(){ + $query = "UPDATE $this->table SET Nombre = '$this->nombre', + Direccion = '$this->direccion', DNI = '$this->dni', + CodigoPostal = '$this->codigo_postal', + Telefono = '$this->telefono', Genero = '$this->genero', + FechaNacimiento = '$this->fecha_nacimiento', + Correo = '$this->correo' WHERE PacienteId = '$this->pacienteid'"; + $resp = parent::nonQuery($query); + if ($resp >= 1){ + return $resp; + } else { + return 0; + } + } + } ?> diff --git a/apirest_yt/pacientes.php b/apirest_yt/pacientes.php index 1638b54..b33c66d 100644 --- a/apirest_yt/pacientes.php +++ b/apirest_yt/pacientes.php @@ -21,6 +21,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET"){ } } else if ($_SERVER['REQUEST_METHOD'] == "POST"){ + // recepción de datos $postBody = file_get_contents("php://input"); // envio de datos al manejador @@ -35,7 +36,19 @@ if ($_SERVER['REQUEST_METHOD'] == "GET"){ echo json_encode($datosArray); } else if ($_SERVER['REQUEST_METHOD'] == "PUT"){ - echo "hola PUT"; + + // recepción de datos + $postBody = file_get_contents("php://input"); + // envio de datos al manejador + $datosArray = $_pacientes->put($postBody); + // devolucion de respuesta + if(isset($datosArray["result"]["error_id"])){ + $responseCode = $datosArray["result"]["error_id"]; + http_response_code($responseCode); + }else{ + http_response_code(200); + } + echo json_encode($datosArray); } else if ($_SERVER['REQUEST_METHOD'] == "DELETE"){ echo "hola DELETE";