From 5b0098b2f19cd76467a845bc1d3c0e3196b7ba95 Mon Sep 17 00:00:00 2001 From: Soka_jplr Date: Wed, 8 May 2024 08:39:52 -0600 Subject: [PATCH] cambios backend --- backend/src/main/java/mx/uv/App.java | 21 ++++++----- .../src/main/java/mx/uv/Controller/DAO.java | 35 ++++++++++++++++--- frontend/index.html | 1 - frontend/src/OfertaEducativa.css | 4 ++- frontend/src/OfertaEducativa.jsx | 2 -- frontend/src/Registro.css | 3 ++ frontend/src/main.jsx | 5 --- 7 files changed, 49 insertions(+), 22 deletions(-) diff --git a/backend/src/main/java/mx/uv/App.java b/backend/src/main/java/mx/uv/App.java index 13e0693..f9a9b8e 100644 --- a/backend/src/main/java/mx/uv/App.java +++ b/backend/src/main/java/mx/uv/App.java @@ -29,36 +29,41 @@ public class App before((request,response)->response.header("Access-Control-Allow-Origin","*")); - get("/TodosLosAlumnos", (request, response) ->{ + get("/todosLosAlumnos", (request, response) ->{ response.type("application/json"); - return gson.toJson(DAO.dameUsuarios()); + return gson.toJson(DAO.dameAlumnos()); }); post("/agregarAlumno", (request, response) ->{ String payload = request.body(); Alumno alumno = gson.fromJson(payload, Alumno.class); - boolean msj = DAO.agregarAlumno(new Alumno("Pedro","Lazaro","Mexicano","SAKHBD197", "PezGato")); + boolean msj = DAO.agregarAlumno(alumno); JsonObject respuesta = new JsonObject(); respuesta.addProperty("msj", msj); return respuesta; }); - put("/EditarAlumno", (request, response) ->{ + put("/editarAlumno", (request, response) ->{ String payload = request.body(); Alumno alumno = gson.fromJson(payload, Alumno.class); boolean verificado = DAO.editarAlumno(alumno); JsonObject respuesta = new JsonObject(); - respuesta.addProperty("existe", verificado); + respuesta.addProperty("Editado", verificado); return respuesta; }); - delete("/EliminarAlumno", (request, response) ->{ + delete("/eliminarAlumno", (request, response) ->{ String payload = request.body(); Alumno alumno = gson.fromJson(payload, Alumno.class); - boolean verificado = DAO.eliminarAlumno(alumno); + boolean verificado = DAO.eliminarAlumno(alumno.getId()); JsonObject respuesta = new JsonObject(); respuesta.addProperty("existe", verificado); return respuesta; }); - + get("/alumnoIniciado", (request, response) ->{ + response.type("application/json"); + String payload = request.body(); + Alumno alumno = gson.fromJson(payload, Alumno.class); + return gson.toJson(DAO.alumnoIniciado(alumno.getMatricula(),alumno.getContrasena())); + }); } } \ No newline at end of file diff --git a/backend/src/main/java/mx/uv/Controller/DAO.java b/backend/src/main/java/mx/uv/Controller/DAO.java index f3cf49d..cc7c7ef 100644 --- a/backend/src/main/java/mx/uv/Controller/DAO.java +++ b/backend/src/main/java/mx/uv/Controller/DAO.java @@ -4,13 +4,14 @@ import java.sql.*; import java.util.ArrayList; import java.util.List; +import com.google.gson.JsonElement; import mx.uv.Model.Alumno; public class DAO { private static Conexion cn = Conexion.getInstance(); - public static List dameUsuarios() { + public static List dameAlumnos() { Statement stm = null; ResultSet rs = null; Connection conn = null; @@ -99,7 +100,7 @@ public class DAO { System.out.println(e); } } - public static boolean eliminarAlumno(Alumno alumno) { + public static boolean eliminarAlumno(int idAlumno) { return false; } @@ -109,16 +110,40 @@ public class DAO { boolean verificacion =false; conn = cn.conectar(); try { - String sql ="UPDATE `producto` SET `nombreProducto` = '"+p.getNombreProducto()+"',`precio` = '"+p.getPrecio()+"',`cantidad` = '"+p.getCantidad()+"',`imagen` = '"+p.getImagen()+"'WHERE `id` = '"+p.getId()+"';"; + String sql ="UPDATE `alumno` SET `nombre` = '"+alumno.getNombre()+"',`apellido` = '"+alumno.getApellido()+"',`fecha_nacimiento` = '"+alumno.getFechaNacimiento()+"',`nacionalidad` = '"+alumno.getNacionalidad()+"', `tipoSangre` = '"+alumno.getTipoDeSangre()+"', `contrasena`= '"+alumno.getContrasena()+"' WHERE `id` = '"+alumno.getId()+"';"; stm = conn.prepareStatement(sql); stm.executeUpdate(); verificacion = true; - conn.close(); } catch (SQLException ex) { System.err.println(ex); }finally{ - actualizarVenta(p); + cerrarConexiones(stm, conn); + cn.cerrarConexion(); } return verificacion; } + + public static Alumno alumnoIniciado(String matricula, String contrasena) { + ResultSet rs = null; + Connection conn = null; + Alumno alumno =null; + + conn = cn.conectar(); + + try { + String sql = "SELECT * FROM alumno WHERE matricula = ? AND contrasena = ?"; + PreparedStatement stmt = conn.prepareStatement(sql); + stmt.setString(1, matricula); + stmt.setString(2, contrasena); + rs = stmt.executeQuery(); + while (rs.next()) { + alumno = new Alumno(rs.getInt(1), rs.getString(2), rs.getString(3),rs.getString(4), rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8)); + } + } catch (Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(null, conn); + } + return alumno; + } } diff --git a/frontend/index.html b/frontend/index.html index 5e538a2..c933b91 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -8,7 +8,6 @@
-
diff --git a/frontend/src/OfertaEducativa.css b/frontend/src/OfertaEducativa.css index 4a0c572..4a0a3aa 100644 --- a/frontend/src/OfertaEducativa.css +++ b/frontend/src/OfertaEducativa.css @@ -63,7 +63,9 @@ div.listaLic{ width: 100%; font-weight: bold; } - +header{ + text-align: center; +} diff --git a/frontend/src/OfertaEducativa.jsx b/frontend/src/OfertaEducativa.jsx index 2e793a3..43c6be5 100644 --- a/frontend/src/OfertaEducativa.jsx +++ b/frontend/src/OfertaEducativa.jsx @@ -3,7 +3,6 @@ import './OfertaEducativa.css' function OfertaEducativa (){ return ( <> -