Modificaciones Usuario.java

parent 022f32c7
......@@ -10,11 +10,10 @@ import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.util.*;
import static com.carpooling.carpoolingaoraha.entidades.Rol.CONDUCTOR;
import static com.carpooling.carpoolingaoraha.entidades.Rol.PASAJERO;
import static com.carpooling.carpoolingaoraha.entidades.Rol.*;
enum Rol {
CONDUCTOR, PASAJERO
CONDUCTOR, PASAJERO, AMBOS
};
@Entity
@Table (name = "usuarios")
......@@ -71,11 +70,7 @@ public class Usuario {
this.claveAcceso = claveAcceso;
this.puntuacion = new ArrayList<>();
this.rol = rol;
if(rol == CONDUCTOR){
this.viajesOfertados = new ArrayList<>();
}else{
this.viajesOfertados = null;
}
this.sistemaCarPooling = new SistemaCarPooling();
puntuacionMedia = 0;
}
......@@ -165,15 +160,11 @@ public class Usuario {
}
public void cambiarRol(){
if(this.rol == CONDUCTOR){
rol = PASAJERO;
}else{
rol = CONDUCTOR;
}
this.rol = AMBOS;
}
public boolean ofrecerViaje(String origen, String destino, Date fechaSalida, int nAsientos, int precioAsiento){
if(this.rol == CONDUCTOR) {
if(this.rol == CONDUCTOR || this.rol == AMBOS) {
//Crea una reserva
Reserva reserva = new Reserva(this, origen, destino, fechaSalida, nAsientos, precioAsiento);
this.viajesOfertados.add(reserva.getIdReserva());
......@@ -183,7 +174,7 @@ public class Usuario {
}
public boolean aceptarPasajero(int idReserva, String DNI, Rol rol){ //Le pasamos el rol del conductor
if(rol == CONDUCTOR){
if(rol == CONDUCTOR || rol == AMBOS){
for(int i=0; i<this.sistemaCarPooling.getReservas().size(); i++){
if(idReserva == this.sistemaCarPooling.getReservas().get(i).getIdReserva() && this.sistemaCarPooling.getReservas().get(i).haySitioDisponible()){
this.sistemaCarPooling.getReservas().get(i).anadirPasajeros(DNI, idReserva);
......@@ -212,7 +203,7 @@ public class Usuario {
for (Viaje viaje : todosLosViajes) {
if (viaje.getOrigen().equals(origen) && viaje.getDestino().equals(destino) &&
viaje.getFechaSalida().equals(fecha)) {
if (getRol().equals(PASAJERO)) {
if (getRol().equals(PASAJERO) || getRol().equals(AMBOS)) {
viajesDisponibles.add(viaje);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment