File size: 3,230 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ws;
import beans.Conductor;
import beans.Respuesta;
import beans.RespuestaValidacion;
import java.sql.Date;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
import javax.ws.rs.core.MediaType;
import model.dao.ConductorDAO;
/**
* REST Web Service
*
* @author manolo
* @author Juan Carlos
*/
@Path("conductores")
public class ConductorWS {
@Context
private UriInfo context;
/**
* Creates a new instance of ConductorWS
*/
public ConductorWS() {
}
@POST
@Path("registrarConductor")
@Produces(MediaType.APPLICATION_JSON)
public Respuesta registrarUsuario(
@FormParam("nombre") String nombre,
@FormParam("telefono") String telefono,
@FormParam("password") String password,
@FormParam("fechaNacimiento") String fechaNacimiento,
@FormParam("numeroLicencia") String numeroLicencia
) {
Respuesta res = new Respuesta();
Conductor conductor = new Conductor(nombre, Date.valueOf(fechaNacimiento),
numeroLicencia, telefono, password);
int fa = ConductorDAO.registrarConductor(conductor);
if (fa > 0) {
res.setError(false);
res.setErrorcode(0);
res.setMensaje("Conductor registrado exitosamente");
} else {
switch (fa) {
case -1:
res.setError(true);
res.setErrorcode(1);
res.setMensaje("Error al registrar conductor, datos no válidos");
break;
case -2:
res.setError(true);
res.setErrorcode(2);
res.setMensaje("Error al registrar conductor, ese numero "
+ "ya está registrado");
break;
default:
res.setError(true);
res.setErrorcode(3);
res.setMensaje("Error de conexión");
break;
}
}
return res;
}
@POST
@Path("autenticar")
@Produces(MediaType.APPLICATION_JSON)
public RespuestaValidacion autenticarConductor(
@FormParam("telefono") String telefono,
@FormParam("token") String token
){
RespuestaValidacion res = new RespuestaValidacion();
res = ConductorDAO.autenticarConductor(telefono, token);
return res;
}
@POST
@Path("iniciarSesion")
@Produces(MediaType.APPLICATION_JSON)
public RespuestaValidacion iniciarSesion(
@FormParam("telefono") String telefono,
@FormParam("password") String password
){
RespuestaValidacion res = new RespuestaValidacion();
res = ConductorDAO.iniciarSesion(telefono, password);
return res;
}
}
|