cambios en App.java
This commit is contained in:
parent
7b37079daa
commit
122b4f43dc
|
@ -1,4 +1,5 @@
|
||||||
package mx.uv;
|
package mx.uv;
|
||||||
|
|
||||||
import static spark.Spark.*;
|
import static spark.Spark.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -8,12 +9,11 @@ import com.google.gson.*;
|
||||||
import mx.uv.Controller.DAO;
|
import mx.uv.Controller.DAO;
|
||||||
import mx.uv.Model.*;
|
import mx.uv.Model.*;
|
||||||
|
|
||||||
public class App
|
public class App {
|
||||||
{
|
|
||||||
static Gson gson = new Gson();
|
static Gson gson = new Gson();
|
||||||
static HashMap<String, Alumno> usuarios = new HashMap<>();
|
static HashMap<String, Alumno> usuarios = new HashMap<>();
|
||||||
public static void main( String[] args )
|
|
||||||
{
|
public static void main(String[] args) {
|
||||||
// fuente:https://gist.github.com/saeidzebardast/e375b7d17be3e0f4dddf
|
// fuente:https://gist.github.com/saeidzebardast/e375b7d17be3e0f4dddf
|
||||||
options("/*", (request, response) -> {
|
options("/*", (request, response) -> {
|
||||||
String accessControlRequestHeaders = request.headers("Access-Control-Request-Headers");
|
String accessControlRequestHeaders = request.headers("Access-Control-Request-Headers");
|
||||||
|
@ -61,10 +61,15 @@ public class App
|
||||||
return respuesta;
|
return respuesta;
|
||||||
});
|
});
|
||||||
|
|
||||||
post("/alumnoIniciado", (request, response) ->{
|
get("/alumnoIniciado", (request, response) -> {
|
||||||
response.type("application/json");
|
response.type("application/json");
|
||||||
String payload = request.body();
|
String contrasena = request.queryParams("contrasena");
|
||||||
Alumno alumno = gson.fromJson(payload, Alumno.class);
|
String matricula = request.queryParams("matricula");
|
||||||
|
Alumno alumno = new Alumno(matricula, contrasena);
|
||||||
|
if (contrasena == null || matricula == null) {
|
||||||
|
response.status(400); // Bad request
|
||||||
|
return gson.toJson("Missing matricula or contrasena");
|
||||||
|
}
|
||||||
return gson.toJson(DAO.alumnoIniciado(alumno.getMatricula(), alumno.getContrasena()));
|
return gson.toJson(DAO.alumnoIniciado(alumno.getMatricula(), alumno.getContrasena()));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue