cambios backend

This commit is contained in:
Soka_jplr 2024-05-08 08:39:52 -06:00
parent 60c1ed8183
commit 5b0098b2f1
7 changed files with 49 additions and 22 deletions

View File

@ -29,36 +29,41 @@ public class App
before((request,response)->response.header("Access-Control-Allow-Origin","*")); before((request,response)->response.header("Access-Control-Allow-Origin","*"));
get("/TodosLosAlumnos", (request, response) ->{ get("/todosLosAlumnos", (request, response) ->{
response.type("application/json"); response.type("application/json");
return gson.toJson(DAO.dameUsuarios()); return gson.toJson(DAO.dameAlumnos());
}); });
post("/agregarAlumno", (request, response) ->{ post("/agregarAlumno", (request, response) ->{
String payload = request.body(); String payload = request.body();
Alumno alumno = gson.fromJson(payload, Alumno.class); 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(); JsonObject respuesta = new JsonObject();
respuesta.addProperty("msj", msj); respuesta.addProperty("msj", msj);
return respuesta; return respuesta;
}); });
put("/EditarAlumno", (request, response) ->{ put("/editarAlumno", (request, response) ->{
String payload = request.body(); String payload = request.body();
Alumno alumno = gson.fromJson(payload, Alumno.class); Alumno alumno = gson.fromJson(payload, Alumno.class);
boolean verificado = DAO.editarAlumno(alumno); boolean verificado = DAO.editarAlumno(alumno);
JsonObject respuesta = new JsonObject(); JsonObject respuesta = new JsonObject();
respuesta.addProperty("existe", verificado); respuesta.addProperty("Editado", verificado);
return respuesta; return respuesta;
}); });
delete("/EliminarAlumno", (request, response) ->{ delete("/eliminarAlumno", (request, response) ->{
String payload = request.body(); String payload = request.body();
Alumno alumno = gson.fromJson(payload, Alumno.class); Alumno alumno = gson.fromJson(payload, Alumno.class);
boolean verificado = DAO.eliminarAlumno(alumno); boolean verificado = DAO.eliminarAlumno(alumno.getId());
JsonObject respuesta = new JsonObject(); JsonObject respuesta = new JsonObject();
respuesta.addProperty("existe", verificado); respuesta.addProperty("existe", verificado);
return respuesta; 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()));
});
} }
} }

View File

@ -4,13 +4,14 @@ import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.google.gson.JsonElement;
import mx.uv.Model.Alumno; import mx.uv.Model.Alumno;
public class DAO { public class DAO {
private static Conexion cn = Conexion.getInstance(); private static Conexion cn = Conexion.getInstance();
public static List<Alumno> dameUsuarios() { public static List<Alumno> dameAlumnos() {
Statement stm = null; Statement stm = null;
ResultSet rs = null; ResultSet rs = null;
Connection conn = null; Connection conn = null;
@ -99,7 +100,7 @@ public class DAO {
System.out.println(e); System.out.println(e);
} }
} }
public static boolean eliminarAlumno(Alumno alumno) { public static boolean eliminarAlumno(int idAlumno) {
return false; return false;
} }
@ -109,16 +110,40 @@ public class DAO {
boolean verificacion =false; boolean verificacion =false;
conn = cn.conectar(); conn = cn.conectar();
try { 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 = conn.prepareStatement(sql);
stm.executeUpdate(); stm.executeUpdate();
verificacion = true; verificacion = true;
conn.close();
} catch (SQLException ex) { } catch (SQLException ex) {
System.err.println(ex); System.err.println(ex);
}finally{ }finally{
actualizarVenta(p); cerrarConexiones(stm, conn);
cn.cerrarConexion();
} }
return verificacion; 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;
}
} }

View File

@ -8,7 +8,6 @@
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>
<DIV></DIV>
<script type="module" src="/src/main.jsx"></script> <script type="module" src="/src/main.jsx"></script>
</body> </body>
</html> </html>

View File

@ -63,7 +63,9 @@ div.listaLic{
width: 100%; width: 100%;
font-weight: bold; font-weight: bold;
} }
header{
text-align: center;
}

View File

@ -3,7 +3,6 @@ import './OfertaEducativa.css'
function OfertaEducativa (){ function OfertaEducativa (){
return ( return (
<> <>
<body>
<header className='headerOE'> <header className='headerOE'>
<nav> <nav>
<ul> <ul>
@ -66,7 +65,6 @@ function OfertaEducativa (){
<footer className='footerOE'> <footer className='footerOE'>
© 2024 Universidad Filadelfia. Todos los derechos reservados © 2024 Universidad Filadelfia. Todos los derechos reservados
</footer> </footer>
</body>
</> </>
); );
} }

View File

@ -85,5 +85,8 @@
.boton:hover { .boton:hover {
background-color: #0056b3; background-color: #0056b3;
} }
header{
text-align: center;
}

View File

@ -1,12 +1,7 @@
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom/client' import ReactDOM from 'react-dom/client'
import OfertaEducativa from './OfertaEducativa.jsx' import OfertaEducativa from './OfertaEducativa.jsx'
import Preinscripcion from './Preinscripcion.jsx'
import SubirPDF from './SubirPDF.jsx'
import General from './General.jsx'
import './Registro.css'
import './login.css';
ReactDOM.createRoot(document.getElementById('root')).render( ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode> <React.StrictMode>